Skip to content

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

Merged

Conversation

isdanni
Copy link
Contributor

@isdanni isdanni commented Oct 21, 2023

Description

  • Expose LexicalScopeContext checker Python API

🤖 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 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, link)
  • 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, link)
  • 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, link)
  • 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)
  • 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, link)

Motivation and Context

Closes #4870

@isdanni isdanni requested a review from a team as a code owner October 21, 2023 01:14
@isdanni isdanni force-pushed the expose-lexical-scope-context-in-checker branch 3 times, most recently from e3e29d6 to c94f216 Compare October 21, 2023 02:04
@codecov
Copy link

codecov bot commented Oct 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
onnx/checker.py 91.83% <100.00%> (+0.92%) ⬆️
onnx/test/checker_test.py 99.21% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

📢 Thoughts on this report? Let us know!

@isdanni isdanni force-pushed the expose-lexical-scope-context-in-checker branch from 2835105 to e1497f7 Compare October 21, 2023 02:21
@isdanni isdanni force-pushed the expose-lexical-scope-context-in-checker branch 2 times, most recently from b39cb02 to 77a498d Compare November 2, 2023 03:34
@isdanni isdanni requested a review from a team as a code owner November 2, 2023 03:34
@isdanni isdanni force-pushed the expose-lexical-scope-context-in-checker branch 2 times, most recently from dee15e3 to 1bb82a5 Compare November 2, 2023 04:07
Signed-off-by: isdanni <leedanni@gmail.com>
@isdanni isdanni force-pushed the expose-lexical-scope-context-in-checker branch from 8c9295d to d3a6864 Compare November 3, 2023 02:38
@isdanni isdanni requested a review from gramalingam November 5, 2023 23:11
@justinchuby
Copy link
Member

Could you resolve conflicts? Thanks!

@justinchuby
Copy link
Member

@gramalingam

Signed-off-by: Danni <leedanni@gmail.com>
@justinchuby justinchuby enabled auto-merge November 9, 2023 00:23
@justinchuby justinchuby disabled auto-merge November 9, 2023 00:23
@isdanni
Copy link
Contributor Author

isdanni commented Nov 9, 2023

btw this PR can be merged now :) @justinchuby

@justinchuby justinchuby added this pull request to the merge queue Nov 9, 2023
attr: AttributeProto, ctx: C.CheckerContext = DEFAULT_CONTEXT
attr: AttributeProto,
ctx: C.CheckerContext = DEFAULT_CONTEXT,
lex_ctx: C.LexicalScopeContext = LEXICAL_SCOPE_CONTEXT,
Copy link
Member

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.

Copy link
Contributor Author

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

Merged via the queue into onnx:main with commit 799dcfe Nov 9, 2023
Comment on lines +103 to +105
function: FunctionProto,
ctx: C.CheckerContext,
lex_ctx: C.LexicalScopeContext,
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update tonight!

@justinchuby
Copy link
Member

#5755

github-merge-queue bot pushed a commit that referenced this pull request Nov 14, 2023
#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 <leedanni@gmail.com>
Comment on lines +95 to 102
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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in #5778

linshokaku pushed a commit to linshokaku/onnx that referenced this pull request Oct 2, 2024
### 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>
linshokaku pushed a commit to linshokaku/onnx that referenced this pull request Oct 2, 2024
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 <leedanni@gmail.com>
Signed-off-by: Linsho Kaku <linsho@preferred.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Expose lexical scope context in Python checker
4 participants