-
Notifications
You must be signed in to change notification settings - Fork 89
Migrate ir_builder to use onnx_ir (take 2) #2665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
justinchuby
wants to merge
35
commits into
main
Choose a base branch
from
justinchu/migrate-irbuilder2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
69b08fb
Rename converter
justinchuby 7e0a767
Update fields
justinchuby 8c7abc6
wip
justinchuby 370a9f5
make locals a stack
justinchuby 10473a9
wip
justinchuby 3889e70
wip
justinchuby e09fdcc
update
justinchuby fa60de6
wip
justinchuby 3aff171
wip
justinchuby 761451a
wip
justinchuby 882af66
wip
justinchuby 852cc42
update
justinchuby be610e9
continue
justinchuby 98754ab
Update analysis pass
justinchuby 22eeddc
live_out
justinchuby c74b854
Update if
justinchuby 2c43e9a
fmt
justinchuby c53b8f3
Update emit ordering
justinchuby c84ad91
update emit call
justinchuby 0af0707
attrs
justinchuby 2196f99
return values
justinchuby b56a161
wip
justinchuby 359eb0b
Merge branch 'main' into justinchu/migrate-irbuilder
justinchuby b04a455
wip
justinchuby e4c9576
wip
justinchuby 11a735e
refactor
justinchuby 0cd1f20
_ValueEnvironment
justinchuby d98e8b5
emit_const
justinchuby 38b1c03
Merge branch 'main' into justinchu/migrate-irbuilder
justinchuby f1c10c6
_ValueEnvironment
justinchuby ce2428f
fixme
justinchuby 7f2fd2b
Merge branch 'main' into justinchu/migrate-irbuilder
justinchuby d95fa48
Merge branch 'main' into justinchu/migrate-irbuilder
justinchuby bba0ff6
Merge
justinchuby 7a0b016
WIP
justinchuby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from typing_extensions import ParamSpec | ||
|
|
||
| import onnxscript | ||
| from onnxscript import converter, ir, irbuilder, values | ||
| from onnxscript import _converter, ir, irbuilder, values | ||
| from onnxscript._internal import ast_utils | ||
|
|
||
| _R = TypeVar("_R") | ||
|
|
@@ -29,7 +29,7 @@ | |
| # See if conversion succeeds. | ||
| # TODO: cleanup Converter interface/API, separating checker from | ||
| # converter | ||
| convert = converter.Converter( | ||
| convert = _converter.Converter( | ||
Check failureCode scanning / lintrunner PYLINT/E1120 Error
No value for argument 'root' in constructor call (no-value-for-parameter)
See no-value-for-parameter. To disable, use # pylint: disable=no-value-for-parameter |
||
| opset=opset, | ||
| global_names=global_names, | ||
| source=source, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| import logging | ||
| import types | ||
| import typing | ||
| from enum import IntFlag | ||
| from typing import ( # type: ignore[attr-defined] | ||
| Any, | ||
| Callable, | ||
|
|
@@ -18,15 +17,13 @@ | |
| Protocol, | ||
| Sequence, | ||
| TypeVar, | ||
| _GenericAlias, | ||
| ) | ||
|
|
||
| import onnx | ||
| import onnx.defs | ||
| from typing_extensions import ParamSpec | ||
|
|
||
| from onnxscript import converter as converter_module | ||
| from onnxscript import irbuilder, sourceinfo, type_annotation | ||
| from onnxscript import _converter, irbuilder, type_annotation | ||
| from onnxscript._internal import ast_utils, deprecation | ||
| from onnxscript.ir import _schemas | ||
|
|
||
|
|
@@ -638,7 +635,7 @@ | |
| closure = inspect.getclosurevars(self.func) | ||
| global_names = module.__dict__.copy() | ||
| global_names.update(closure.nonlocals) | ||
| converter = converter_module.Converter( | ||
| converter = _converter.Converter( | ||
Check failureCode scanning / lintrunner PYLINT/E1120 Error
No value for argument 'root' in constructor call (no-value-for-parameter)
See no-value-for-parameter. To disable, use # pylint: disable=no-value-for-parameter |
||
| opset=self._opset, | ||
| global_names=global_names, | ||
| source=src, | ||
|
|
@@ -686,90 +683,3 @@ | |
| # argument order from the Python function definition, which is lost in OpSchema. | ||
| self._param_schemas = _param_schemas_from_function_ir(self.function_ir) | ||
| return self._param_schemas | ||
|
|
||
|
|
||
| class SymbolValue: | ||
| """Represents script-time value information about named variables used in a script. | ||
| At translation-time, the (local) variables of a script, including its parameters, | ||
| are bound to a SymbolValue. | ||
| SymbolValues fall into the following categories: | ||
| AttrRef: Function parameters of attribute-kind, also mapped to ONNX attributes | ||
| Dynamic: values computed at runtime (of tensor type, for now) mapped to NodeArgs. | ||
| Dynamic values include input-parameters of the script, as well intermediate | ||
| values computed in the script. | ||
| For example, consider the following script definition: | ||
| :: | ||
| @script() | ||
| def ThresholdedRelu(X, alpha: float): | ||
| zero = op.CastLike(0, X) | ||
| return op.Where(X > alpha, X, zero) | ||
| Here, `X` has a Dynamic value, `alpha` has an AttrRef value, and `zero` | ||
| has a Dynamic value. | ||
| Scripts may also contain references to global variables, but the translator | ||
| does not associate a SymbolValue with them. The python value of global variables | ||
| is used directly in the translation, and such global variables are intended | ||
| to be used for limited purposes, namely: | ||
| * To identify an opset | ||
| * To represent constant-values, translated into ONNX constants. | ||
| """ | ||
|
|
||
| def __init__(self, info: sourceinfo.SourceInfo) -> None: | ||
| if not isinstance(info, sourceinfo.SourceInfo): | ||
| raise TypeError(f"info must be of type sourceinfo.SourceInfo not {type(info)!r}.") | ||
| self.info = info | ||
|
|
||
|
|
||
| class AttrRef(SymbolValue): | ||
| def __init__( | ||
| self, attr_name: str, typeinfo: _GenericAlias, info: sourceinfo.SourceInfo | ||
| ) -> None: | ||
| """Initializes AttrRef. | ||
| Arguments: | ||
| attr_name: name of 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.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 | ||
|
|
||
|
|
||
| class DynamicKind(IntFlag): | ||
| Unknown = 0 | ||
| Input = 1 | ||
| Output = 2 | ||
| Intermediate = 4 | ||
| Loop = 8 | ||
|
|
||
|
|
||
| class Dynamic(SymbolValue): | ||
| def __init__( | ||
| self, onnx_var: str, kind: DynamicKind, info: sourceinfo.SourceInfo, typeinfo=None | ||
| ) -> None: | ||
| """Initializes Dynamic. | ||
| Arguments: | ||
| onnx_var: the name of the ONNX variable used to represent 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) | ||
| assert isinstance(kind, DynamicKind) | ||
| self.value = onnx_var | ||
| self.kind = kind | ||
| self.typeinfo = typeinfo | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / lintrunner
PYLINT/E1120 Error