Skip to content

[Fix] diffusion: Keep the linear-GELU verdict cache out of torch.compile traces - #45944

Merged
mickqian merged 1 commit into
mainfrom
mick/diffusion-gelu-verdict-compile-guard
Oct 23, 2026
Merged

mickqian merged 1 commit into
mainfrom
mick/diffusion-gelu-verdict-compile-guard

Conversation

@mickqian

@mickqian mickqian commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

#44643 caches the fused linear-GELU verdict per linear in a module-level WeakKeyDictionary, _VERDICTS. Under torch.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:

torch._dynamo hit config.recompile_limit (64) ... ltx_2.py:1263 ... last reason: len(...fused_linear_gelu_site._VERDICTS.data) != 28

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_gelu computes 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_linears in test_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.py 27/27; with the dynamic-LoRA PR merged in, test_sites.py + test_quality_fusion_lora.py 32/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):

round 1 round 2
main 10.754 s 10.487 s
this PR 10.152 s 9.915 s

That is −5.5% in both rounds:

  • stage-1 step time: 0.198–0.206 s → 0.185–0.190 s;
  • server ready: 128 s → 104 s;
  • the recompile_limit line 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

…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

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant