-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expose LexicalScopeContext in checker.py #5693
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
Expose LexicalScopeContext in checker.py #5693
Conversation
e3e29d6
to
c94f216
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know! |
2835105
to
e1497f7
Compare
b39cb02
to
77a498d
Compare
dee15e3
to
1bb82a5
Compare
Signed-off-by: isdanni <leedanni@gmail.com>
8c9295d
to
d3a6864
Compare
Could you resolve conflicts? Thanks! |
Signed-off-by: Danni <leedanni@gmail.com>
btw this PR can be merged now :) @justinchuby |
attr: AttributeProto, ctx: C.CheckerContext = DEFAULT_CONTEXT | ||
attr: AttributeProto, | ||
ctx: C.CheckerContext = DEFAULT_CONTEXT, | ||
lex_ctx: C.LexicalScopeContext = LEXICAL_SCOPE_CONTEXT, |
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.
Sorry for being late to point this out but we should avoid abbreviations for readability. Consider lexical_scope_ctx
(keep ctx
for consistency)?
If @gramalingam likes the suggestion, I suggest creating a follow up PR to amend this change.
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.
lexical_scope_ctx
sounds good to me. I could work on this. Same with parameterizing the checker tests
function: FunctionProto, | ||
ctx: C.CheckerContext, | ||
lex_ctx: C.LexicalScopeContext, |
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.
Should we provide default contexts to check_function as well? This is failing tests in https://github.com/microsoft/onnxscript/actions/runs/6856753046/job/18644541143?pr=1154
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.
Will update tonight!
ctx = checker.C.CheckerContext() | ||
ctx.ir_version = IR_VERSION | ||
ctx.opset_imports = {"": 14} | ||
|
||
lex_ctx = checker.C.LexicalScopeContext() | ||
|
||
checker.check_function(func_nested_identity_add, ctx, lex_ctx) | ||
|
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.
Removed in #5778
### Description - Expose LexicalScopeContext checker Python API <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at e1497f7</samp> ### Summary 📝🔬🐍 <!-- 1. 📝 for updating the type annotations 2. 🔬 for enhancing the lexical scope validation 3. 🐍 for adding and modifying the Python bindings --> This pull request adds lexical scope validation support to the `checker` module of ONNX. It modifies the Python and C++ code to allow users to create and pass `LexicalScopeContext` objects to the checker functions. It also updates the tests and the type annotations for the `checker` module. > _`checker` module_ > _validates lexical scope_ > _autumn of errors_ ### Walkthrough * Add `LEXICAL_SCOPE_CONTEXT` variable to the public API of the `checker` module and remove `helper` module from it ([link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-02263d309b5f73a30725601891d76efb5b1c72e484298bdea671f104e19eb68cR18), [link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-02263d309b5f73a30725601891d76efb5b1c72e484298bdea671f104e19eb68cL42)) * Create a global `LEXICAL_SCOPE_CONTEXT` variable in the `checker` module and use it as the default argument for the `check_attribute`, `check_node`, `check_function`, and `check_graph` functions ([link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-02263d309b5f73a30725601891d76efb5b1c72e484298bdea671f104e19eb68cL59-R61), [link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-02263d309b5f73a30725601891d76efb5b1c72e484298bdea671f104e19eb68cL83-R117)) * Add a Python binding for the `C.LexicalScopeContext` class in the `onnx/cpp2py_export.cc` file and use it to pass the `lex_ctx` argument to the C++ checker functions ([link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-901b627f812650417003b35cded512164308bb73dc9df1e92950b048625d64aeR484-R486), [link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-901b627f812650417003b35cded512164308bb73dc9df1e92950b048625d64aeL504-R545)) * Update the type annotations for the `checker` module in the `onnx/onnx_cpp2py_export/checker.pyi` file to include the `LexicalScopeContext` class and the `lex_ctx` parameter ([link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-f30ab95b6239698fb733b19a75ff6ed19b4b7475c55677d986de0086baa362f7L5-R20)) * Modify the `test_check_function_nested` and `test_check_graph_ir_version_3` functions in the `onnx/test/checker_test.py` file to create and pass custom `lex_ctx` values to the checker functions ([link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-ba056a79b8f17fee8bf49ee51c5f3fadcab77398b81d38c761e838e9c9086d66L94-R101), [link](https://github.com/onnx/onnx/pull/5693/files?diff=unified&w=0#diff-ba056a79b8f17fee8bf49ee51c5f3fadcab77398b81d38c761e838e9c9086d66L101-R110)) ### Motivation and Context Closes onnx#4870 Signed-off-by: isdanni <leedanni@gmail.com> Signed-off-by: Danni <leedanni@gmail.com> Signed-off-by: Linsho Kaku <linsho@preferred.jp>
Description
🤖 Generated by Copilot at e1497f7
Summary
📝🔬🐍
This pull request adds lexical scope validation support to the
checker
module of ONNX. It modifies the Python and C++ code to allow users to create and passLexicalScopeContext
objects to the checker functions. It also updates the tests and the type annotations for thechecker
module.Walkthrough
LEXICAL_SCOPE_CONTEXT
variable to the public API of thechecker
module and removehelper
module from it (link, link)LEXICAL_SCOPE_CONTEXT
variable in thechecker
module and use it as the default argument for thecheck_attribute
,check_node
,check_function
, andcheck_graph
functions (link, link)C.LexicalScopeContext
class in theonnx/cpp2py_export.cc
file and use it to pass thelex_ctx
argument to the C++ checker functions (link, link)checker
module in theonnx/onnx_cpp2py_export/checker.pyi
file to include theLexicalScopeContext
class and thelex_ctx
parameter (link)test_check_function_nested
andtest_check_graph_ir_version_3
functions in theonnx/test/checker_test.py
file to create and pass customlex_ctx
values to the checker functions (link, link)Motivation and Context
Closes #4870