Skip to content

[Perf] diffusion: fused gate/up + SwiGLU MLP on comfy_kitchen INT8 for Qwen-Image 2.1 - #44196

Merged
mickqian merged 3 commits into
sgl-project:mainfrom
niehen6174:perf/qwen21-int8-fused-mlp
Oct 18, 2026
Merged

mickqian merged 3 commits into
sgl-project:mainfrom
niehen6174:perf/qwen21-int8-fused-mlp

Conversation

@niehen6174

@niehen6174 niehen6174 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

On the comfy_kitchen INT8 backend, Qwen-Image 2.1's MLP ran three GEMMs plus a standalone SiLU-mul: gate_layer, proj, silu(gate) * up written to HBM in BF16, then out. ComfyUI runs the same checkpoint as one [gate | up] GEMM and a down-projection that applies the SwiGLU inside its quantizer (int8_linear(..., input_act="swiglu")).

Modifications

  • convrot_int8_comfy_kitchen.py: add comfy_kitchen_swiglu_mlp, which makes the two kitchen calls. The linear method's apply is unchanged.
  • qwen_image21.py:
    • pack_gate_up_weights() runs from post_load_weights and from _apply, so packing survives .to() and CPU offload. It puts the gate_layer/proj INT8 weights and row scales into one storage each. This mirrors pack_qkv_weights: parameters keep their names and shapes, and no reference to the shared storage is kept.
    • packed_gate_up() re-derives the stacked views on every forward.
    • LoRA wrappers, layerwise-offload placeholders, TP > 1, torch.compile and the JIT backend keep the separate projections.

Accuracy Tests

  • The stacked GEMM computes the same per-column arithmetic as the two separate projections.
  • The fused quantizer keeps silu(gate) * up in FP32 instead of rounding it to BF16 first, so outputs are not bitwise the previous path.
    • Against an FP32 reference, relative L2 error is 1.33% for the fused path vs 1.35% for eager at (2048, 3072→1024), and 1.44% vs 1.46% at (4096, 12288→4096).
    • It is the same call ComfyUI makes for this model.
  • New unit test (test_convrot_int8_backends.py) checks:
    • the fused error vs FP32 is no worse than eager's;
    • re-packing after a CPU round trip;
    • the fallback is bitwise the eager path once the shared storage is gone.

Speed Tests and Profiling

Qwen-Image 2.1 INT8 checkpoint, comfy_kitchen backend, SGLD ComfyUI workflow, 8 steps × 3 seeds. Steady model-time gain:

GPU CFG 1 CFG 4
RTX 4090 +4.75% +4.46%
RTX 5090 +4.44% +4.16%
H200 (kitchen forced) +3.17% +2.46%

H200, B200 and RTX 5090 default to the JIT backend, where this path is inactive. RTX 4090 (sm89) always uses comfy_kitchen.

Checklist


CI States

Latest PR Test (Base): ✅ Run #39116725304
Latest PR Test (Extra): ❌ Run #39116725117
Latest PR Test (AMD ROCm 10): ⏳ Run #39116725108

…en INT8

The INT8 MLP ran three GEMMs and a standalone SiLU-mul. ComfyUI runs the
same checkpoint as one [gate | up] GEMM and a down-projection that applies
the SwiGLU inside its quantizer (int8_linear input_act="swiglu").

Do the same on the comfy_kitchen backend. Like pack_qkv_weights,
post_load_weights (and .to() round trips) move gate_layer/proj weights and
row scales into one storage while the parameters keep their names and
shapes. LoRA wrappers, offload placeholders, TP > 1, torch.compile and the
JIT backend keep the separate projections.

The fused quantizer keeps silu(gate) * up in FP32 instead of rounding it to
BF16, so outputs are not bitwise the previous path; they sit slightly
closer to an FP32 reference, and match ComfyUI's call.

Steady model time with comfy_kitchen, 8 steps x 3 seeds: +4.5-4.8% on
RTX 4090, +4.2-4.4% on RTX 5090, +2.5-3.2% on H200 (CFG 1 and 4).
@github-actions github-actions Bot added the diffusion SGLang Diffusion label Oct 14, 2026
@niehen6174
niehen6174 marked this pull request as ready for review October 14, 2026 06:10
@niehen6174 niehen6174 added the run-ci CI: run the baseline test suite on this PR label Oct 15, 2026
@niehen6174

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@github-actions

This comment has been minimized.

@mickqian mickqian changed the title [Perf] Qwen-Image 2.1: fused gate/up + SwiGLU MLP on comfy_kitchen INT8 [Perf] diffusion: fused gate/up + SwiGLU MLP on comfy_kitchen INT8 for Qwen-Image 2.1 Oct 18, 2026
@mickqian
mickqian merged commit e17fed6 into sgl-project:main Oct 18, 2026
134 of 149 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants