-
Notifications
You must be signed in to change notification settings - Fork 72
Returning choice values in patterns #2284
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
Conversation
For my understanding, could you explain more on what "returned choice-values are already covered by the other output values" means? |
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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.
Pull Request Overview
This PR fixes the handling of Choice values when used as return values in patterns and refines value-binding logic to facilitate returning these values. In addition, it extends the backward slice computation to include value patterns and updates the matching and output retrieval methods accordingly.
- Extend the _add_backward_slice API to incorporate backward_slice_values.
- Update GraphPattern initialization to check for uncovered choice values.
- Refactor binding logic (bind_value and _get_output_values) for improved consistency.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
onnxscript/rewriter/pattern_test.py | Adds a new test to verify that OrValue can be returned from a pattern. |
onnxscript/rewriter/pattern.py | Updates various methods (e.g., bind_value, _add_backward_slice, GraphPattern.init, _get_output_values) to support returning choice values. |
Comments suppressed due to low confidence (1)
onnxscript/rewriter/pattern.py:973
- The new parameter 'backward_slice_values' is not documented. Consider updating the docstring to explain its purpose and usage.
def _add_backward_slice(node: NodePattern, backward_slice: set[NodePattern], backward_slice_values: set[ValuePattern]) -> None:
"value1 is covered by value2" is just shorthand here for "value1 is transitively used to compute value2". In the pattern-matching situation, a successful backward match for "value2" would also have found a match for "value1". Consider a pattern that includes
Here, if we have successfully matched a subgraph for value2, we no longer need to do any more search to match value1, it is guaranteed to have already been found. |
@gramalingam looks like the docs workflow failed: https://github.com/microsoft/onnxscript/actions/runs/14933269595/job/41954640986 |
A fix for the use of Choice values (i.e.,
OrValue([choice1, choice2])
as a return-value in the pattern (that is, as a root of the pattern). This is a bit complicated to support with the current implementation, which is oriented towards iterating over the nodes in the graph, and matching them against pattern-nodes. This PR provides a limited extension (which handles the case in PR 2277): when the returned choice-values are already covered by the other output values, they can be supported by the existing matcher.Also, on a related note, fix how value-bindings are handled in the pattern-matcher to make it easier to return these values as the outputs of the pattern.