Reuse the graph's fake mode when every input is a lifted constant - #22310
Open
msluszniak wants to merge 1 commit into
Open
Reuse the graph's fake mode when every input is a lifted constant#22310msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
_ExportPassBase.call picks the FakeTensorMode to retrace under by
scanning self.inputs() for a FakeTensor. inputs() unwraps a
constant-carrying FakeTensor to its real .constant tensor:
fake = node.meta["val"]
if hasattr(fake, "constant") and fake.constant is not None:
return fake.constant
so a graph whose placeholders are all lifted constants yields no
FakeTensor at all, even though the graph itself is faked. The scan then
falls through to opening a brand new FakeTensorMode, and the pass
retraces under it while the placeholders keep their original fake
tensors. The result is one graph holding tensors from two modes, which
detect_fake_mode() rejects downstream:
File "exir/_program_utils.py", line 27, in get_shape_env
fake_mode = detect_fake_mode(vals)
AssertionError: fake mode (...) from fake tensor input 0 doesn't match
mode (...) from fake tensor input 3
Partitioners produce exactly this shape of submodule: an input
independent subgraph, whose scalar operands are lifted to constant
placeholders when it is split out. A sine positional embedding is enough
to trigger it, and it aborts the whole lowering because the assertion
escapes the pass manager. Seen with the Vulkan backend on RF-DETR.
Recover the graph's own fake mode before falling back to a new one. The
fallback still applies when the graph carries no fake tensors at all, so
passes that genuinely run without one are unaffected.
msluszniak
requested review from
JacobSzwejbka and
larryliu0820
as code owners
August 29, 2026 14:45
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22310
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
msluszniak
added a commit
to software-mansion-labs/executorch
that referenced
this pull request
Aug 30, 2026
_ExportPassBase.call scans self.inputs() for a FakeTensor to pick the mode to retrace under, but inputs() unwraps a constant-carrying FakeTensor to its real .constant tensor. A graph whose placeholders are all lifted constants therefore yields no FakeTensor, falls through to a brand new FakeTensorMode, and ends up holding tensors from two modes, which detect_fake_mode() rejects downstream. Partitioners produce exactly this shape of submodule. Seen with the Vulkan backend on RF-DETR. Backport of upstream pytorch/executorch#22310.
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.
Summary
Fixes #22309.
_ExportPassBase.callpicks theFakeTensorModeto retrace under by scanningself.inputs()for aFakeTensor.inputs()unwraps a constant-carrying fake tensor to its real.constanttensor first, so a graph whose placeholders are all lifted constants yields noFakeTensorat all even though the graph itself is faked. The scan then falls through to opening a brand new mode, the pass retraces under it, and the untouched placeholders keep their original fake tensors. One graph, two modes, rejected downstream bydetect_fake_mode():Partitioners produce exactly this shape of submodule: an input-independent subgraph whose scalar operands become lifted constant placeholders when it is split out. A sine positional embedding is enough to trigger it. Because the assertion escapes the pass manager, one such submodule aborts the whole lowering, and the message names whichever pass happened to be running rather than anything about fake modes.
This recovers the graph's own fake mode before falling back to a new one. The fallback still applies when the graph carries no fake tensors at all, so passes that genuinely run without one are unaffected.
Test plan
New case in
exir/tests/test_pass_infra.pybuilding a graph whose placeholders are constant-carrying fake tensors and asserting the post-pass graph holds a single mode. It fails onmainwithAssertionError: 2 != 1and passes with this change.No regressions across the core pass suites. Same run on
mainand on this branch:The 17 failures are identical on both (byte-identical failure lists) and are pre-existing in my environment, which lacks the compiled portable lib.
End to end: RF-DETR nano now lowers to the Vulkan backend. It needs #22307 and #22308 as well, since it hits all three; with the three applied together,
to_edge_transform_and_lowercompletes over its 15 delegate submodules.