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 <[email protected]>
8c9295d to
d3a6864
Compare
|
Could you resolve conflicts? Thanks! |
Signed-off-by: Danni <[email protected]>
|
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.
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.
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.
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.
Will update tonight!
#5757) ### Description - Use `lexical_scope_ctx` instead of `ctx` in `checker.py` - Provide default contexts in `check_function()` ### Motivation and Context Follow up to #5693 Close #5755 Signed-off-by: isdanni <[email protected]>
| 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) | ||
|
|
### 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 <[email protected]> Signed-off-by: Danni <[email protected]> Signed-off-by: Linsho Kaku <[email protected]>
onnx#5757) ### Description - Use `lexical_scope_ctx` instead of `ctx` in `checker.py` - Provide default contexts in `check_function()` ### Motivation and Context Follow up to onnx#5693 Close onnx#5755 Signed-off-by: isdanni <[email protected]> Signed-off-by: Linsho Kaku <[email protected]>
Description
🤖 Generated by Copilot at e1497f7
Summary
📝🔬🐍
This pull request adds lexical scope validation support to the
checkermodule of ONNX. It modifies the Python and C++ code to allow users to create and passLexicalScopeContextobjects to the checker functions. It also updates the tests and the type annotations for thecheckermodule.Walkthrough
LEXICAL_SCOPE_CONTEXTvariable to the public API of thecheckermodule and removehelpermodule from it (link, link)LEXICAL_SCOPE_CONTEXTvariable in thecheckermodule and use it as the default argument for thecheck_attribute,check_node,check_function, andcheck_graphfunctions (link, link)C.LexicalScopeContextclass in theonnx/cpp2py_export.ccfile and use it to pass thelex_ctxargument to the C++ checker functions (link, link)checkermodule in theonnx/onnx_cpp2py_export/checker.pyifile to include theLexicalScopeContextclass and thelex_ctxparameter (link)test_check_function_nestedandtest_check_graph_ir_version_3functions in theonnx/test/checker_test.pyfile to create and pass customlex_ctxvalues to the checker functions (link, link)Motivation and Context
Closes #4870