Skip to content

[diffusion] perf: fuse MiniMax-H3's RMSNorm and indexed AdaLN under quality lossless - #43327

Merged
mickqian merged 1 commit into
mainfrom
mick/diffusion-h3-lossless-norm-modulate
Oct 9, 2026
Merged

mickqian merged 1 commit into
mainfrom
mick/diffusion-h3-lossless-norm-modulate

Conversation

@mickqian

@mickqian mickqian commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Each MiniMax-H3 DiT block normalizes its residual stream twice, before attention and before the MLP. Each time it runs two memory-bound kernels: nn.RMSNorm, then the indexed AdaLN modulation x * (1 + scale[idx]) + shift[idx]. That is one full read and write of the [tokens, 5376] activations more than the math needs, and the chain rounds to BF16 after the norm and again after each modulation op.

A fused RMSNorm + AdaLN kernel was removed from this path before, because it drifted the 2-GPU consistency goldens. That drift is exactly what the lossless tier allows: same math and operand precision, only the rounding moves. So this PR brings the fusion back under the quality gate. exact and every CI golden keep the reference chain.

Modifications

  • rmsnorm_indexed_scale_shift (Triton): computes rmsnorm(x) * (1 + scale[idx]) + shift[idx] in one FP32 pass with a single rounding. It reads the AdaLN tables per row by index, so they are never materialized per token.
    • Launch config: one row per program, 8 warps. Packing 16 rows into a program, which is the per-token kernel's heuristic, spills the FP32 row tiles. At H3's width that variant took 4.5 ms for 32768 rows: 24× the one-row launch and 10× the unfused chain.
  • New QualityGatedFusion site "MiniMax-H3 fused RMSNorm + AdaLN", registered at tier lossless in _QUALITY_FUSION_HANDLERS. Every DiT block marks it, and both modulate sites use the fused kernel while it is mounted.
    • quality="lossless" (the default) and "high" mount it.
    • "exact" unmounts it and keeps nn.RMSNorm plus indexed_scale_shift_bf16_ bit for bit.
  • Cookbook: the quality-level section now says what lossless changes in the denoise path.

Accuracy Tests

  • test/registered/kernels/ops/diffusion/test_rmsnorm_indexed_scale_shift.py (new): checks the kernel against the same math in FP32 with one rounding, and against the reference rounding chain, at widths 1024 and 5376 and 1/37/1025 rows.

    • Max error against the FP32 math is 0.0156, which is one BF16 step at these magnitudes. The reference chain is at 0.061.
  • No H3 CI golden moves. Every MiniMax-H3 consistency case pins quality="exact", as testcase_configs.py does for any case that names no level.

  • End to end, with the fusion against without it (both at the default level, same seed, 4×H200), the outputs are not pixel-close. Neither are two exact runs that split the work differently: H3's 50-step trajectory turns rounding differences into a different sample.

    pair video PSNR audio log-spectral distance
    Ref2VA, Ulysses 2: with vs without 20.8 dB 3.0 dB
    T2VA, Ulysses 2: with vs without 23.2 dB 2.0 dB
    T2VA, Ulysses 4: with vs without 17.9 dB 6.2 dB
    reference: exact at Ulysses 2 vs exact at Ulysses 4 21.9 dB 1.6 dB

    Side by side, the frames show the same scene, subject and quality, with different camera framing and details. At Ulysses 4 the shot is closer and the shirt differs, as it also does between the two exact topologies. Both runs of every arm are md5-identical, so the fused path is deterministic.

Speed Tests and Profiling

Kernel, H200, D=5376. For scale, H3's rows per rank are 24826 for Ref2VA at Ulysses 2, 18871 for T2VA at Ulysses 2 and 9436 at Ulysses 4.

rows nn.RMSNorm + indexed_scale_shift_bf16_ fused speedup
10240 147.5 µs 62.6 µs (3.5 TB/s) 2.4×
20480 280.7 µs 115.7 µs (3.8 TB/s) 2.4×
32768 440.2 µs 182.0 µs (3.9 TB/s) 2.4×

End to end, client latency, 4×H200, 50 steps, --performance-mode speed, default quality. The arms ran ABBA on one box (without, with, with, without), on top of the Ulysses copy-engine pipeline (#43164):

Case without with e2e denoise stage
Ref2VA 5 s, 2 GPUs, Ulysses 2 220.15 / 219.75 s 218.90 / 218.93 s −0.47% 213.65 → 212.52 s (−0.53%)
T2VA 5 s, 2 GPUs, Ulysses 2 141.33 / 141.37 s 140.68 / 140.73 s −0.45% 137.65 → 136.94 s (−0.52%)
T2VA 5 s, 4 GPUs, Ulysses 4 72.27 / 72.31 s 71.90 / 71.86 s −0.57% 70.48 → 70.07 s (−0.58%)

Each cell is the two runs of an arm. The two arms differ only by this PR.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): 🚫 Run #37900840565
Latest PR Test (Extra): ❌ Run #37900840101
Latest PR Test (AMD ROCm 10): ⏳ Run #37900840445

@mickqian mickqian added the run-ci CI: run the baseline test suite on this PR label Oct 9, 2026
@mickqian mickqian added the diffusion SGLang Diffusion label Oct 9, 2026
@mintlify

mintlify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready View Preview Oct 9, 2026, 7:48 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

This branch was successfully deployed

1 active deployment
staging - docs — 46b4d415 Deployed Oct 9, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant