Skip to content
Closed
Changes from 1 commit
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
22 changes: 15 additions & 7 deletions onnxscript/rewriter/_rewrite_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,22 @@
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.

if delta.match.nodes and delta.new_nodes:
# Concatenate metadata props from all original nodes
fused_metadata_props = "Fused: " + "\t\n".join(
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
# 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 ""
Expand Down
Loading