Skip to content

[diffusion][AMD] kernels: Fix fused QK-norm JIT kernels on ROCm and enable them - #13

Open
avjves wants to merge 302 commits into
mainfrom
pr/rocm-qknorm-kernels
Open

avjves wants to merge 302 commits into
mainfrom
pr/rocm-qknorm-kernels

Conversation

@avjves

@avjves avjves commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Motivation

sgl-project#35573 enabled the fused QK-norm and QK-norm+RoPE paths on ROCm, but the kernels behind them still don't build on all models. elementwise/qknorm.cuh fails outright, and diffusion/qknorm_rope.cuh fails for neox instantiations. Non-neox rope is the one case that already worked, which is why FLUX.2 saw the benefit of sgl-project#35573 and MiniMax H3 did not.

This PR removes two dead CUDA includes in qknorm.cuh, and on ROCm pins the shuffle width to the kernel's 32-lane sub-group instead of letting HIP default it to the physical wave64. With both fixed, MiniMax-H3's QK-norm paths accept ROCm.

Without these changes neither of the kernels work on ROCm. Theser are necessary for eager / compile mode parity.

CUDA is unaffected. The shuffle change is behind #ifndef USE_ROCM and the dropped includes were dead.

Modifications

  • elementwise/qknorm.cuh carried cuda_bf16.h / cuda_fp16.h as dead includes, which hipcc cannot find ("fatal error: 'cuda_bf16.h' file not found"). The file reaches the GPU only through impl/norm.cuh and the runtime.cuh macro shims, both of which hipcc builds, so the includes can just go.

  • __shfl_sync(kActiveMask, ...) passes a uint32_t mask, and HIP static_asserts sizeof(MaskT) == 8. On ROCm this now calls __shfl(..., partner_lane, device::kWarpThreads) instead. device::kWarpThreads is 32u unconditionally, so the kernel indexes lanes in 32-wide logical warps, while HIP defaults the shuffle width to the physical wave64. partner_lane is an index inside that 32-lane sub-group, so the width has to be explicit.

  • minimax_h3.py gated _apply_qk_norm and _use_fused_qknorm_rope on current_platform.is_cuda(). Both now accept ROCm, which is what reaches the two kernels above. MiniMax uses is_neox=True, the instantiation that did not
    build.

Accuracy Tests

For testing, using MiniMax-H3. The output changes slightly (exactly 1 BF16 ULP) as expected by the rope kernel. Enabling torch.compile would change it as well. No artifacts present.

Command:

sglang generate \
    --model-path MiniMaxAI/MiniMax-H3 \
    --ulysses-degree 8 --ring-degree 1 --num-gpus 8 \
    --num-inference-steps 50 \
    --dit-cpu-offload False --dit-layerwise-offload False \
    --text-encoder-cpu-offload False --image-encoder-cpu-offload False \
    --offload-during-compile False --vae-cpu-offload False \
    --warmup-mode request --warmup-steps 50 \
    --vae-precision bf16 --image-encoder-precision bf16 \
    --output-path /outputs/minimax_h3.pr1 \
    --prompt 'A cat flying through the universe on a broom, playing rap music from his boombox' \
    --seed 42 \
    --config /outputs/minimax_h3.pr1/config.json \
    --perf-dump-path /outputs/minimax_h3.pr1/perf/pr1.json"

Before

v0.mp4

After

pr1.mp4

Speed Tests and Profiling

1. High-level Summary

Metric Baseline New Diff Status
E2E Latency 29317.56 ms 28142.04 ms -1175.52 ms (-4.0%) ✅
Throughput 0.03 req/s 0.04 req/s - -

2. Stage Breakdown

