Open
Description
I find there are some bugs when trying to use attributes as vector for constant node input inside a local function, i.e.
These codes could work:
from onnxscript import opset18 as op
from onnxscript import script
import numpy as np
@script()
def LocalFunc(X, alpha: int):
alphaX = op.Constant(value_int=alpha)
gammaX = op.Constant(value_ints=[1, 2])
Add = alphaX + X + gammaX
return Add
v = np.array([[0, 1], [2, 3]], dtype=np.int64)
result = LocalFunc(v, 1)
print(result)
But this snippet would report errors:
@script()
def LocalFunc1(X, alpha: int, gamma: int):
alphaX = op.Constant(value_ints=[alpha, gamma])
Add = alphaX + X
return Add
v = np.array([[0, 1], [2, 3]], dtype=np.int64)
result = LocalFunc1(v, 1, 2)
print(result)
Errors are like
...
onnxscript\converter.py", line 471, in _eval_constant_expr
return eval(cpl, self.globals, locals) # pylint: disable=eval-used
File "<ast>", line 3, in <module>
NameError: name 'alpha' is not defined
...
NameError: ERROR: Missing names, globals contains ['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'op', 'script', 'np', 'LocalFunc', 'v', 'result'], locals [].
at: Function 'LocalFunc1', line 3
alphaX = op.Constant(value_ints=[alpha, gamma])
^
I think there might be a bug in the Constant node conversion, and such bug makes it hard for us to use multiple attributes directly in local function design.
Could you fix it?
Activity