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
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions onnxscript/rewriter/_rewrite_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@
f = ir.Function(domain, name, overload, graph=graph, attributes=())
model.functions[f.identifier()] = f

# 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.

if delta.match.nodes and delta.new_nodes:
# Concatenate docstrings from all original nodes
for attribute in attributes:
fused_attribute = "\n".join(
n.metadata_props[attribute] for n in delta.match.nodes if getattr(n, "metadata_props", None) and attribute in n.metadata_props
)
if fused_attribute.strip():
fused_attribute = "Fused from nodes with following attributes: " + fused_attribute
for node in delta.new_nodes:
# Assign to all new nodes
if attribute in node.metadata_props:
node.metadata_props[attribute] += f"\n{fused_attribute}"

Check warning on line 547 in onnxscript/rewriter/_rewrite_rule.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/rewriter/_rewrite_rule.py#L547

Added line #L547 was not covered by tests
else:
node.metadata_props[attribute] = fused_attribute

if verbose:
name = f"{rule.name}: " if rule.name else ""
print(f"----{name}Matched Nodes----")
Expand Down
Loading