Skip to content

[Perf] [ROCM] diffusion: Bit-exact fast QK RMSNorm and fused RoPE for MiniMax-H3 - #47569

Merged
mickqian merged 2 commits into
mainfrom
mick/rocm-h3-qknorm-aten-exact
Oct 31, 2026
Merged

mickqian merged 2 commits into
mainfrom
mick/rocm-h3-qknorm-aten-exact

Conversation

@mickqian

@mickqian mickqian commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

On ROCm, H3 keeps the per-head QK RMSNorm on aten rms_norm. Its vectorized_layer_norm_kernel runs one 256-thread block per 128-wide row (~0.6 TB/s) after a .contiguous() copy of each strided q/k view of the fused QKV: QK norm plus that copy is 5.1% of a denoise step (43.7 ms/step) at 1280x704 on 4xMI355X.

Modifications

  • New Triton kernel aten_head_rmsnorm_triton.py that replays aten's arithmetic (4 contiguous squares per lane, shfl-down fold 16/8/4/2/1, rsqrtf, w * (rstd * x)) and reads the strided q/k views directly. It is used only after a first-sight BitExactFusionGate check against the eager path passes.
  • Second commit: the bf16 NeoX RoPE (each product and the sum rounded to bf16, dims past rot_dim passed through) is applied in the same pass, behind its own first-sight gate.
  • Tests added to test/registered/kernels/ops/diffusion/test_norm.py (fail on main, pass here).

Accuracy Tests

Bitwise: MP4 md5 identical to main for every prompt checked (22/22 in the final 20-prompt run, which includes the other ROCm branches), plus the kernel unit test comparing against aten bit for bit.

Speed Tests and Profiling

Setup for all numbers below: 4x MI355X, MiniMax-H3 T2VA, 1280x704 (SemiAnalysis "720p"), 124 frames, 49 forwards, Ulysses 4 + aiter, single stream. Each arm is a fresh server (1 warmup + 3 timed requests), ABAB across two rounds, base = main 75a5da7f.

720p median
main 44.78 s
+ QK norm 42.51 s (-2.27 s)
+ RoPE fusion a further -0.17 s

QK norm per step: 43.7 ms -> 7.1 ms.

Checklist

  • Format your code according to the pre-commit config (isort / ruff / black pass).
  • Add unit tests (merged into the existing test file for the touched area).
  • Provide accuracy and speed benchmark results (above).

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #41159226768
Latest PR Test (Extra): ❌ Run #41159226703
Latest PR Test (AMD ROCm 10): ⏳ Run #41159226745

mickqian and others added 2 commits October 30, 2026 22:51
ROCm keeps H3's per-head QK norm on aten rms_norm, whose
vectorized_layer_norm_kernel runs one 256-thread block per 128-wide row
(~0.6 TB/s) after a .contiguous() copy of each strided q/k view. Add a
Triton kernel that replays that kernel's arithmetic (4 contiguous squares
per lane, shfl-down fold 16/8/4/2/1, rsqrtf, w * (rstd * x)) and reads the
fused-qkv views directly, behind a first-sight BitExactFusionGate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…MSNorm

Apply the bf16 NeoX rotary_embedding (each product and the sum rounded to
bf16, dims past rot_dim passed through) in the QK norm's pass instead of a
second read-modify-write of q and k, behind its own first-sight gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added documentation Improvements or additions to documentation diffusion SGLang Diffusion jit-kernel labels Oct 31, 2026
@github-actions

This comment has been minimized.

@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 31, 2026
@mickqian mickqian changed the title [Perf] [ROCm] diffusion: Bit-exact fast QK RMSNorm and fused RoPE for MiniMax-H3 [Perf] [ROCM] diffusion: Bit-exact fast QK RMSNorm and fused RoPE for MiniMax-H3 Oct 31, 2026
@mickqian
mickqian merged commit 7585ccc into main Oct 31, 2026
286 of 328 checks passed
@mickqian
mickqian deleted the mick/rocm-h3-qknorm-aten-exact branch October 31, 2026 14:12
niehen6174 added a commit to niehen6174/sglang that referenced this pull request Nov 5, 2026
Reviewed the six upstream minimax_h3.py changes since the last pin
(sgl-project#46047, sgl-project#46709, sgl-project#47567, sgl-project#47569, sgl-project#47566 and the BCG output buffers). None
touches what h3_comfyui_v1 relies on in its single-GPU eager torch_sdpa
profile: DiTBlock.forward is unchanged, _attend still calls
fused_inplace_qknorm_rope on the _use_fused_qknorm_rope branch with the same
arguments (the new pipelined branch needs Ulysses, which the profile
rejects), and _embed still returns (embeddings, t_emb) in eager mode.
Yuxingwang-intel pushed a commit to Yuxingwang-intel/sglang that referenced this pull request Nov 6, 2026
… MiniMax-H3 (sgl-project#47569)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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