Skip to content

Conversation

justinchuby
Copy link
Member

@justinchuby justinchuby commented May 29, 2025

  1. It's now possible to do node.attributes.add(ir.Attr(...)) to avoid having to get the name as a redundant step.

  2. Also allow node attributes to be initialized with a dictionary

    • This way users do not have to use
    ir.Node(attributes=node.attributes.values())

    when copying the node. Instead, it is possible to

    ir.Node(attributes=node.attributes)
  3. Implement get_* methods on attributes to make getting default attributes easier.

    Before

    attr = node.attributes.get("attr")
    if attr is not None:
        value = attr.as_int()
    else:
        value = 42

    now

    value = node.attributes.get_int("attr", 42)

@justinchuby justinchuby requested review from titaiwangms and a team as code owners May 29, 2025 23:57
Copy link

codecov bot commented May 29, 2025

Codecov Report

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

Project coverage is 82.23%. Comparing base (d28c4e6) to head (1392da0).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/onnx_ir/_graph_containers.py 91.54% 6 Missing ⚠️
src/onnx_ir/_core.py 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   81.75%   82.23%   +0.48%     
==========================================
  Files          57       57              
  Lines        6965     7110     +145     
  Branches      948      958      +10     
==========================================
+ Hits         5694     5847     +153     
+ Misses        905      902       -3     
+ Partials      366      361       -5     

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

@justinchuby justinchuby force-pushed the justinchu/initializer-add branch from 9c32b3c to 4f538be Compare May 30, 2025 00:00
@justinchuby justinchuby changed the title Create add methods to initializers and attributes Create add methods on initializers and attributes May 30, 2025
- Also allow attributes to be initialized with a dictionary

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby force-pushed the justinchu/initializer-add branch 2 times, most recently from 2b3d340 to 7496efb Compare May 30, 2025 00:38
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby added the enhancement New feature or request label May 30, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby force-pushed the justinchu/initializer-add branch from 8528f85 to a98e2e5 Compare May 30, 2025 17:22
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby force-pushed the justinchu/initializer-add branch from f81143c to 6859ed6 Compare June 2, 2025 21:35
@justinchuby justinchuby added this to the 0.1.1 milestone Jun 2, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby merged commit c139242 into main Jun 2, 2025
24 checks passed
@justinchuby justinchuby deleted the justinchu/initializer-add branch June 2, 2025 22:27
titaiwangms pushed a commit to titaiwangms/ir-py that referenced this pull request Jun 2, 2025
1. It's now possible to do `node.attributes.add(ir.Attr(...))` to avoid
having to get the name as a redundant step.
2. Also allow node attributes to be initialized with a dictionary
    - This way users do not have to use
    ```py
    ir.Node(attributes=node.attributes.values())
    ```
	when copying the node. Instead, it is possible to

    ```py
    ir.Node(attributes=node.attributes)
    ```
3. Implement get_* methods on attributes to make getting default
attributes easier.

    Before
    ```py
    attr = node.attributes.get("attr")
    if attr is not None:
        value = attr.as_int()
    else:
        value = 42
    ```

    now

    ```py
    value = node.attributes.get_int("attr", 42)
    ```

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Ti-Tai Wang <titaiwang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module: api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants