Repository navigation
Studio: hosted ConvRot INT8 file for FLUX.1-schnell (inert until the file is published) - #18639
Merged
Merged
Conversation
…cover FLUX.1-schnell's hosted ConvRot resolution
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. 👍 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". |
danielhanchen
added a commit
that referenced
this pull request
Nov 20, 2026
…nell ConvRot mapping (#18652) ## Summary `Backend CI / (Python 3.13, diffusion)` is red on `main` (seen on #18650, reproduced on current `main`): ``` FAILED tests/test_diffusion_family_data_freeze.py::test_family_data_resolves_identically E AssertionError: per_family E {'flux.1': {... 'convrot_default_on': True, ...}} != {'flux.1': {... 'convrot_default_on': False, ...}} ``` ## Cause #18639 deliberately gave `flux.1` a hosted ConvRot INT8 spec: `FLUX.1-schnell-INT8-ConvRot.safetensors` in `unsloth/FLUX.1-schnell-FP8`, `default_on = True`. The freeze test exists to make every such change explicit. Its docstring says a deliberate change regenerates the fixture with `UNSLOTH_FREEZE_UPDATE=1`, and the fixture diff is the review artifact. #18639 did not regenerate it, so the code change is intended and the frozen snapshot is stale. ## Change `studio/backend/tests/fixtures/diffusion_family_data_freeze.json`, regenerated with `UNSLOTH_FREEZE_UPDATE=1` and `UNSLOTH_DIFFUSION_INT8_CONVROT` unset. The diff (6 lines added, 3 removed) contains only #18639's change for `flux.1`: - `convrot_default_on`: `false` to `true`; - `convrot_filename` and `convrot_repo`: `null` to the schnell ConvRot file and repo; - `flux.1` added to the family tables: the default-on set, filename map and repo map. No exclude-token, NVFP4 or other family entry moves. Those are the sets baked into published prequant artifacts, so hosted checkpoints are unaffected. ## Testing - `tests/test_diffusion_family_data_freeze.py`: fails on `main` with the diff above, passes with this fixture. - `tests/test_diffusion_flux1_convrot_hosted.py` (#18639's own tests) still passes: 14 passed together.
danielhanchen
added a commit
that referenced
this pull request
Nov 22, 2026
…tput into the rotation, and shares one Q/K/V quant (#18766) FLUX.1-schnell on the hosted ConvRot INT8 file (#18639) was about 5% slower per image than plain INT8 on an RTX PRO 6000. Two things caused it. The FLUX.2 / FLUX.3 producer fusion (`diffusion_flux_convrot_fused`) did not cover `FluxTransformer2DModel`, so every rotated Linear rotated and quantized its own input: Q, K and V each rotated the same activation, in both the double and the single blocks. Also, the GELU(tanh) MLP output (and, in single blocks, the concat with the attention output) was written to HBM in bf16, then read back by `rotq_h16`. ## Change - `diffusion_flux_convrot_fused`: FLUX.1 patches, scoped to the modules `install` marks on a FLUX.1 denoiser with ConvRot Linears. - `transformer_flux._get_projections` shares one rotation + act quant for Q / K / V and for the added context Q / K / V. This is the same wrapper FLUX.2 uses, and the diffusers body is the same. - `FeedForward.forward` (GELU tanh, Dropout, rotated down projection) and `FluxSingleTransformerBlock.forward` (diffusers' body, or the arch patch's addcmul body when that one is installed) give `proj_out` / `net[2]` the projection output, plus the attention output in its own layout. Neither the GELU product nor the concat is written. - Every gate is checked per call. Anything else (no mark, hooks, LoRA, offload, other dtypes) runs the stock forward. - `diffusion_convrot_quant`: - `rotq_h16x` gets `ACT = 2`: GELU(tanh) of the gate only, so the value is never loaded. - New op `unsloth_studio::convrot_gelu_act_quant_int8(prefix?, gate, group, v2)`, with a fake impl. - The GELU helper follows ATen / Inductor op for op (one FMA for `x + k x^3`, pinned `*_rn`, plain multiplies at the end so subnormal inputs keep `0.5 * x`). - The probe first checks every finite bf16 input bit for bit against `F.gelu(approximate="tanh")`, then runs `codes_close` on FLUX.1's shapes, including the [attention | GELU] row and GELU's non-monotonic tail. - Armed on sm89 and sm120 (measured). Each card keeps the stock path where the fused kernel measured slower: below 1024 rows on L4; on RTX PRO 6000 below 2048 rows with the attention prefix and always without it (the FF measured 0.94x there). The 256-row text-stream MLP is excluded everywhere. - The probe verdict is persisted with the other ConvRot verdicts (card fingerprint + source hash), and its kernels join the probe prewarm pool, so only a card's first load compiles them (on a thread pool). Later loads take the same time as main's. - ROCm gets a portable helper built on `triton.language.extra.libdevice` (no `*_rn` there). - `diffusion_int8_gemm.gelu_linear`: the producer-fed GEMM, a copy of `producer_linear` without the value. - Kill switches: - `UNSLOTH_DIFFUSION_FLUX_CONVROT_FUSED=0` restores main exactly: no FLUX.1 patch is installed and the stock functions come back. - `UNSLOTH_DIFFUSION_FLUX1_GELU_FUSED=0` or `UNSLOTH_DIFFUSION_INT8_ROTQUANT_PRODUCER=0` turn off only the GELU producer. The shared Q / K / V quant stays; it is the same op on the same tensor, so images are bit-identical to main either way. - Scope: the FLUX.1 patches sit on module-wide diffusers code that other families reuse. Chroma calls `transformer_flux._get_projections`, and every model has `FeedForward`. So they act only on the attentions, FeedForwards and single blocks that `install` marked on a FLUX.1 denoiser. A ConvRot Chroma loaded after a ConvRot FLUX.1 in the same process keeps its stock projections. The mark is read from the instance `__dict__` first, so an unmarked module pays one dict lookup per call. - A failed GELU probe is logged at info level with the reason; FLUX.1 then keeps the compiled GELU + concat path. ## Results RTX PRO 6000 Blackwell (sm120), Colab. FLUX.1-schnell, 1024 px, 4 steps, 8 prompts, guidance 0, Studio `begin_load` int8 with the ConvRot file built on the VM. Compiled + CUDA graphs, resident. Each cell is a fresh process, and the A/A repeats were interleaved. | arm | steady s/image (3 reps) | s/step | peak_alloc GiB | images vs main | |---|---|---|---|---| | main | 0.6713-0.6737 | 0.1507-0.1510 | 24.42 | - | | shared Q / K / V only (`UNSLOTH_DIFFUSION_FLUX1_GELU_FUSED=0`) | 0.6475 | 0.1443-0.1445 | 24.42 | 8/8 bit-identical | | this PR | 0.6243-0.6277 | 0.1389-0.1391 | 24.42 | 8/8 bit-identical | - s/step is 7.9% lower than main and s/image 7.1% lower. The A/A spread is under 0.4%. These numbers are from the final head of this branch. An earlier session gave the same result: 0.1390 vs 0.1512. - Load time in a new process: 8.2 s for both main and this PR once the card's verdict is stored. The first load on a card takes 14.4 s, because it prewarms the probe kernels on 8 threads and stores the verdict. - LPIPS is 0.0 against main on every prompt. Repeats are bit-identical. - 0 graph breaks, 0 recompiles, and no CUDA graph fallbacks in any cell. - Rotation launches per render: 1676 on main, 1068 with shared Q / K / V only, 916 here. GELU producer calls: 152. The FF producer stays off on sm120 (0.94x alone), so those calls are the single-block proj_out. Kernel alone (quant stage, `do_bench_cudagraph`, codes and scales `torch.equal` to the compiled GELU + concat + `rotq_h16` on every shape, v1 and v2): | shape | L4 main / fused ms | RTX PRO 6000 main / fused ms | |---|---|---| | single-block proj_out, 4352 x (3072 + 12288) | 2.30 / 1.54 (1.50x) | 0.361 / 0.283 (1.28x) | | FF, 4096 x 12288 | 1.46 / 1.22 (1.19x) | 0.240 / 0.255 (0.94x, kept stock) | | single block at 512 px, 1280 rows | 0.575 / 0.472 (1.22x) | 0.068 / 0.090 (0.76x, kept stock) | | text FF, 256 rows | 0.045 / 0.077 (0.58x, kept stock) | 0.013 / 0.021 (0.63x, kept stock) | GELU helper over all 65280 finite bf16 inputs: 0 bit differences against ATen eager and against Inductor (with and without `emulate_precision_casts`), on L4 and RTX PRO 6000. ## Tests `tests/test_diffusion_flux1_convrot_gelu.py` (CPU): - A tiny FLUX.1 transformer with the patches forced on (int8 pieces replaced by the plain modules) matches stock bit for bit, eager and dynamo fullgraph, in fp32 and bf16, with the expected call counts. - The arch-patched addcmul single block is kept. - Unmarked FeedForwards and unrotated Linears keep the stock path. - Install scoping and the kill switch. - The patch spec covers FLUX.1. - Reference, fake shapes, the CPU op body equal to the stock reference, the min-rows gate, and the kernel source contract. Also covered: - A tiny Chroma run after a FLUX.1 install takes the stock projections. This test fails if the mark check is removed. - An unmarked FeedForward is rejected without an `nn.Module.__getattr__` miss. - What each kill switch restores. - A Dropout in the FF with a forward hook, a pre-hook or an instance `forward` keeps the stock FeedForward, so the callback still runs. This test fails without the check. - The info log on a failed probe. - `tests/test_diffusion_flux1_convrot_gelu.py` also covers the persisted verdict (a later load adopts it without probing) and the prewarm plumbing for FLUX.1 loads. `test_differential.py` against 8b7cde7 (6 files): DISCRIMINATING, FIXED 4, HEAD_FAIL 0, 107 unchanged. The broader backend suite (315 files, about 17300 tests; the 4 `test_mcp_tools_*` files fail to collect on both sides and were left out) has 61 failures, the same test IDs on main (8b7cde7) and here. They come from compat_preflight, compile_cache, layer split lifecycle, memory, the QwenImage 2.1 eager and strided attention tests, the media model index, SDXL whole-pipeline GGUF, hosted video int8 offload, the prequant base id and a FLUX.2 mirror shape guard. ## Not proven here - L4 end to end: Studio group-offloads FLUX.1 on L4, so `_swapped_rec` is None and none of this engages there. The L4 numbers above are the kernel alone. - A100 (sm80) is not armed (not measured). B200 and T4 were not run. - AMD: the ROCm helper is written but not run (probe ready). The FLUX.1 shared Q / K / V route also covers the RDNA native W8A8 Linears through `_rdna_shared`. That is bit-identical by construction but was not run on gfx1151. - The RTX PRO 6000 end-to-end run had the prefix-free FF still fused; it is gated off there now (about 1 ms per image). Not re-measured after that change.
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.
FLUX.1-schnell is the only one of Studio's main INT8 image families still loading an unrotated hosted INT8 file. Z-Image-Turbo, Qwen-Image-2.1 and FLUX.2-klein-4B already load a hosted ConvRot INT8 file (group-256 block Hadamard on the activations, rotation baked into the weights). This PR adds the same mapping for schnell, and it does nothing until the file is uploaded.
Change
diffusion_families.py:flux.1getsint8_convrot = ConvRotSpec(group = 0, filename = "FLUX.1-schnell-INT8-ConvRot.safetensors", repo = "unsloth/FLUX.1-schnell-FP8", default_on = True). This is the same group 0 pattern LTX-2.5 uses. The rotation lives only in the file's metadata (every quantized Linear, group 256), so:FLUX.1-schnell-INT8.safetensors,.pt,transformer_int8.pt) stays behind it, so until the file exists on the repo the plain file loads exactly as it does today;convrot_spec_for_schemeis still(0, ());UNSLOTH_DIFFUSION_INT8_CONVROT=0resolves exactly what main resolves.scripts/build_prequant_checkpoint.py:upload_destinationrefused a group 256 build for a family whose spec is group 0 ("reserved for the ConvRot group 0 build"). A group 0 spec has no runtime path to match, so the check now only applies when the spec has a group.File to publish first
unsloth/FLUX.1-schnell-FP8/FLUX.1-schnell-INT8-ConvRot.safetensors, built with this branch:(torch 2.14.1, torchao 0.18.0, diffusers 0.41.0: 15,173,636,512 bytes, 419 rotated Linears, 137 s on an RTX PRO 6000).
Results
FLUX.1-schnell at 1024x1024, 4 steps, through
DiffusionBackend.begin_load(..., transformer_quant="int8", speed_mode="default")(compiled + CUDA graphs). The rotated file was served throughUNSLOTH_DIFFUSION_PREQUANT_MIRROR, so it went through this mapping. Every cell ran in a fresh process; arms were interleaved over 3 repeats. LPIPS (alex) is against Studio's own bf16 render over 8 prompts.RTX PRO 6000 Blackwell (sm120):
ConvRotLinear/Int8Tensorin the ConvRot arm (419 plainInt8Tensoron main),int8_gemminspeed_optims, 0 graph breaks and 0 recompiles after the first render.L4 (sm89, 24 GB). Studio picks group offload for every arm here, the same policy on main and on this branch:
Tests
tests/test_diffusion_flux1_convrot_hosted.pycovers the schnell chain (rotated first, plain chain intact), the kill switch, dev / Krea-dev, the other schemes, plain at-load quantization, mirror lookup and the build script's upload name. Two assertions intest_diffusion_int8_runtime_convrot.pythat listed flux.1 as opt-in are updated.test_differential.pyagainst the merge base: DISCRIMINATING, 7 fixed, 0 head failures.test_build_prequant_checkpoint.py::test_the_recorded_base_must_be_the_canonical_id_not_just_the_same_tailfails on both main and this branch (it reads a local./temp/qwen_image_21path), so it is not caused by this change.Not proven here