Skip to content

fix: FakeTensorUpdater with the dict processed_hashes in PyTorch main - #5046

Closed
shoumikhin wants to merge 1 commit into
pytorch:mainfrom
shoumikhin:fix-faketensorupdater-processed-hashes
Closed

shoumikhin wants to merge 1 commit into
pytorch:mainfrom
shoumikhin:fix-faketensorupdater-processed-hashes

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What is wrong today

FakeTensorUpdater in Torch-TensorRT subclasses the PyTorch class of the same name. When it starts, it marks every call_function node that has no meta["val"] as "not yet processed", so that incremental_update fills in the missing fake tensor. It does that with self.processed_hashes.discard(...), which assumes processed_hashes is a set.

PyTorch main recently changed processed_hashes into a dict keyed by node (pytorch/pytorch#204337). With PyTorch main or nightly, any graph with a call_function node that lacks meta["val"] now fails in post_lowering:

AttributeError: 'dict' object has no attribute 'discard'

One way to get such a node is the write-back copy_ that functionalization leaves behind for an in-place custom op.

What this change does

  • If processed_hashes is a dict, remove the node with pop(node, None). The parent class then sees no stored hash for the node and recomputes its metadata, same as before.
  • Otherwise keep the old discard(hash) path. The torch>=2.16.0.dev pin still allows nightlies from before the PyTorch change, and those still use the set. A TODO notes that the set path can go once the minimum PyTorch includes the change.
  • Add tests/py/dynamo/lowering/test_fake_tensor_updater.py. It exports a small relu(x + 1) model, deletes meta["val"] from the relu node, runs FakeTensorUpdater, and checks that the node gets back a fake tensor with the right shape and dtype. It runs on CPU and does not build an engine.

Testing

In a fresh virtual environment on Linux x86_64, with a Python-only editable install of this branch, run on CPU:

python -m pytest tests/py/dynamo/lowering/test_fake_tensor_updater.py -v
PyTorch Without this change With this change
nightly 2.16.0.dev20261114 (dict) fails with the AttributeError above passes
nightly 2.16.0.dev20261112 (set) passes passes

I also checked that the test fails (KeyError: 'val') when the new dict branch is replaced by a no-op, so it checks that the metadata is filled in, not only that nothing crashes. The existing test_batch_cheap_fx_cleanups.py still passes. black, isort and ruff report no changes.

The other known failure on the PyTorch 2.16 nightly, the removal of TorchScript (torch.jit.script, trace, save and load), is fixed separately in #5059. Most red jobs on that nightly need both changes.

@meta-cla meta-cla Bot added the cla signed label Nov 15, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Nov 15, 2026
@github-actions
github-actions Bot requested a review from zewenli98 November 15, 2026 04:54
PyTorch main changed FakeTensorUpdater.processed_hashes from a set of
node hashes to a dict keyed by node (pytorch/pytorch#204337). Our
FakeTensorUpdater subclass still calls processed_hashes.discard(), so on
PyTorch main and nightly it fails with

    AttributeError: 'dict' object has no attribute 'discard'

whenever the graph has a call_function node without meta["val"]. This
breaks post_lowering for such graphs, for example the write-back copy_
left by functionalizing an in-place custom op.

Pop the node from the dict when processed_hashes is a dict, and keep the
old set path for PyTorch builds made before that change, which the
current torch>=2.16.0.dev pin still allows.

Add a small test that removes meta["val"] from a node of an exported
graph and checks that FakeTensorUpdater fills it in again.
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Folded into #5059.

@shoumikhin shoumikhin closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant