-
Notifications
You must be signed in to change notification settings - Fork 83
Implement MatchContext class for rewriter pattern matching #2455
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
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
…omments Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
|
@copilot can you add a brief section in the rewriter tutorial explaining this context object? |
…Context Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
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.
Run lintrunner f
|
@copilot can you fix the lint errors by running "lintrunner f" or "lintrunner -a"? |
Co-authored-by: gramalingam <10075881+gramalingam@users.noreply.github.com>
Fixed lint errors by running
Fixed all lint errors by running |
This PR introduces the
PatternMatchContextclass to provide context information during pattern matching in the ONNX rewriter system.Changes Made
Core Implementation
Added
PatternMatchContextclass inonnxscript/rewriter/_basics.pywith read-only properties:model: The model being matchedgraph_or_function: The graph or function being matchedmain_root_node: The main root node of the matching subgraphoutput_values: The output values of the matching subgraphnodes: All nodes of the matching subgraphUpdated pattern matching logic in
onnxscript/rewriter/_rewrite_rule.pyat line 134 to create and passPatternMatchContextinstances to condition functionsExported the new class in the rewriter module's
__all__list for external useUsage Example
Testing
onnxscript/rewriter/pattern_match_context_test.pycovering:Backward Compatibility
contextparameter is passed as the first argument, maintaining the existing**match.bindingspatternValidation
Fixes #2454.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.