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
9 changes: 9 additions & 0 deletions onnxscript/rewriter/_rewrite_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,15 @@ 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 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.

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.

# 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 verbose:
name = f"{rule.name}: " if rule.name else ""
print(f"----{name}Matched Nodes----")
Expand Down
Loading