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