SIGN IN SIGN UP

[fx] Shallow-copy `from_node` provenance in `NodeSource` instead of deepcopy (#193051) (#193051)

Summary:

`NodeSource.__init__` recursively deep-copies `node.meta["from_node"]` whenever a pass-retraced node is created. Because each provenance list contains earlier `NodeSource` records, repeated pass replay copies an increasingly large provenance tree and can make this path approximately quadratic in pass depth.

Copy only the outer list with `list(...)`. This preserves snapshot semantics for callers that later append to the original list while sharing the existing provenance records. Those records are treated as immutable after construction; existing code already aliases or shallow-copies them.

The regression test makes the contract explicit: the captured outer list is distinct, later mutations to the original list are not observed, existing `NodeSource` entries remain shared by identity, and `to_dict()` serialization is unchanged. This is a targeted complexity reduction; it does not change graph structure, node metadata contents, or serialization format.

In a representative U55 workflow targeting ExecuTorch, this reduced warm end-to-end model export/lowering time by ~15% (406s → 342s, not insignificant).

Differential Revision: D109215317

Pull Request resolved: https://github.com/pytorch/pytorch/pull/193051
Approved by: https://github.com/aorenste
A
Andrew Pullin committed
0184680c5f3d24802a8c7e56996d189b9ca08d35
Parent: 48c8844
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com> on 8/25/2026, 5:13:15 PM