Repository navigation
[Fix] diffusion: Keep the linear-GELU verdict cache out of torch.compile traces - #45944
Merged
Merged
Conversation
…ile traces #44643 caches the fused linear+GELU verdict in a module-level WeakKeyDictionary. Under torch.compile dynamo guards on the dict's size, so every new linear a shared block forward sees recompiles that frame. LTX-2 (48 blocks x 2 FFNs) hits recompile_limit on the block forward ("len(...fused_linear_gelu_site._VERDICTS.data) != N") and then runs it eager behind 64 failing guard sets on every call. Compute the verdict directly while tracing, as before #44643; eager calls keep the cache. The verdict is unchanged, so outputs are identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mickqian
requested review from
BBuf,
niehen6174 and
yingluosanqian
as code owners
October 23, 2026 02:25
Collaborator
Author
|
/tag-and-rerun-ci |
This was referenced Oct 23, 2026
Merged
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.
Motivation
#44643 caches the fused linear-GELU verdict per linear in a module-level
WeakKeyDictionary,_VERDICTS. Undertorch.compile, dynamo guards on that dict's size. DiT blocks share one compiled forward, so every new linear a block brings changes the size and recompiles the frame. On 4xB300, an LTX-2 compile run logged this on both ranks:After that, the blocks ran eager behind failing guards on every call.
This fixes a regression introduced by #44643 (same author).
Modifications
In
fused_linear_gelu_site.py,can_use_linear_gelucomputes the input-independent verdict directly while tracing (torch.compiler.is_compiling()), as it did before #44643. Eager calls keep the cache. The verdict is the same either way, so outputs are unchanged.New CUDA test
test_mounted_gelu_sites_compile_one_frame_across_linearsintest_sites.py: 12 blocks with two mounted sites each must compile to one frame. On H200 it fails on main and passes here (test_sites.py27/27; with the dynamic-LoRA PR merged in,test_sites.py+test_quality_fusion_lora.py32/32).This PR and "[Fix] diffusion: Keep dynamic LoRA deltas on fused linear-GELU sites" both edit
can_use_linear_gelu. They merge cleanly in either order. The LoRA PR's adapter check sits above this PR's compile branch, so it also applies while tracing; keep that order if either one is rebased.Accuracy Tests
The same verdict is computed, so the same path runs and outputs are unchanged.
Speed Tests and Profiling
LTX-2 two-stage, compile profile, 2xH200, two interleaved rounds (e2e):
That is −5.5% in both rounds:
recompile_limitline is gone from the log.LTX-2 under compile is still slower than eager on H200, because of graph breaks after attention. That is out of scope here.
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #39889476214
Latest PR Test (Extra): ❌ Run #39889476191
Latest PR Test (AMD ROCm 10): ❌ Run #39889476143