Repository navigation
Studio: share the FLUX.3 joint block int8 ConvRot quant under the span forward - #17337
Merged
Merged
Conversation
…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.
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
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
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.prepareinstalls its span-aware joint block forward at load (one modulation row per span for reference images), before the regional compile;diffusion_flux_convrot_fusedthen looks for the stock diffusers body onFlux3SingleTransformerBlock.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 extrarotq_h16pass of about 0.24 ms per joint block per step (28 x 16 = 448 extra launches per 16 step image).This PR:
diffusion_cond_blocks._PATCHED_SINGLE;JOINT_ATTN_FF, set bydiffusion_flux_convrot_fusedwhile 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=0keeps the separate MLP-input quant (UNSLOTH_DIFFUSION_FLUX_CONVROT_FUSED=0still 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:
-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_h16goes from 1504 to 1056 launches (350 to 230 ms); the int8 GEMM (3168 launches each), attention,rotq_h16xand 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:
UNSLOTH_DIFFUSION_FLUX3_SPAN_FUSED=0Paired, 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):
Tests
studio/backend/tests/test_diffusion_flux_convrot_fused.py, with the span forward installed first (as the load does):torch.compile(fullgraph = True), equals stock bit for bit and makes one shared quant call covering Q, K, V and the MLP input;f3_single, is idempotent, and uninstall restores the recorded stock forward and clears the hook;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