-
Notifications
You must be signed in to change notification settings - Fork 101
Raise version converter error when function attribute is RefAttr #2806
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
Open
titaiwangms
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
titaiwangms:titaiwang/raise_refattr_function_vc
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.
+72
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
36a846e
fix
titaiwangms eac3cf8
Update onnxscript/version_converter/_version_converter_test.py
titaiwangms 5ce524f
Update onnxscript/version_converter/_version_converter.py
titaiwangms a5b0d86
Merge branch 'main' into titaiwang/raise_refattr_function_vc
titaiwangms 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,73 @@ def test_metadata_is_copied_to_multiple_replacement_nodes(self): | |
| f"Node {i} ({node.op_type}) should have metadata copied", | ||
| ) | ||
|
|
||
| def test_version_convert_raises_on_function_node_with_ref_attribute(self): | ||
| """Test that version conversion raises when a function contains a node with a ref attribute.""" | ||
| # Build a function with a LeakyRelu node that uses a RefAttr for 'alpha' | ||
| func_input = ir.Value(name="x") | ||
| ref_attr = ir.RefAttr("alpha", "alpha", ir.AttributeType.FLOAT) | ||
| func_output = ir.Value(name="result") | ||
| leaky_relu_node = ir.Node( | ||
| domain="", | ||
| op_type="LeakyRelu", | ||
| inputs=[func_input], | ||
| outputs=[func_output], | ||
| attributes=[ref_attr], | ||
| version=18, | ||
| ) | ||
| func_graph = ir.Graph( | ||
| inputs=[func_input], | ||
| outputs=[func_output], | ||
| nodes=[leaky_relu_node], | ||
| opset_imports={"": 18}, | ||
| ) | ||
| func_attr_param = ir.Attr("alpha", ir.AttributeType.FLOAT, 0.01) | ||
| function = ir.Function( | ||
| domain="pkg.custom", | ||
| name="leaky_relu_func", | ||
| graph=func_graph, | ||
| attributes=[func_attr_param], | ||
| ) | ||
|
|
||
| # Build a main graph that calls the function | ||
| main_input = ir.Value(name="input_x") | ||
| main_output = ir.Value(name="output") | ||
| call_node = ir.Node( | ||
| domain="pkg.custom", | ||
| op_type="leaky_relu_func", | ||
| inputs=[main_input], | ||
| outputs=[main_output], | ||
| version=18, | ||
| ) | ||
| main_graph = ir.Graph( | ||
| inputs=[main_input], | ||
| outputs=[main_output], | ||
| nodes=[call_node], | ||
| opset_imports={"": 18, "pkg.custom": 1}, | ||
| ) | ||
| model = ir.Model( | ||
| main_graph, | ||
| ir_version=8, | ||
| functions=[function], | ||
| ) | ||
|
|
||
| target_version = 20 | ||
| with self.assertRaises( | ||
| ( | ||
| version_converter._version_converter.VersionConverterError, # pylint: disable=protected-access | ||
| ir.passes.PassError, | ||
| ) | ||
| ) as ctx: | ||
| version_converter.convert_version(model, target_version=target_version) | ||
| # Check the error message, unwrapping PassError if needed | ||
| error = ctx.exception | ||
| if isinstance(error, ir.passes.PassError) and error.__cause__ is not None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use assertRegex, after the error is properly raised |
||
| error = error.__cause__ | ||
| self.assertIn( | ||
| "has ref attribute, which is not supported by version converter", | ||
| str(error), | ||
| ) | ||
|
|
||
|
|
||
| class VersionConverter25to26Test(unittest.TestCase): | ||
| @pytest.mark.xfail(strict=True, reason="Version upgrade beyond 25 not yet supported.") | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an issue that PassError is raised. I realized this in the shape inferencer as well. I think we should find a way to move the main logic out of the pass, and make the pass a simple wrapper around the logic so VersionConverterError can be properly raised by
convert_version