Skip to content

Studio: share the FLUX.3 joint block int8 ConvRot quant under the span forward - #17337

Merged
danielhanchen merged 1 commit into
mainfrom
studio-flux3-joint-block-shared-quant
Nov 10, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-flux3-joint-block-shared-quant

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

FLUX.3 klein runs 28 of its 33 blocks as joint blocks (Flux3SingleTransformerBlock). #17230 made each FLUX.3 block quantize its modulated input once for Q / K / V and the MLP input together. On current main that sharing never engages for the joint blocks:

  • diffusion_cond_blocks.prepare installs its span-aware joint block forward at load (one modulation row per span for reference images), before the regional compile;
  • diffusion_flux_convrot_fused then looks for the stock diffusers body on Flux3SingleTransformerBlock.forward, finds the span forward instead, and declines (patches {... 'f3_single': False} in the load log).

So every joint block quantizes its input twice per step: once for Q / K / V and once more for ff.linear_in. On an L4 that is one extra rotq_h16 pass of about 0.24 ms per joint block per step (28 x 16 = 448 extra launches per 16 step image).

This PR:

  • applies the joint block patch to the stock forward that the span forward calls whenever a render has no reference span (the text to image path), kept in diffusion_cond_blocks._PATCHED_SINGLE;
  • for renders with a reference span, the span body now asks one helper for the attention and MLP outputs (JOINT_ATTN_FF, set by diffusion_flux_convrot_fused while it is installed). It returns None, and the stock modules run, whenever the block is not on the swapped int8 ConvRot Linears.

Both paths run the same rotation and act quant on the same tensor as before, so the codes and scales are identical. Uninstall restores the recorded stock forward and clears the hook. Kill switch: UNSLOTH_DIFFUSION_FLUX3_SPAN_FUSED=0 keeps the separate MLP-input quant (UNSLOTH_DIFFUSION_FLUX_CONVROT_FUSED=0 still turns off all of it).

Results

Colab L4, torch 2.13 / Triton 3.7.1, compiled default speed mode with CUDA graphs, resident, hosted int8 ConvRot checkpoint (what an INT8 pick loads). One VM for every row; each process is a fresh load, main and this PR alternating, median of 3 renders per process.

FLUX.3 klein, 1024x1024, 16 steps:

s/img per process median s/step median A/A spread (s/img)
main 9.087 / 9.118 / 9.087 9.087 0.5478 0.34%
this PR 8.948 / 8.948 / 8.960 8.948 0.5392 0.13%

-0.14 s per image (-1.5%); the slowest PR process is faster than the fastest main process. Torch peak allocated memory is unchanged (11.64 GiB).

Kernel census, one profiled render each on the same VM: rotq_h16 goes from 1504 to 1056 launches (350 to 230 ms); the int8 GEMM (3168 launches each), attention, rotq_h16x and the Inductor kernels are within 0.3%. The load log now reports 'f3_single': True. 0 graph breaks, 0 recompiles, 3 compiled graphs in every process.

Accuracy, 16 renders (8 prompts x 2 seeds), LPIPS (alex) against the bf16 render on the same VM:

arm mean max
main 0.0175 0.106
main, second process 0.0175 0.106
this PR 0.0159 0.088
this PR, UNSLOTH_DIFFUSION_FLUX3_SPAN_FUSED=0 0.0166 0.103

Paired, this PR minus main: -0.0015 (95% CI -0.0057 to +0.0023). Every producer-fused call checked against the current path on the real activations matched (79 / 79 calls, codes and scales). FLUX.3 renders are not bit-reproducible across processes (each process picks its own Inductor reduction configs, as noted in #17230): the kill switch arm, which runs exactly main's path, differs from main by LPIPS 0.0077 mean, the same as this PR (0.0079).

No change on the other int8 ConvRot families sharing these paths (same VM):

model main s/img this PR s/img A/A spread images vs main
FLUX.2 klein 4B (4 steps) 2.089 2.086 <= 0.8% identical (16 / 16)
Qwen-Image-2.1-Turbo (8 steps) 6.743 6.742 <= 0.4% identical (16 / 16)

Tests

studio/backend/tests/test_diffusion_flux_convrot_fused.py, with the span forward installed first (as the load does):

  • a joint block with and without a reference span, eager and under torch.compile(fullgraph = True), equals stock bit for bit and makes one shared quant call covering Q, K, V and the MLP input;
  • install reports f3_single, is idempotent, and uninstall restores the recorded stock forward and clears the hook;
  • the kill switch keeps the separate quant.

All 6 new tests fail on main and pass here. The rest of the file and the FLUX.3 / cond blocks test files fail the same tests by ID on main and on this branch (CPU, missing optional deps).

Not covered here

  • Budgeted loads that stream the denoiser blocks: their Linears carry offload hooks and the shared paths decline hooked modules by design, so nothing changes there.
  • Renders with reference images (the span path) are covered by the CPU tests only, not by a GPU render.
  • Cards other than the L4 (A100, RTX PRO 6000, B200) and FLUX.3 klein base were not run.

…n forward

diffusion_cond_blocks installs its span-aware Flux3SingleTransformerBlock.forward at load, before the
regional compile, so the flux_convrot_fused f3_single patch saw a non-stock body and declined: every
joint block (28 of 33 FLUX.3 klein blocks) quantized its MLP input separately from Q / K / V.

The joint block patch now goes to the stock forward the span forward delegates to (renders without a
reference span), and the span body reads one shared attention + MLP helper (renders with one). Same op
on the same tensor, so the outputs are unchanged. UNSLOTH_DIFFUSION_FLUX3_SPAN_FUSED=0 restores the
separate quant.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T03:14:01.665611Z 7f26034 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 7f260344b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 762e849 into main Nov 10, 2026
@danielhanchen
danielhanchen deleted the studio-flux3-joint-block-shared-quant branch November 10, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant