Repository navigation
Studio diffusion: keep the fused AdaLN census out of compiled FLUX.1 blocks (recompile limit on first render) - #17310
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
FLUX.1 (schnell and dev) loaded in Studio on NVIDIA Linux at the default speed tier fails its first render with
Seen on a Colab A100 40GB with auto INT8 (the default there) at ed3eec6, in every repeat.
Root cause
Since #16760 the fused AdaLN forwards are installed on NVIDIA Linux off the
offtier, including the compiled tiers. Undertorch.compile,_fused_modulatecorrectly returns None so the stock math is traced. The engagement censusCOUNTS["adaln_stock"] += 1still runs inside the trace, though. Dynamo treats a write to a module-global dict as a side effect: it guards on the current value (COUNTS['adaln_stock'] == 139) and replays the increment after the graph. The next call therefore always fails the guard, so every block call compiles a new graph.FLUX.1 is the only family affected because its repeated blocks (
FluxTransformerBlock,FluxSingleTransformerBlock) callAdaLayerNormZero/AdaLayerNormZeroSingleinside the regionally compiled region. FLUX.2 modulates inline and only usesAdaLayerNormContinuousin the eagernorm_out. Z-Image, Qwen-Image and FLUX.3 never install these forwards. The single block hits the limit first (38 calls per step against 19 for the double block), underfullgraph=True. That kills the CUDA graph capture and then the eager fallback. The audit run's per-process stats show 121 unique graphs for FLUX.1, against 2 for FLUX.2 klein and Z-Image. This is not int8 specific: a bf16 FLUX.1 at the compiled tiers hits the same guard.The RoPE wrapper in the same file and the fp8 unit-scale path already skip their counters while compiling. AdaLN was the one that did not.
Fix
The AdaLN census now goes through
_count(), which only increments outside a trace (torch.compiler.is_compiling()). Eager counting is unchanged, there are no new graph breaks,fullgraphis kept, and compiled output does not change (the traced math was already the stock branch).Tests
studio/backend/tests/test_diffusion_rocm_fused.py, CPU only:test_compiled_adaln_never_recompiles_per_call(3 classes): compiles a call through each patched AdaLN class withfullgraph=True, dynamic=Falseundererror_on_recompile, checks the output against eager and checks the census is untouched while compiled.test_tiny_flux1_regional_compile_holds_its_graphs_across_steps: a tinyFluxTransformer2DModelwithcompile_repeated_blocks(fullgraph=True, dynamic=False)(Studio's FLUX.1 settings), three denoise steps; the graph count after step 1 must not grow.RecompileErrorx3,recompile limit exceededon the tiny FLUX.1)