Skip to content
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

Support optional attribute checking in matcher #1629

Merged
merged 10 commits into from
Jul 2, 2024
Merged

Conversation

gramalingam
Copy link
Collaborator

Extend matcher to allow users to specify whether all attributes must be exactly as in pattern. Change default-value to allow extra-attributes in actual node, not specified in pattern.

onnxscript/ir/_convenience.py Show resolved Hide resolved
@@ -205,6 +205,7 @@ def __call__(
domain: str | None = None,
version: int | None = None,
outputs: int | list[str | None] = 1,
_allow_other_attributes: bool | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean the option is experimental and not user facing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really. It is more to avoid conflicts with ONNX attribute names. We discussed doing something similar for other names as well, like domain/version/outputs. Any thoughts about this? May be a good time to do it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. I don't have a better idea yet but I am wishing for one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(Post internal discussion comment): My personal preference and recommendation is to use kwargs with a leading underscore for domain/version/outputs/ etc. This

  • Meets the goal of distinguishing ONNX op attributes from builder's custom options,
  • Involves the least typing effort for users and least cognitive overhead in reading-or-writing (except for using names like domain/version, which fails the first criterion).

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 81.39535% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.58%. Comparing base (3244e92) to head (dcc6985).

Files Patch % Lines
onnxscript/rewriter/pattern.py 50.00% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1629   +/-   ##
=======================================
  Coverage   75.58%   75.58%           
=======================================
  Files         240      240           
  Lines       25653    25690   +37     
  Branches     4615     4621    +6     
=======================================
+ Hits        19389    19418   +29     
- Misses       5385     5390    +5     
- Partials      879      882    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@titaiwangms titaiwangms self-requested a review June 17, 2024 19:52
Copy link

github-actions bot commented Jun 17, 2024

Test Results

     30 files  ±     0      30 suites  ±0   1h 25m 28s ⏱️ - 5m 36s
 11 378 tests  -  1 464   8 772 ✅  - 1 450    2 547 💤 ±     0  59 ❌  - 14 
195 304 runs   - 17 540  60 955 ✅  - 2 704  134 271 💤  - 14 820  78 ❌  - 16 

For more details on these failures, see this check.

Results for commit 2b151af. ± Comparison against base commit 159e5bc.

This pull request removes 1465 and adds 1 tests. Note that renamed tests count towards both.
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0001_dynamo_mobilenetv2_100_dynamo_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0002_dynamo_resnet18_dynamo_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0003_dynamo_Speech2Text2ForCausalLM_dynamo_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0004_torchscript_model_torchscript_model_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0005_attn_llama2_4_34_0_attn_llama2_4_34_0_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0006_attn_llama2_4_34_1_attn_llama2_4_34_1_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0007_attn_llama2_4_36_0_attn_llama2_4_36_0_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0008_attn_phi_1_5_0_attn_phi_1_5_0_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0009_attn_phi_1_5_1_attn_phi_1_5_1_onnx
tests.ir.serde_roundtrip_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_0010_attn_phi_1_5_2_attn_phi_1_5_2_onnx
…
onnxscript.rewriter.pattern_test.RewriteRuleTest ‑ test_optional_attribute

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

LGTM based on discussion. I would document the decision and guideline on how we name the parameters

@justinchuby
Copy link
Collaborator

Should the NodePattern class use the underscore version too? I think we can remove underscore there because attributes are not unpacked.

https://github.com/microsoft/onnxscript/blob/95927da57f79cc7a575aaaa500e1dd7709935139/onnxscript/rewriter/pattern.py#L439C9-L439C32

@justinchuby
Copy link
Collaborator

I would also add a docstring for NodePattern

@gramalingam gramalingam merged commit e824285 into main Jul 2, 2024
44 of 45 checks passed
@gramalingam gramalingam deleted the rama/matcher-attr branch July 2, 2024 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants