From 0834bec471c48f82a174c1b4c2bd8d7d5ec212e0 Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 14:24:35 -0800 Subject: [PATCH 1/9] Use ir.Attr value Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 6 +++--- onnxscript/_internal/values.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 82388a19cf..a7c814ad38 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -354,7 +354,7 @@ def _to_onnx_attr_ref( msg = f"Unsupported attribute type {pytype!r}." fail(info.msg(msg) if info else msg) attr_type = ir.AttributeType(ta.pytype_to_attrtype(pytype)) - return ir.Attr(attrname, attr_type, None, val.value) + return ir.Attr(attrname, attr_type, None, val.value.name) def _to_onnx_var( self, @@ -536,7 +536,7 @@ def _translate_attr( val = self._lookup(expr.id, self._source_of(expr)) if isinstance(val, values.AttrRef): attr_type = ir.AttributeType(ta.pytype_to_attrtype(val.typeinfo)) - attr_ref = ir.Attr(attr_name, attr_type, None, val.value) + attr_ref = ir.Attr(attr_name, attr_type, None, val.value.name) if attr_meta is not None and (attr_ref.type != attr_meta.type): self.fail( expr, @@ -1459,7 +1459,7 @@ def _translate_function_signature_common( attribute_type = ta.pytype_to_attrtype(typeinfo) attr = ir.Attr(x.arg, ir.AttributeType(attribute_type), default_value, None) self._current_fn.append_parameter(attr) - self._bind(x.arg, values.AttrRef(x.arg, typeinfo, self._source_of(x))) + self._bind(x.arg, values.AttrRef(attr, typeinfo, self._source_of(x))) else: onnx_parameter = make_value(x.arg, typeinfo, self._source_of(x)) self._current_fn.append_parameter(onnx_parameter) diff --git a/onnxscript/_internal/values.py b/onnxscript/_internal/values.py index f9f0958de3..c3cf1d9626 100644 --- a/onnxscript/_internal/values.py +++ b/onnxscript/_internal/values.py @@ -861,18 +861,18 @@ def __init__(self, info: sourceinfo.SourceInfo) -> None: class AttrRef(SymbolValue): def __init__( - self, attr_name: str, typeinfo: _GenericAlias, info: sourceinfo.SourceInfo + self, attr: ir.Attr, typeinfo: _GenericAlias, info: sourceinfo.SourceInfo ) -> None: """Initializes AttrRef. Arguments: - attr_name: name of the attribute-parameter + attr: An ir.Attr representing the attribute-parameter typeinfo: type annotation of the attribute. op's attributes in ONNX are usually single type or list of single type. info: for debugging use. """ super().__init__(info) - self.value = attr_name + self.value = attr self.typeinfo = typeinfo if not isinstance(typeinfo, (type, _GenericAlias)): # typing._GenericAlias for List[int] and List[str], etc. From b3db32b75bdb995af02091c8f3b8212ba6028ca4 Mon Sep 17 00:00:00 2001 From: "G. Ramalingam" Date: Mon, 29 Dec 2025 14:51:34 -0800 Subject: [PATCH 2/9] Update onnxscript/_internal/converter.py Co-authored-by: Justin Chu --- onnxscript/_internal/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index a7c814ad38..3d56a26825 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -354,7 +354,7 @@ def _to_onnx_attr_ref( msg = f"Unsupported attribute type {pytype!r}." fail(info.msg(msg) if info else msg) attr_type = ir.AttributeType(ta.pytype_to_attrtype(pytype)) - return ir.Attr(attrname, attr_type, None, val.value.name) + return ir.Attr(attrname, attr_type, value=None, ref_attr_name=val.value.name) def _to_onnx_var( self, From 9e9c88614c9b8f7d51dc6006c35493b7bbcd93cc Mon Sep 17 00:00:00 2001 From: "G. Ramalingam" Date: Mon, 29 Dec 2025 14:51:43 -0800 Subject: [PATCH 3/9] Update onnxscript/_internal/converter.py Co-authored-by: Justin Chu --- onnxscript/_internal/converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 3d56a26825..56ef7baf29 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -536,7 +536,7 @@ def _translate_attr( val = self._lookup(expr.id, self._source_of(expr)) if isinstance(val, values.AttrRef): attr_type = ir.AttributeType(ta.pytype_to_attrtype(val.typeinfo)) - attr_ref = ir.Attr(attr_name, attr_type, None, val.value.name) + attr_ref = ir.Attr(attr_name, attr_type, None, ref_attr_name=val.value.name) if attr_meta is not None and (attr_ref.type != attr_meta.type): self.fail( expr, From 843afce518b23805dba1058f3eca4ce9be092e81 Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 15:25:32 -0800 Subject: [PATCH 4/9] Use SymbolValue for IRfunction as well. --- onnxscript/_internal/converter.py | 11 +++++++---- onnxscript/_internal/values.py | 24 +++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 56ef7baf29..1fa2e7ec46 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -543,10 +543,13 @@ def _translate_attr( f"Attribute type '{attr_ref.type}' does not match expected type '{attr_meta.type}'", ) return attr_ref - if isinstance(val, irbuilder.IRFunction): + if isinstance(val, values.SymbolValue) and isinstance( + val.value, irbuilder.IRFunction + ): + irfunction = val.value # Check that outer-scope variables referenced by function have same value # at function-definition site and use-as-attribute site, to avoid errors. - for pyvar, previous in val.outer_scope_variables: + for pyvar, previous in irfunction.outer_scope_variables: current = self._lookup(pyvar, self._source_of(expr)) if current.value != previous.value: self.fail( @@ -556,7 +559,7 @@ def _translate_attr( ) # Create GraphProto attribute - val = val.to_graph_proto() + val = irfunction.to_graph_proto() else: val = self._eval_constant_expr(expr) @@ -1431,7 +1434,7 @@ def _translate_nested_function_def(self, fn: ast.FunctionDef) -> None: function_ir.outer_scope_variables = [ (var, self._lookup(var, self._source_of(fn))) for var in outer_scope_vars ] - self._bind(fn.name, function_ir) + self._bind(fn.name, values.SymbolValue(function_ir, self._source_of(fn))) # TODO: Does not yet handle nested functions within nested functions. self._current_fn.add_nested_function(function_ir) diff --git a/onnxscript/_internal/values.py b/onnxscript/_internal/values.py index c3cf1d9626..28ae3d5cab 100644 --- a/onnxscript/_internal/values.py +++ b/onnxscript/_internal/values.py @@ -853,9 +853,17 @@ def ThresholdedRelu(X, alpha: float): * To represent constant-values, translated into ONNX constants. """ - def __init__(self, info: sourceinfo.SourceInfo) -> None: + def __init__(self, value: Any, info: sourceinfo.SourceInfo) -> None: + """ + Initializes SymbolValue. + + Arguments: + value: The value bound to a python variable in a script. + info: source-location information for error-messages/debugging + """ if not isinstance(info, sourceinfo.SourceInfo): raise TypeError(f"info must be of type sourceinfo.SourceInfo not {type(info)!r}.") + self.value = value self.info = info @@ -871,8 +879,7 @@ def __init__( op's attributes in ONNX are usually single type or list of single type. info: for debugging use. """ - super().__init__(info) - self.value = attr + super().__init__(attr, info) self.typeinfo = typeinfo if not isinstance(typeinfo, (type, _GenericAlias)): # typing._GenericAlias for List[int] and List[str], etc. @@ -891,7 +898,7 @@ class DynamicKind(IntFlag): class Dynamic(SymbolValue): def __init__( self, - onnx_var: ir.Value, + ir_value: ir.Value, kind: DynamicKind, info: sourceinfo.SourceInfo, typeinfo: TypeAnnotationValue | None = None, @@ -899,15 +906,14 @@ def __init__( """Represents an ir.Value with some extra information. Arguments: - onnx_var: the name of the ONNX variable used to represent this value + ir_value: the ir.Value corresponding to this value kind: the DynamicKind of this variable info: source-location information for error-messages/debugging typeinfo: type-information for the value """ - super().__init__(info) + super().__init__(ir_value, info) assert isinstance(kind, DynamicKind) - if not isinstance(onnx_var, ir.Value): - raise TypeError(f"onnx_var must be of type ir.Value not {type(onnx_var)!r}.") - self.value = onnx_var + if not isinstance(ir_value, ir.Value): + raise TypeError(f"ir_value must be of type ir.Value not {type(ir_value)!r}.") self.kind = kind self.typeinfo = typeinfo From aec7b2e0c4b993437374a693db9ad512c333fd41 Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 16:40:35 -0800 Subject: [PATCH 5/9] Improve handling of attr ref Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 56 +++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 1fa2e7ec46..3d161d7780 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -534,32 +534,44 @@ def _translate_attr( if isinstance(expr, ast.Name): val = self._lookup(expr.id, self._source_of(expr)) - if isinstance(val, values.AttrRef): - attr_type = ir.AttributeType(ta.pytype_to_attrtype(val.typeinfo)) - attr_ref = ir.Attr(attr_name, attr_type, None, ref_attr_name=val.value.name) - if attr_meta is not None and (attr_ref.type != attr_meta.type): - self.fail( - expr, - f"Attribute type '{attr_ref.type}' does not match expected type '{attr_meta.type}'", + if isinstance(val, values.SymbolValue): + val = val.value + if isinstance(val, ir.Attr): + # A reference to an attribute parameter: + attr = val + attr_ref = ir.Attr( + attr_name, attr.type, value=None, ref_attr_name=attr.name ) - return attr_ref - if isinstance(val, values.SymbolValue) and isinstance( - val.value, irbuilder.IRFunction - ): - irfunction = val.value - # Check that outer-scope variables referenced by function have same value - # at function-definition site and use-as-attribute site, to avoid errors. - for pyvar, previous in irfunction.outer_scope_variables: - current = self._lookup(pyvar, self._source_of(expr)) - if current.value != previous.value: + if attr_meta is not None and (attr.type != attr_meta.type): self.fail( expr, - f"Outer scope variable '{pyvar}' referenced by function " - f"'{expr.id!r}' modified.", + f"Attribute type '{attr_ref.type}' does not match expected type '{attr_meta.type}'", ) - - # Create GraphProto attribute - val = irfunction.to_graph_proto() + return attr_ref + if isinstance(val, irbuilder.IRFunction): + # A reference to a nested-function: convert to GraphProto and use it. + irfunction = val + # Check that outer-scope variables referenced by function have same value + # at function-definition site and use-as-attribute site, to avoid errors. + for pyvar, previous in irfunction.outer_scope_variables: + current = self._lookup(pyvar, self._source_of(expr)) + if current.value != previous.value: + self.fail( + expr, + f"Outer scope variable '{pyvar}' referenced by function " + f"'{expr.id!r}' modified.", + ) + # Create GraphProto attribute + val = irfunction.to_graph_proto() + if isinstance(val, ir.Value): + self.fail(expr, f"Cannot use ir.Value '{expr.id}' as an attribute.") + else: + # Treat as a constant python-value, to be converted below. + pass + else: + # This must be a reference to an outer-scope python-value, typically a constant. + # The value will be converted to an ONNX attribute value below. + pass else: val = self._eval_constant_expr(expr) From 89c802ab8470f711f3b6823ae335ce7a1673b36a Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 17:16:20 -0800 Subject: [PATCH 6/9] Cleanup attr ref representation Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 21 ++++++++++----------- onnxscript/_internal/values.py | 20 ++++---------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 3d161d7780..79856137a7 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -339,22 +339,20 @@ def tensor_name_generator() -> str: def _to_onnx_attr_ref( self, val: values.AttrRef, info: Optional[sourceinfo.SourceInfo] ) -> ir.Attr: - pytype = val.typeinfo - attrtype = ta.pytype_to_attrtype(pytype) + attrtype = val.value.type attrname = None - if attrtype is onnx.AttributeProto.FLOAT: + if attrtype is ir.AttributeType.FLOAT: # onnx.AttributeProto.FLOAT: attrname = "value_float" - elif attrtype is onnx.AttributeProto.INT: + elif attrtype is ir.AttributeType.INT: attrname = "value_int" - elif attrtype is onnx.AttributeProto.STRING: + elif attrtype is ir.AttributeType.STRING: attrname = "value_string" - elif attrtype is onnx.AttributeProto.INTS: + elif attrtype is ir.AttributeType.INTS: attrname = "value_ints" else: - msg = f"Unsupported attribute type {pytype!r}." + msg = f"Unsupported attribute type {attrtype!r}." fail(info.msg(msg) if info else msg) - attr_type = ir.AttributeType(ta.pytype_to_attrtype(pytype)) - return ir.Attr(attrname, attr_type, value=None, ref_attr_name=val.value.name) + return ir.Attr(attrname, attrtype, value=None, ref_attr_name=val.value.name) def _to_onnx_var( self, @@ -369,7 +367,7 @@ def _to_onnx_var( result = self.emit( [result_name], values.Op(self.default_opset, "Constant"), [], [attr] ) - if ta.base_type_is_bool(val.typeinfo): + if val.as_bool: # ONNX attributes use an int-encoding for bools, but ONNX tensor types # distinguish between int and bool. So we cast the int tensor to a bool tensor, # to promote a (python) bool attribute to a ONNX bool tensor. @@ -1474,7 +1472,8 @@ def _translate_function_signature_common( attribute_type = ta.pytype_to_attrtype(typeinfo) attr = ir.Attr(x.arg, ir.AttributeType(attribute_type), default_value, None) self._current_fn.append_parameter(attr) - self._bind(x.arg, values.AttrRef(attr, typeinfo, self._source_of(x))) + as_bool = ta.base_type_is_bool(typeinfo) + self._bind(x.arg, values.AttrRef(attr, as_bool, self._source_of(x))) else: onnx_parameter = make_value(x.arg, typeinfo, self._source_of(x)) self._current_fn.append_parameter(onnx_parameter) diff --git a/onnxscript/_internal/values.py b/onnxscript/_internal/values.py index 28ae3d5cab..c7e955e69f 100644 --- a/onnxscript/_internal/values.py +++ b/onnxscript/_internal/values.py @@ -13,7 +13,6 @@ import typing from enum import IntFlag from typing import ( # type: ignore[attr-defined] - TYPE_CHECKING, Any, Callable, ClassVar, @@ -22,7 +21,6 @@ Protocol, Sequence, TypeVar, - _GenericAlias, ) import onnx @@ -36,9 +34,6 @@ from onnxscript.ir import _schemas from onnxscript.onnx_types import ONNXType -if TYPE_CHECKING: - from onnxscript._internal.type_annotation import TypeAnnotationValue - _R = TypeVar("_R") _P = ParamSpec("_P") @@ -868,23 +863,16 @@ def __init__(self, value: Any, info: sourceinfo.SourceInfo) -> None: class AttrRef(SymbolValue): - def __init__( - self, attr: ir.Attr, typeinfo: _GenericAlias, info: sourceinfo.SourceInfo - ) -> None: + def __init__(self, attr: ir.Attr, as_bool: bool, info: sourceinfo.SourceInfo) -> None: """Initializes AttrRef. Arguments: attr: An ir.Attr representing the attribute-parameter - typeinfo: type annotation of the attribute. - op's attributes in ONNX are usually single type or list of single type. + as_bool: Whether the attribute is to be interpreted as a bool type (represented as int in ONNX) info: for debugging use. """ super().__init__(attr, info) - self.typeinfo = typeinfo - if not isinstance(typeinfo, (type, _GenericAlias)): - # typing._GenericAlias for List[int] and List[str], etc. - raise TypeError(f"Expecting a type not f{type(typeinfo)} for typeinfo.") - self.typeinfo = typeinfo + self.as_bool = as_bool class DynamicKind(IntFlag): @@ -901,7 +889,7 @@ def __init__( ir_value: ir.Value, kind: DynamicKind, info: sourceinfo.SourceInfo, - typeinfo: TypeAnnotationValue | None = None, + typeinfo: type_annotation.TypeAnnotationValue | None = None, ) -> None: """Represents an ir.Value with some extra information. From ee2fdfb95c4dc39ad998414fc05583d6285c7f5c Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 19:17:35 -0800 Subject: [PATCH 7/9] Minor fix Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 79856137a7..192e2991d2 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -382,8 +382,9 @@ def _to_onnx_var( ) self._castable.add(result_name) return result - if isinstance(val, values.Dynamic): - return val.value + if isinstance(val, values.SymbolValue): + if isinstance(val.value, ir.Value): + return val.value # Assume value is a python-value convertible to a tensor # TODO: check if value is convertible to a TensorProto, so that we can # produce a better error _message otherwise @@ -1130,6 +1131,7 @@ def ret(exp, i, suffix): preferred_name = f"return_val{suffix}" return_var = self._translate_expr(exp, preferred_name) # TODO(rama) val = self._lookup(return_var.name, self._source_of(exp), False) + # TODO(rama): Can we avoid using val.kind here? And rely on the ir.Value methods like is_graph_input()? if val and val.kind == values.DynamicKind.Input: # In ONNX, a graph-input cannot be an output of the graph. # We need to insert a copy. From 75d9471f6e5dd88d049e30def02a264745248379 Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 21:07:52 -0800 Subject: [PATCH 8/9] Checking if value is graph input Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 10 +++++----- onnxscript/_internal/values.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 192e2991d2..7236a40334 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -1131,11 +1131,11 @@ def ret(exp, i, suffix): preferred_name = f"return_val{suffix}" return_var = self._translate_expr(exp, preferred_name) # TODO(rama) val = self._lookup(return_var.name, self._source_of(exp), False) - # TODO(rama): Can we avoid using val.kind here? And rely on the ir.Value methods like is_graph_input()? - if val and val.kind == values.DynamicKind.Input: - # In ONNX, a graph-input cannot be an output of the graph. - # We need to insert a copy. - return_var = self._emit_copy(return_var, preferred_name) + if isinstance(val, values.SymbolValue) and isinstance(val.value, ir.Value): + if val.value.is_graph_input(): + # In ONNX, a graph-input cannot be an output of the graph. + # We need to insert a copy. + return_var = self._emit_copy(return_var, preferred_name) for prev_output in self._current_fn.outputs: if prev_output.name == return_var.name: # ONNX does not allow duplicate output names. diff --git a/onnxscript/_internal/values.py b/onnxscript/_internal/values.py index c7e955e69f..c379f28461 100644 --- a/onnxscript/_internal/values.py +++ b/onnxscript/_internal/values.py @@ -903,5 +903,5 @@ def __init__( assert isinstance(kind, DynamicKind) if not isinstance(ir_value, ir.Value): raise TypeError(f"ir_value must be of type ir.Value not {type(ir_value)!r}.") - self.kind = kind + # self.kind = kind self.typeinfo = typeinfo From c8c2f578be73a08bee3c6ceb02d2df6d9ab175c3 Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Mon, 29 Dec 2025 21:37:01 -0800 Subject: [PATCH 9/9] Remove Dynamic class Signed-off-by: Ganesan Ramalingam --- onnxscript/_internal/converter.py | 19 +++++++----------- onnxscript/_internal/values.py | 33 ------------------------------- onnxscript/values.py | 4 ---- 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/onnxscript/_internal/converter.py b/onnxscript/_internal/converter.py index 7236a40334..d9c367115a 100644 --- a/onnxscript/_internal/converter.py +++ b/onnxscript/_internal/converter.py @@ -1059,7 +1059,7 @@ def assign(lhs: ast.AST, rhs: ast.AST) -> None: typeinfo = None if typeinfo is not None: set_type_info(t, typeinfo) - var = values.Dynamic(t, values.DynamicKind.Intermediate, info, typeinfo) + var = values.SymbolValue(t, info) self._bind(lhs, var) elif isinstance(lhs, ast.Tuple): # Assignments of the form "x, y, z = op.SomeOp(...)" @@ -1082,9 +1082,7 @@ def generate_onnx_name(x: ast.AST): for x, output in zip(lhs.elts, outputs): self._bind( x.id, - values.Dynamic( - output, values.DynamicKind.Intermediate, self._source_of(x) - ), + values.SymbolValue(output, self._source_of(x)), ) else: self.fail(lhs, f"Unsupported construct in LHS of assignment: '{type(lhs)!r}'") @@ -1205,7 +1203,7 @@ def rename(x): for x, y in zip(live_defs, if_outputs): self._bind( x, - values.Dynamic(y, values.DynamicKind.Intermediate, self._source_of(stmt)), + values.SymbolValue(y, self._source_of(stmt)), ) def _translate_loop_stmt(self, loop_stmt: Union[ast.For, ast.While]) -> None: @@ -1272,7 +1270,7 @@ def _translate_loop_stmt(self, loop_stmt: Union[ast.For, ast.While]) -> None: self._current_fn.append_parameter(onnx_loop_var) self._bind( python_loop_var_name, - values.Dynamic(onnx_loop_var, values.DynamicKind.Loop, self._source_of(loop_stmt)), + values.SymbolValue(onnx_loop_var, self._source_of(loop_stmt)), ) self._current_fn.append_parameter( @@ -1293,9 +1291,8 @@ def _translate_loop_stmt(self, loop_stmt: Union[ast.For, ast.While]) -> None: ) self._bind( pv, - values.Dynamic( + values.SymbolValue( ir.Value(name=onnx_var_name), - values.DynamicKind.Loop, self._source_of(loop_stmt), ), ) @@ -1391,7 +1388,7 @@ def rename(x): if isinstance(loop_outputs, ir.Value): loop_outputs = [loop_outputs] for x, loop_output in zip(outputs, loop_outputs): - self._bind(x, values.Dynamic(loop_output, values.DynamicKind.Output, info)) + self._bind(x, values.SymbolValue(loop_output, info)) def _translate_block( self, @@ -1482,9 +1479,7 @@ def _translate_function_signature_common( self._used_vars.add(x.arg) self._bind( x.arg, - values.Dynamic( - onnx_parameter, values.DynamicKind.Input, self._source_of(x) - ), + values.SymbolValue(onnx_parameter, self._source_of(x)), ) if fn.returns: type_annotation = self._eval_constant_expr(fn.returns) diff --git a/onnxscript/_internal/values.py b/onnxscript/_internal/values.py index c379f28461..b6e0b33eb6 100644 --- a/onnxscript/_internal/values.py +++ b/onnxscript/_internal/values.py @@ -11,7 +11,6 @@ import logging import types import typing -from enum import IntFlag from typing import ( # type: ignore[attr-defined] Any, Callable, @@ -873,35 +872,3 @@ def __init__(self, attr: ir.Attr, as_bool: bool, info: sourceinfo.SourceInfo) -> """ super().__init__(attr, info) self.as_bool = as_bool - - -class DynamicKind(IntFlag): - Unknown = 0 - Input = 1 - Output = 2 - Intermediate = 4 - Loop = 8 - - -class Dynamic(SymbolValue): - def __init__( - self, - ir_value: ir.Value, - kind: DynamicKind, - info: sourceinfo.SourceInfo, - typeinfo: type_annotation.TypeAnnotationValue | None = None, - ) -> None: - """Represents an ir.Value with some extra information. - - Arguments: - ir_value: the ir.Value corresponding to this value - kind: the DynamicKind of this variable - info: source-location information for error-messages/debugging - typeinfo: type-information for the value - """ - super().__init__(ir_value, info) - assert isinstance(kind, DynamicKind) - if not isinstance(ir_value, ir.Value): - raise TypeError(f"ir_value must be of type ir.Value not {type(ir_value)!r}.") - # self.kind = kind - self.typeinfo = typeinfo diff --git a/onnxscript/values.py b/onnxscript/values.py index 0b8bd2519a..2759dd5fdf 100644 --- a/onnxscript/values.py +++ b/onnxscript/values.py @@ -7,8 +7,6 @@ from onnxscript._internal.values import ( AttrRef, - Dynamic, - DynamicKind, OnnxClosure, OnnxFunction, Op, @@ -21,8 +19,6 @@ __all__ = [ "AttrRef", - "Dynamic", - "DynamicKind", "OnnxClosure", "OnnxFunction", "Op",