Repository navigation
Studio diffusion: FLUX.1 ConvRot INT8 fuses GELU and the attention output into the rotation, and shares one Q/K/V quant - #18766
Conversation
…ion output straight into the down projections' rotation + act quant, and shares one Q / K / V quant
…TZ) and stays off below each card's measured row count
…th plain multiplies instead of a select
…h even after a stand-in import
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. |
…vRot verdicts and its kernels join the probe prewarm pool
…ately (off on RTX PRO 6000, where it measured 0.94x) [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7928142d5f
ℹ️ 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".
| and type(net[1]) is _CLS.get("Dropout") | ||
| and (not ff.training or net[1].p == 0) |
There was a problem hiding this comment.
Reject hooked dropout modules before bypassing their forward
When a marked FeedForward's dropout has a forward/pre-forward hook or an instance-level forward override, this eligibility check still permits fusion. If gelu_linear succeeds, the replacement skips net[1] entirely, silently dropping the callback and any activation transformation it performs; the stock path invokes that module even in evaluation mode. Check _gemm._hooked(net[1]) alongside the dropout type check, as is already done for the activation, so these modules retain their original behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks, fixed in 078330b: the FF fused path now also requires the Dropout to carry no forward hook, pre-forward hook or instance-level forward, the same _hooked check the activation gets, so it falls back to the stock FeedForward and every callback fires. Covered by test_a_hooked_dropout_keeps_the_stock_ff.
…dules (Chroma keeps its projections), read the mark from the instance dict, document the kill switches and log a failed GELU probe
…rd when its Dropout has a forward hook, pre-hook or instance forward [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
…ntion plan keys, CUTLASS live race key, step-skip sample= shape (#18981) Four small fixes from a recheck of the merged FLUX.1 ConvRot GELU (#18766), INT8 attention sink fold (#18786), CUTLASS race key (#18797) and SDXL static step skip (#18826) changes. Each one is its own commit with a test that fails before it and passes after. ## Changes 1. **FLUX.1 ConvRot GELU gate traces on torch 2.10 / 2.11** (`diffusion_convrot_quant.py`). `convrot_gelu_act_quant` chose its row threshold with `rows[prefix is None]`. Dynamo on torch 2.10 and 2.11 cannot trace a tuple indexed by a bool. With `fullgraph=True` the compile raises `Unsupported`; without it, every armed FF / single-block down projection graph-breaks. torch 2.6 and 2.12+ accept it. The index is now `1 if prefix is None else 0`, which selects the same entry. 2. **INT8 attention launch plans follow the kernel switches** (`diffusion_int8_attention.py`). `_plan` reads `UNSLOTH_DIFFUSION_INT8_ATTENTION_RESID_FOLD`, and `kernel_variant` reads the sink order and native P switches, when a plan picks its kernels. The warm lookup in `_find_plan` did not key on them. Flipping the fold off in a running process therefore left warm shapes on the folded kernel until `forget_plans`. The plan key now includes the three switches as set. That costs three env reads, about 1.7 us of host time per call, and nothing under CUDA graph replay. 3. **CUTLASS race key covers the live row race** (`diffusion_int8_gemm.py`). `_live_row_race` decides which calls race and applies the `force` pick. It also writes its winner into the same disk entry that `_cutlass_plan` reads back on the next load. Neither it nor `live_race_enabled` was in `_RACE_SOURCES`, so an edit confined to the live race kept old verdicts. Both are keyed now. This applies cleanly on top of the open race-key closure change, whose closure test still passes with both applied. 4. **Step skip reads `sample=`** (`diffusion_step_skip.py`). The reuse key took the latent from `hidden_states` or the first positional argument. A `UNet2DConditionModel` called with `sample=` was therefore keyed with shape `None`, and a skipped step after a latent shape change returned the previous output at the old size. The stock SDXL pipeline passes the latent positionally, so Studio's own renders were not affected. ## Tests (CPU, base = parent commit, head = this branch) | Test | Base | Head | |---|---|---| | `test_diffusion_convrot_gelu_route_trace.py` on torch 2.10.0 / 2.11.0 | 2 failed, 1 passed | 3 passed | | same on torch 2.6.0 / 2.12.1 / 2.13.0 / 2.14.1 | n/a | 3 passed | | `test_diffusion_int8_attention_resid_fold.py::test_a_warm_plan_follows_the_kill_switch` | failed (warm plan reused) | passed | | `test_diffusion_int8_cutlass_race_key.py` (3 new live race cases) | 3 failed, 27 passed | 30 passed | | `test_diffusion_step_skip_unet.py::test_a_skipped_step_never_returns_another_latent_shape[True]` | failed (width 8 for a width 12 latent) | passed | The surrounding INT8 attention, CUTLASS, GEMM, step skip and FLUX.1 GELU suites have the same results on both arms. 8 FLUX.1 GELU tests fail on both base and head when they run in the same process after the step skip and INT8 suites, and they pass when that file runs alone. That failure predates this change. ## Not covered here - No GPU run. The four changes are host-side keys and gates, and each one is checked on CPU against the real module code. - The `+1.7 us` host cost per INT8 attention call was measured on CPU, not as end-to-end render time.
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 coverFluxTransformer2DModel, 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 byrotq_h16.Change
diffusion_flux_convrot_fused: FLUX.1 patches, scoped to the modulesinstallmarks on a FLUX.1 denoiser with ConvRot Linears.transformer_flux._get_projectionsshares 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) andFluxSingleTransformerBlock.forward(diffusers' body, or the arch patch's addcmul body when that one is installed) giveproj_out/net[2]the projection output, plus the attention output in its own layout. Neither the GELU product nor the concat is written.diffusion_convrot_quant:rotq_h16xgetsACT = 2: GELU(tanh) of the gate only, so the value is never loaded.unsloth_studio::convrot_gelu_act_quant_int8(prefix?, gate, group, v2), with a fake impl.x + k x^3, pinned*_rn, plain multiplies at the end so subnormal inputs keep0.5 * x).F.gelu(approximate="tanh"), then runscodes_closeon FLUX.1's shapes, including the [attention | GELU] row and GELU's non-monotonic tail.triton.language.extra.libdevice(no*_rnthere).diffusion_int8_gemm.gelu_linear: the producer-fed GEMM, a copy ofproducer_linearwithout the value.UNSLOTH_DIFFUSION_FLUX_CONVROT_FUSED=0restores main exactly: no FLUX.1 patch is installed and the stock functions come back.UNSLOTH_DIFFUSION_FLUX1_GELU_FUSED=0orUNSLOTH_DIFFUSION_INT8_ROTQUANT_PRODUCER=0turn 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.transformer_flux._get_projections, and every model hasFeedForward. So they act only on the attentions, FeedForwards and single blocks thatinstallmarked 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.Results
RTX PRO 6000 Blackwell (sm120), Colab. FLUX.1-schnell, 1024 px, 4 steps, 8 prompts, guidance 0, Studio
begin_loadint8 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.UNSLOTH_DIFFUSION_FLUX1_GELU_FUSED=0)Kernel alone (quant stage,
do_bench_cudagraph, codes and scalestorch.equalto the compiled GELU + concat +rotq_h16on every shape, v1 and v2):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):Also covered:
nn.Module.__getattr__miss.forwardkeeps the stock FeedForward, so the callback still runs. This test fails without the check.tests/test_diffusion_flux1_convrot_gelu.pyalso covers the persisted verdict (a later load adopts it without probing) and the prewarm plumbing for FLUX.1 loads.test_differential.pyagainst 8b7cde7 (6 files): DISCRIMINATING, FIXED 4, HEAD_FAIL 0, 107 unchanged. The broader backend suite (315 files, about 17300 tests; the 4test_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
_swapped_recis None and none of this engages there. The L4 numbers above are the kernel alone._rdna_shared. That is bit-identical by construction but was not run on gfx1151.