Stage Name Baseline (ms) New (ms) Diff (ms) Diff (%) Status
InputValidationStage 0.03 0.04 +0.01 +23.8% ⚪️
MiniMaxH3PartitionAdmissionStage 0.02 0.02 +0.01 +33.6% ⚪️
MiniMaxH3TextEncodingStage 29.64 29.23 -0.41 -1.4% ⚪️
MiniMaxH3VisualEncodingStage 0.01 0.02 +0.00 +8.7% ⚪️
MiniMaxH3AudioEncodingStage 0.01 0.01 +0.00 +3.8% ⚪️
MiniMaxH3LatentPreparationStage 11.70 11.23 -0.47 -4.0% ⚪️
MiniMaxH3TimestepPreparationStage 0.13 0.15 +0.02 +14.2% ⚪️
MiniMaxH3DenoisingStage 24650.74 23212.86 -1437.88 -5.8% ⚪️
MiniMaxH3DecodingStage 1590.55 1582.83 -7.71 -0.5% ⚪️
Scheduler.return_result.spill_arrays 0.06 0.06 +0.00 +0.7% ⚪️
SchedulerClient.materialize_file_refs 0.01 0.01 +0.00 +1.2% ⚪️

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@avjves avjves changed the title [diffusion] Fix fused QK-norm JIT kernels on ROCm and enable them [diffusion][AMD] Fix fused QK-norm JIT kernels on ROCm and enable them Sep 18, 2026
@avjves avjves changed the title [diffusion][AMD] Fix fused QK-norm JIT kernels on ROCm and enable them [diffusion][AMD] kernels: Fix fused QK-norm JIT kernels on ROCm and enable them Sep 18, 2026
@avjves
avjves force-pushed the pr/rocm-qknorm-kernels branch from f9d6857 to 3448773 Compare September 21, 2026 13:32
gilfordting and others added 27 commits October 30, 2026 17:07
…TP rank divergence in DFlash/DSpark) (sgl-project#38565)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: sglang-bot <sglang-bot@users.noreply.github.com>
Co-authored-by: zijiexia <37504505+zijiexia@users.noreply.github.com>
… graphs (sgl-project#47467)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…lf-warp (sgl-project#47465)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…gl-project#47240)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
…em (sgl-project#47543)

Co-authored-by: metamergebot <324680979+metamergebot@users.noreply.github.com>
Co-authored-by: ZYHowell <ZYHowell@users.noreply.github.com>
…ync in alloc_extend_swa_tail (sgl-project#47542)

Co-authored-by: metamergebot <324680979+metamergebot@users.noreply.github.com>
Co-authored-by: ZYHowell <ZYHowell@users.noreply.github.com>
…across the GPU so one long context no longer sets the step time (sgl-project#47387)

Co-authored-by: Guanxin Li <15062761+latrawy@users.noreply.github.com>
…s at the first refusal (sgl-project#46898)

Co-authored-by: metamergebot <324680979+metamergebot@users.noreply.github.com>
Co-authored-by: ZYHowell <ZYHowell@users.noreply.github.com>
mickqian and others added 30 commits November 3, 2026 09:24
…oject#47900)

Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: ishandhanani <82981111+ishandhanani@users.noreply.github.com>
Co-authored-by: Ishan Dhanani <ishandhanani@gmail.com>
…ble classmethod (sgl-project#47954)

Co-authored-by: metamergebot <324680979+metamergebot@users.noreply.github.com>
Co-authored-by: shodoco <shodoco@users.noreply.github.com>
…ect#48051)

Co-authored-by: lianghougong <lianghouhong@xiaohongshu.com>
…in c5e8b9b3 and revert sgl-project#47560 (sgl-project#47929)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ty domains (sgl-project#47976)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ntX points (sgl-project#48070)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…decode (sgl-project#47993)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… run-to-run spread (sgl-project#47957)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Po-Han Huang (NVIDIA) <53919306+nvpohanh@users.noreply.github.com>
…void cache aliasing (sgl-project#46327)

Co-authored-by: Hubert Lu <Hubert.Lu@amd.com>
… the cached prompt K/V (sgl-project#47962)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Po-Han Huang (NVIDIA) <53919306+nvpohanh@users.noreply.github.com>
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.