-
Notifications
You must be signed in to change notification settings - Fork 93
A few fixes relating to constant propagation #1892
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
df26a53
Move compute constant value utility
gramalingam 1954086
Compute constant computation into core
gramalingam e770ebc
Avoid reference implementation for Constant op
gramalingam 0fe52af
Remove _ir_utils file
gramalingam f816280
Undo const prop in ir core
gramalingam 18862b9
Lint fixes
gramalingam 2b497fb
Merge branch 'main' into rama/const-prop
gramalingam 3c15d4b
Update documentation
gramalingam c1fa51f
Merge branch 'rama/const-prop' of https://github.com/microsoft/onnx-s…
gramalingam 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
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 |
|---|---|---|
| @@ -1,46 +1,13 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| """This is a temporary utility to assist new IR while it's still under development.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import typing | ||
|
|
||
| import numpy as np | ||
|
|
||
| from onnxscript import ir | ||
|
|
||
| GRAPH_OUTPUT_META_KEY = "pkg.onnxscript.rewriter.generic_pattern.graph_output" | ||
|
|
||
|
|
||
| def propagate_const_value(ir_value: ir.Value) -> ir.Value: | ||
| """Temporary method to propagate a constant value to the IR value.""" | ||
| node = ir_value.producer() | ||
| if node is None: | ||
| return ir_value | ||
| if node.op_type != "Constant": | ||
| return ir_value | ||
| attr_name, attr_value = next(iter(node.attributes.items())) | ||
| if attr_value is None or not isinstance(attr_value, ir.Attr): | ||
| return ir_value | ||
| import onnxscript.ir as ir | ||
| from onnxscript.optimizer import basic_constant_propagation | ||
|
|
||
| const_value: ir.TensorProtocol | ||
| if attr_name in {"value_float", "value_floats"}: | ||
| const_value = ir.Tensor( | ||
| np.array(attr_value.value, dtype=np.float32), name=ir_value.name | ||
| ) | ||
| elif attr_name in {"value_int", "value_ints"}: | ||
| const_value = ir.Tensor(np.array(attr_value.value, dtype=np.int64), name=ir_value.name) | ||
| elif attr_name in {"value_string", "value_strings"}: | ||
| const_value = ir.StringTensor( | ||
| np.array(attr_value.value, dtype=np.bytes_), name=ir_value.name | ||
| ) | ||
| elif attr_name == "value": | ||
| const_value = typing.cast(ir.TensorProtocol, attr_value.value) | ||
| else: | ||
| return ir_value | ||
|
|
||
| ir_value.const_value = const_value | ||
| ir_value.shape = const_value.shape # type: ignore | ||
| ir_value.dtype = const_value.dtype | ||
| return ir_value | ||
| def get_const_value(value: ir.Value) -> ir.TensorProtocol | None: | ||
| node = value.producer() | ||
| if node is not None: | ||
| basic_constant_propagation([node]) | ||
| return value.const_value |
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
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.
Uh oh!
There was an error while loading. Please reload this page.