Skip to content

[DRAFT] Merge metadata props when fusing #2375

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bmehta001
Copy link
Contributor

No description provided.

@bmehta001 bmehta001 force-pushed the merge-docstrings-when-fusing branch from 0ffe2bd to cd8ea57 Compare June 12, 2025 17:49
Comment on lines 537 to 539
fused_metadata_props = "Fused: " + "\t\n".join(
n.metadata_props for n in delta.match.nodes if getattr(n, "metadata_props", None)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

n will always have metadata_props.

n.metadata_props for n in delta.match.nodes if getattr(n, "metadata_props", None)
)
# Assign to all new nodes (or just the first, depending on your policy)
delta.new_nodes[0].metadata_props += fused_metadata_props
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer metadata_props.update()

# If we are fusing nodes, update the metadata props of the new node(s)
if delta.match.nodes and delta.new_nodes:
# Concatenate metadata props from all original nodes
fused_metadata_props = "Fused: " + "\t\n".join(
Copy link
Collaborator

@justinchuby justinchuby Jun 12, 2025

Choose a reason for hiding this comment

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

I would consider creating special reconciliation logic for known fields

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1. I am also confused a bit here. Isn't metadata_props effectively a dict[str, str]? I am not sure how the proto is represented in onnx-ir, but assuming it is a dictionary. We should be merging the dictionaries, using special merging logic for known entries in the dictionary.

This may require us to extend the definition/documentation of specific metadata fields. For example, we may need a way to represent a set of source-locations, instead of a single source-location, for a source-location metadata.

Copy link

codecov bot commented Jun 19, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.28%. Comparing base (dcf98c8) to head (eff274c).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/rewriter/_rewrite_rule.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2375      +/-   ##
==========================================
+ Coverage   70.15%   70.28%   +0.12%     
==========================================
  Files         197      199       +2     
  Lines       24985    25233     +248     
  Branches     2669     2691      +22     
==========================================
+ Hits        17529    17735     +206     
- Misses       6529     6566      +37     
- Partials      927      932       +5     

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

@@ -531,14 +531,22 @@ def _apply_to_graph_or_function(
f = ir.Function(domain, name, overload, graph=graph, attributes=())
model.functions[f.identifier()] = f

# If we are fusing nodes, update the metadata props of the new node(s)
# If we are fusing nodes, update the docstring of the new node(s)
attributes = ["namespace", "pkg.torch.onnx.class_hierarchy", "pkg.torch.onnx.fx_node", "pkg.torch.onnx.name_scopes", "pkg.torch.onnx.stack_trace"]
Copy link
Collaborator

@justinchuby justinchuby Jun 19, 2025

Choose a reason for hiding this comment

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

For namespace, class_hierarchy and name_scopes, we should parse the info and find the common leading scopes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants