Skip to content

Studio diffusion: fuse the int8 SwiGLU MLP on block-streamed Qwen-Image-2.1 denoisers - #15370

Merged
danielhanchen merged 5 commits into
mainfrom
studio-diffusion-resident-step-graph
Oct 26, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-diffusion-resident-step-graph

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Qwen-Image-2.1 int8 ran about 3% slower per step at 12 / 8 GB VRAM budgets than at 16 / 24 GB on L4 (0.814 against 0.789 s/step at 1024x1024). The group-offload hooks and the block-streamed step graph are not the cause: with every group resident, the replayed graph has no copies and the hooks do not run. The cause is one int8 kernel lever that the streamed load path dropped.

This change lets the onload-device install patch those MLPs too. The group hook onloads the whole block before the MLP runs. _swiglu_down and shared_rotq_linears already fall back to the stock MLP whenever a weight is not on the activation's device, so a weight that is still on the host can never reach the fused kernels. A layer split (several cards) keeps the per-card filter.

Kill switch: UNSLOTH_DIFFUSION_INT8_SWIGLU_STREAMED=0 restores the previous behaviour.

Results

Colab L4, one VM, base (main 9e44983) and head interleaved per budget (base, head, head, base). 1024x1024, 25 steps, CFG 1. Each process renders a cold image, 2 cached-prompt images and 4 new prompts. s/step is the median of the 4 new prompts.

budget base r1 / r2 head r1 / r2 change
12 GB s/step 0.8140 / 0.8144 0.7841 / 0.7879 -3.5%
8 GB s/step 0.8274 / 0.8273 0.7964 / 0.7974 -3.7%
16 GB s/step (reference) 0.7890 0.7874 unchanged
12 GB render total s 21.906 / 21.944 21.215 / 21.273 -3.1%
8 GB render total s 22.154 / 22.148 21.405 / 21.457 -3.3%
12 GB own peak (NVML) 11.684 GiB 11.164 / 11.166 GiB lower
8 GB own peak (NVML) 7.803 GiB 7.799 GiB same
  • 12 GB now matches 16 GB per step (0.784-0.788 against 0.787-0.789).
  • 8 GB sits about 1% above 16 GB; that remainder is real block streaming.
  • Base A/A spread is 0.0004 s/step at 12 GB and 0.0001 s/step at 8 GB, so the change is about 75x the noise.
  • Every head process logs one act quant for gate / value on 32 SwiGLU MLP(s) + the SiLU product fused into the down projection's act quant. No base 12 / 8 GB process does.
  • Each process captures the step graph once, on its first render. No arm re-captures on later prompts or hits an out-of-memory.

On B200 (local, emulated 12 / 8 GiB caps), the int8 GEMM and ConvRot kernels are off by default on sm100, so this change is a no-op there: same kernels, same images. With the GEMM forced on (UNSLOTH_DIFFUSION_INT8_GEMM=1), at both caps:

  • head launches 647 kernels per step against 711, 2 fewer act quants per block;
  • GPU kernel time is 101.2-102.3 ms per step against 102.8-103.8 ms (one contended base outlier at 132.6 left out);
  • images are byte-identical to base in all 5 base / 5 head processes;
  • the allocator peak is the same.

Tests

studio/backend/tests/test_diffusion_int8_gemm.py:

  • the streamed install patches a host-resident SwiGLU MLP, and the resident install still does not;
  • a MLP whose weight sits on another card is kept stock;
  • _swap marks only the onload-device install as streamed;
  • end to end on CUDA: a group-offloaded block on the host runs the fused SwiGLU path after its onload, bit-identical to the resident install. The kill switch keeps it stock.

The new cases fail on main and pass here. The whole file passes: 151 passed.

…ge-2.1 denoisers

The onload-device int8 GEMM install (12 / 8 GB budgets) skipped every SwiGLU MLP because its weights were
still on the host at install time, so those budgets ran four act quants per MLP where 16 / 24 GB run two.
The streamed install now patches them too; the fused path already keeps the stock MLP on any weight that is not
on the activation's device. Kill switch UNSLOTH_DIFFUSION_INT8_SWIGLU_STREAMED=0.
@danielhanchen danielhanchen self-assigned this Oct 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T12:29:35.644307Z 0e45142 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

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 0e45142343

ℹ️ 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 aa9b152 into main Oct 26, 2026
9 of 39 checks passed
@danielhanchen
danielhanchen deleted the studio-diffusion-resident-step-graph branch October 26, 2026 13:33
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