Repository navigation
[Diffusion] Fuse FLUX.2 gated residual normalization on Blackwell - #37112
Merged
Merged
Conversation
BBuf
requested review from
AgainstEntropy,
DarkSharpness,
HaiShaw,
HydraQYH,
celve,
mickqian,
ping1jing2,
yichiche,
yingluosanqian and
yuan-luo
as code owners
August 30, 2026 09:06
Collaborator
Author
|
/tag-run-ci-label extra |
Collaborator
Author
|
/rerun-failed-ci |
Collaborator
Author
|
/rerun-failed-ci |
Collaborator
Author
|
/rerun-failed-ci |
Co-authored-by: Cursor <[email protected]>
Collaborator
Author
|
/rerun-failed-ci |
This was referenced Sep 1, 2026
StevenChenSE
pushed a commit
to StevenChenSE/sglang
that referenced
this pull request
Sep 6, 2026
…l-project#37112) Co-authored-by: Cursor <[email protected]>
1 of 5 tasks
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
This PR adds a Blackwell JIT fast path for FLUX.2's gated residual update followed by LayerNorm and adaLN scale/shift. It is the gated-residual-normalization optimization described in Agentic Kernels in Production.
The production BF16 path previously launched
residual_gate_addand LayerNorm/modulation separately. The new path carries an eligible FFN residual update to the next block and materializes both results with one model-specific CUDA kernel:flowchart LR R[residual] --> F[fused CUDA JIT kernel] U[FFN or attention update] --> F G[gate] --> F M[next LayerNorm scale and shift] --> F F --> RO[updated BF16 residual] F --> NO[normalized and modulated BF16 input] X[unsupported shape, dtype, device, or compile mode] --> E[existing eager kernels]In a profiled denoise step, 80 gated-residual and 80 norm/modulate calls become 77 fused calls plus 3+3 boundary calls. This removes 77 GPU launches per step.
Implementation details
nn.LayerNormmodules and checkpoint/state-dict layout unchanged.torch.compile, and unsupported layouts use the existing path.End-to-end benchmark
Hardware/software: 1x NVIDIA GB300 288 GB (SM 10.3), driver 580.105.08, PyTorch 2.13.0+cu130. Model: FLUX.2-dev ModelOpt NVFP4. Native SGLang backend; transformer, text encoder, and VAE resident.
Workload: 1024x1024, 50 denoise steps, guidance scale 4.0, seed 20260830, lossless PNG, one request warmup per fresh process. Five main and five PR runs used balanced order
main, PR, PR, main, PR, main, main, PR, main, PR.Kernel microbenchmark
Median CUDA-event time after 25 warmups, 200 samples. The baseline is
residual_gate_addfollowed by the production LayerNorm/modulation helper.[1, 512, 6144][1, 4096, 6144][1, 4608, 6144]Profile evidence
Two profiled denoise steps per side at the formal 1024x1024 shape:
Accuracy and generated-image comparison
The same formal runs were used for performance and quality measurement. All five images within each side were deterministic, and main and PR produced the same PNG bytes.
b00811e8777a7002f9e4b05400c032aa4c9932450127e2898d875fe2231d1d82b00811e8777a7002f9e4b05400c032aa4c9932450127e2898d875fe2231d1d82Prompt:
A cinematic technical poster of a red panda GPU engineer in a dark research laboratory, inspecting a luminous Blackwell accelerator board, with a notebook clearly labeled SGLANG RESNORM, realistic fur, intricate electronics, dramatic rim lightingValidation
test/registered/kernels/ops/diffusion/test_model_fast_paths.py: 44 passed--enable-torch-compile: passed and produced an image--dit-layerwise-offload true: passed and produced an imageruff check,ruff format --check,clang-format --dry-run --Werror,py_compile, andgit diff --check: passedCI States
Latest PR Test (Base): ⏳ Run #33423597740
Latest PR Test (Extra): ✅ Run #33423597299
Latest PR Test (AMD ROCm 7.2): ❌ Run #33423597670