Repository navigation
fix: FakeTensorUpdater with the dict processed_hashes in PyTorch main - #5046
Closed
shoumikhin wants to merge 1 commit into
Closed
shoumikhin wants to merge 1 commit into
shoumikhin wants to merge 1 commit into
Conversation
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
force-pushed
the
fix-faketensorupdater-processed-hashes
branch
from
November 15, 2026 17:11
c0870b6 to
18ae455
Compare
3 tasks done
This was referenced Nov 16, 2026
Contributor
Author
|
Folded into #5059. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is wrong today
FakeTensorUpdaterin Torch-TensorRT subclasses the PyTorch class of the same name. When it starts, it marks everycall_functionnode that has nometa["val"]as "not yet processed", so thatincremental_updatefills in the missing fake tensor. It does that withself.processed_hashes.discard(...), which assumesprocessed_hashesis a set.PyTorch main recently changed
processed_hashesinto a dict keyed by node (pytorch/pytorch#204337). With PyTorch main or nightly, any graph with acall_functionnode that lacksmeta["val"]now fails inpost_lowering: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
processed_hashesis a dict, remove the node withpop(node, None). The parent class then sees no stored hash for the node and recomputes its metadata, same as before.discard(hash)path. Thetorch>=2.16.0.devpin 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.tests/py/dynamo/lowering/test_fake_tensor_updater.py. It exports a smallrelu(x + 1)model, deletesmeta["val"]from therelunode, runsFakeTensorUpdater, 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:
AttributeErroraboveI 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 existingtest_batch_cheap_fx_cleanups.pystill passes.black,isortandruffreport no changes.The other known failure on the PyTorch 2.16 nightly, the removal of TorchScript (
torch.jit.script,trace,saveandload), is fixed separately in #5059. Most red jobs on that nightly need both changes.