Skip to content

[ROCm][MiniMax-M3] Fuse qkv_proj's per-token FP8 input quant into the input RMSNorm - #65310

Open
vorapolsiloai wants to merge 9 commits into
vllm-project:mainfrom
vorapolsiloai:mm3-norm-fp8-fusion
Open

vorapolsiloai wants to merge 9 commits into
vllm-project:mainfrom
vorapolsiloai:mm3-norm-fp8-fusion

Conversation

@vorapolsiloai

@vorapolsiloai vorapolsiloai commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #61119: waiting for it to merge, then this PR continues review. Only the last commit is this PR (01906c6, "Fuse qkv_proj's per-token FP8 input quant into the input RMSNorm"); the other commits are #61119. The numbers below were measured on main before the rebase; numbers on top of #61119 are being re-measured.

Overview

In MiniMax-M3 decoder layers the input RMSNorm writes a BF16 row and a separate kernel reads it back to quantize it to per-token FP8 for qkv_proj. This puts that quant into the fused norm kernel, opt-in (VLLM_MINIMAX_M3_FUSE_NORM_FP8=1); output matches the unfused path up to 1-ULP rounding.

MI355X, MiniMax-M3 TP4: +1.1 to +2.2% output tok/s and -0.7 to -2.0% median TPOT in all 6 workloads (8k/1k and 1k/1k, c4/16/64); fused op 1.4-1.6x faster at M = 17424.

Claims

  • GSM8K, GPQA diamond and NIAH 128k unchanged.
  • Applies to MiniMaxM3Sparse* checkpoints on ROCm with per-token dynamic FP8 qkv_proj input; MXFP8-attention checkpoints are unaffected.
  • Off under batch invariance; no other model is touched.

Validation

Full description, commands, tables, provenance

Overview

In each MiniMax-M3 decoder layer the input RMSNorm (fused with the residual add) feeds qkv_proj, which on FP8-attention checkpoints takes a per-token FP8 activation. Today the norm writes a BF16 row and a separate kernel reads it back to quantize it, while checkpoints with MXFP8 attention already quantize inside the fused norm kernel. This PR adds the per-token FP8 quant to that same fused kernel (opt-in, VLLM_MINIMAX_M3_FUSE_NORM_FP8=1), computing the scale as AITER's per-token quant does, so the output matches the unfused path up to 1-ULP rounding.

Perf: +1.1 to +2.2% output tok/s and -0.7 to -2.0% median TPOT in all 6 workloads of the 8k/1k and 1k/1k sweep at c4/16/64 (MI355X, MiniMax-M3 TP4); GSM8K, GPQA diamond and NIAH 128k unchanged; the fused op is 1.4-1.6x faster at M = 17424.

Claims

  • One kernel launch and one BF16 write + read of the normed activation fewer per decoder layer: higher throughput and lower TPOT at every input length and concurrency measured (median TTFT -1.5 to -3.8%), no accuracy change.
  • Applies to MiniMax-M3-architecture checkpoints (MiniMaxM3Sparse*) on ROCm whose qkv_proj input quant is per-token dynamic FP8 (FP8-attention checkpoints such as amd/MiniMax-M3-MXFP4-AttnFP8, the one measured). Checkpoints with MXFP8 attention linears already use the MXFP8 fusion and are unaffected (checked: MiniMax-M3.1-Flash MXFP4). Off under batch invariance; no other model is touched.

Validation

pytest tests/kernels/test_minimax_m3_amd_ops.py   # MI350X: 149 passed, 1 skipped (gfx942 only); new test: 16 cases
# MI355X; main arm: the same command without VLLM_MINIMAX_M3_FUSE_NORM_FP8=1
VLLM_MINIMAX_M3_FUSE_NORM_FP8=1 VLLM_USE_BREAKABLE_CUDAGRAPH=1 VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_MOE=1 \
VLLM_ROCM_USE_AITER_UNIFIED_ATTENTION=1 VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=1 VLLM_ROCM_QUICK_REDUCE_QUANTIZATION=INT4 \
VLLM_ROCM_ENABLE_QRINT4=0 VLLM_ROCM_SHUFFLE_KV_CACHE_LAYOUT=1 VLLM_WORKER_MULTIPROC_METHOD=spawn SAFETENSORS_FAST_GPU=1 \
VLLM_ENGINE_READY_TIMEOUT_S=3600 \
vllm serve amd/MiniMax-M3-MXFP4-AttnFP8 --tensor-parallel-size 4 --distributed-executor-backend mp --trust-remote-code \
  --block-size 128 --no-enable-prefix-caching --limit-mm-per-prompt '{"image": 1}' \
  --mm-processor-kwargs '{"min_pixels": 65536, "max_pixels": 16777216}' --mm-processor-cache-gb 0 --max-model-len 133120 \
  --gpu-memory-utilization 0.93 --max-num-batched-tokens 32768 --max-num-seqs 128 --enable-chunked-prefill --async-scheduling \
  --attention-backend ROCM_AITER_UNIFIED_ATTN --attention-config '{"indexer_kv_dtype": "fp8"}' \
  --compilation-config '{"mode": 3, "cudagraph_mode": "FULL_AND_PIECEWISE", "custom_ops": ["+rms_norm", "+quant_fp8"]}' \
  --moe-backend aiter --tool-call-parser minimax_m3 --enable-auto-tool-choice --reasoning-parser minimax_m3 \
  --kv-cache-dtype fp8_e4m3 --mm-encoder-tp-mode data --jit-monitor-mode warn --jit-monitor-verbose

vllm bench serve --backend openai-chat --endpoint /v1/chat/completions --model amd/MiniMax-M3-MXFP4-AttnFP8 \
  --tokenizer amd/MiniMax-M3-MXFP4-AttnFP8 --trust-remote-code --dataset-name random --random-input-len 8192 \
  --random-output-len 1024 --random-range-ratio 0.0 --max-concurrency 64 --num-prompts 384 --num-warmups 64 \
  --ready-check-timeout-sec 0 --request-rate inf --ignore-eos --seed 30 \
  --percentile-metrics ttft,tpot,itl,e2el --metric-percentiles 50,90,99 --save-result --save-detailed
text 8192/1024, c64 (main: 6 runs, PR: 3 runs, interleaved, fresh servers) main PR delta null range
output tok/s 2978 3010 +1.1% (p 0.012) ±0.3%
median TTFT (ms) 2198 2155 -2.0% (p 0.012) ±0.1%
median TPOT (ms) 19.34 19.15 -1.0% (p 0.012) ±0.4%

Null range: the same delta over every 3-vs-3 split of the 6 main runs; every PR run beat every main run on all three metrics.

Standard sweep and accuracy, same server command (main: 4 runs, PR: 2 runs, interleaved, fresh servers; evals: 1 run per arm):

vllm bench serve --model amd/MiniMax-M3-MXFP4-AttnFP8 --trust-remote-code --dataset-name random \
  --random-input-len 8192 --random-output-len 1024 --ignore-eos --max-concurrency 64 --num-prompts 512 --num-warmups 64 \
  --seed 0 --percentile-metrics ttft,tpot,itl,e2el --metric-percentiles 50,99 --save-result --save-detailed
# also --random-input-len 1024, and (--max-concurrency, --num-prompts, --num-warmups) = (4, 64, 4), (16, 128, 16)
MA=model=amd/MiniMax-M3-MXFP4-AttnFP8,base_url=http://localhost:8000/v1/completions,max_retries=3,max_length=133120,tokenizer_backend=huggingface
lm_eval --model local-completions --model_args $MA,num_concurrent=64 --tasks gsm8k --num_fewshot 5 --seed 1234 --batch_size 1 --log_samples
lm_eval --model local-completions --model_args $MA,num_concurrent=16 --tasks gpqa_diamond_zeroshot --seed 1234 --batch_size 1 --log_samples
lm_eval --model local-completions --model_args $MA,num_concurrent=8 --tasks niah_single_1,niah_single_2,niah_single_3 \
  --metadata '{"max_seq_lengths": [131072]}' --limit 25 --seed 1234 --batch_size 1 --log_samples
# GPQA diamond read from the official CSV (the HF dataset is gated); NIAH = RULER niah_single_1/2/3 at 131072 tokens, 25 samples each
main / PR, delta (null) 8k/1k c4 8k/1k c16 8k/1k c64 1k/1k c4 1k/1k c16 1k/1k c64
output tok/s 590 / 601, +1.9% (±0.2) 1529 / 1563, +2.2% (±0.3) 2942 / 2981, +1.3% (±0.3) 623 / 636, +2.2% (±0.4) 1775 / 1803, +1.6% (±0.1) 4141 / 4186, +1.1% (±0.3)
median TPOT (ms) 6.31 / 6.19, -1.9% (±0.3) 9.29 / 9.12, -1.9% (±0.7) 20.05 / 19.76, -1.4% (±0.4) 6.26 / 6.14, -2.0% (±0.3) 8.77 / 8.64, -1.4% (±0.6) 14.83 / 14.72, -0.7% (±0.5)
median TTFT (ms) 485 / 477, -1.7% (±0.8) 1183 / 1138, -3.8% (±4.9) 1765 / 1737, -1.6% (±0.5) 168 / 162, -3.4% (±0.8) 277 / 273, -1.5% (±0.4) 704 / 681, -3.1% (±12.2)
accuracy (same questions and seed) main PR paired exact McNemar p
GSM8K 5-shot, strict-match (1319) 0.8825 0.8901 0.48
GPQA diamond 0-shot, acc (198) 0.5202 0.5455 0.53
NIAH single 1/2/3 at 131072 (75) 75/75 75/75 1.0

Null: the largest delta between the 4 main runs split 2 vs 2. Both PR runs beat all 4 main runs on output tok/s and median TPOT in all 6 workloads.

Sweep, all metrics; 128k row (MI355X; main 4 runs / PR 2 runs, means)

metric (main / PR, delta, null) 8k/1k c4 8k/1k c16 8k/1k c64 1k/1k c4 1k/1k c16 1k/1k c64
P99 TTFT (ms) 498 / 498, +0.0% (±1.1) 1836 / 1811, -1.4% (±0.8) 6728 / 6579, -2.2% (±0.9) 179 / 174, -2.6% (±2.5) 301 / 295, -1.8% (±1.1) 1001 / 1011, +0.9% (±12.9)
P99 TPOT (ms) 6.66 / 6.55, -1.6% (±0.4) 10.38 / 10.20, -1.7% (±0.3) 21.58 / 21.26, -1.5% (±0.3) 6.38 / 6.23, -2.4% (±1.1) 9.05 / 8.87, -1.9% (±1.0) 15.30 / 15.17, -0.9% (±0.5)
median ITL (ms) 6.32 / 6.20, -1.9% (±0.2) 8.70 / 8.49, -2.4% (±0.4) 15.01 / 14.86, -1.0% (±0.1) 6.26 / 6.14, -1.9% (±0.2) 8.76 / 8.66, -1.2% (±0.9) 14.60 / 14.48, -0.8% (±0.2)
P99 ITL (ms) 6.42 / 6.30, -1.9% (±0.6) 9.36 / 9.20, -1.7% (±0.6) 439 / 432, -1.6% (±0.7) 6.52 / 6.23, -4.6% (±5.6) 10.06 / 9.15, -9.1% (±17.7) 15.13 / 14.87, -1.7% (±1.4)
median E2EL (ms) 6939 / 6811, -1.8% (±0.2) 10719 / 10536, -1.7% (±0.6) 22195 / 21903, -1.3% (±0.4) 6572 / 6438, -2.0% (±0.3) 9219 / 9097, -1.3% (±0.2) 15809 / 15628, -1.1% (±0.2)
P99 E2EL (ms) 6972 / 6876, -1.4% (±0.5) 10972 / 10859, -1.0% (±0.8) 27580 / 27285, -1.1% (±1.2) 6626 / 6458, -2.5% (±1.3) 9454 / 9249, -2.2% (±1.8) 16109 / 15972, -0.8% (±0.6)

59 of 66 delta cells (11 metrics incl. total token and request throughput) are outside the null range, all better; a code-identical arm (2 vs 4 runs) lands outside in ~13 by chance. 128k/1k c4 on a fresh server (--random-input-len 131072 --max-concurrency 4 --num-prompts 8 --num-warmups 0): median TPOT 9.75 -> 9.58 ms (-1.8%). GSM8K flexible-extract 0.8863 -> 0.8908 (p 0.69). About 15% of GSM8K answers also differ between main and branches that do not touch the numerics (batch-order effects at temperature 0), so the paired test is the comparison, not the score difference.

Details

Implementation, op microbenchmark, image rows, scope changes

Op level, MI350X, fused vs gemma_fused_add_rmsnorm + per-token scaled_fp8_quant, median time:

M N fused (us) unfused (us) FP8 elements differing (all 1 ULP)
1 / 64 / 2048 3072, 6144 faster at every shape 0 to 21 per 10k
17424 3072 118.3 161.3 11.9 per 10k
17424 6144 172.6 284.5 7.5 per 10k

No sign flips; the residual output is identical, and the mean error against an FP32 reference is equal for both paths.

Image rows, same runs (output tok/s; not claimed):

1 image per request, input 1024 / output 64 main PR delta null range
768x1024, c16 735 768 +4.4% ±2.5% (spread between identical main arms: -3.3 .. +5.1%)
2048x1600, c16 379 381 +0.5% ±1.2%
768x1024, c64 1181 1180 -0.0% ±4.3%
768x1024, c256 1452 1476 +1.6% ±2.2%
# image rows; (bucket, concurrency, prompts, warm-ups, seed) = (768x1024, 16, 96, 16, 14), (2048x1600, 16, 96, 16, 15),
# (768x1024, 64, 384, 64, 20), (768x1024, 256, 1536, 256, 21)
vllm bench serve --backend openai-chat --endpoint /v1/chat/completions --model amd/MiniMax-M3-MXFP4-AttnFP8 \
  --tokenizer amd/MiniMax-M3-MXFP4-AttnFP8 --trust-remote-code --dataset-name random-mm \
  --random-mm-base-items-per-request 1 --random-mm-num-mm-items-range-ratio 0.0 \
  --random-mm-limit-mm-per-prompt '{"image": 1, "video": 0}' --random-mm-bucket-config '{(768, 1024, 1): 1.0}' \
  --random-input-len 1024 --random-output-len 64 --random-range-ratio 0.0 --max-concurrency 16 --num-prompts 96 \
  --num-warmups 16 --ready-check-timeout-sec 0 --request-rate inf --ignore-eos --seed 14 \
  --percentile-metrics ttft,tpot,itl,e2el --metric-percentiles 50,90,99 --save-result --save-detailed

Details

Not claimed: numbers on top of #61119 (measured on main before the rebase). Depends on #61119.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)

@mergify mergify Bot added quantization minimax rocm Related to AMD ROCm labels Nov 3, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Nov 3, 2026
@vorapolsiloai vorapolsiloai changed the title [ROCm][MiniMax-M3] Fuse qkv_proj's per-token FP8 input quant into the input RMSNorm [ROCm][MiniMax-M3] LM-path speedups: fused norm + FP8 quant, dense short MSA prefill, JIT warm-ups Nov 3, 2026
@akii96

akii96 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hey @vorapolsiloai, heads up on an ordering question. My PR #61119 adds fuse_input_allreduce to the AMD MiniMax-M3 model, which sits in the forward_input_norm branch before the fuse_input_norm_mxfp8 path. @frida-andersson flagged that your FP8 norm change here would need to handle the case where both fuse_input_allreduce and the per-token FP8 norm are active on the same layer.

I would say maybe my PR #61119 might land first. Can you make sure your PR can handle the combined case on top of mine ? Happy to help if you'd like me to test the interaction once both are in. Let me know if you'd prefer a different approach!

@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

@akii96 yes lets do that I will rebase on top of your branch

@mergify

mergify Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @vorapolsiloai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

…'s norm

The NVIDIA MiniMax-M3 model leaves each FFN output un-reduced and lets the
next layer's input_layernorm (or the final norm) complete that all-reduce
through fused_allreduce_gemma_rms_norm. The AMD model only fused the
attention-site all-reduce, so every layer paid a separate FFN all-reduce
plus a norm.

Port the wiring: MoE/MLP built with reduce_results=False, the chain set up
in MiniMaxM3Model, and the final norm absorbing the last layer's reduce.
EAGLE3 captures after a deferring layer reduce a copy so they never record
a per-rank partial.

Deferral is off under PP>1 (hidden states cross stages), with mono decode
or specialized decode (their kernels expect reduced layer outputs), and for
MTP (adds the residual directly). Layers whose input norm also quantizes to
MXFP8 all-reduce first and keep that fusion.

Co-authored-by: Claude (DSH agent)
Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
- Split DecoderLayer.forward into forward_input_norm + forward_after_input_norm
  so the model loop can capture residual for EAGLE3 after the norm completes the
  deferred all-reduce. This eliminates the extra all-reduce per capture that the
  previous _maybe_add_hidden_state override performed, matching the NVIDIA model.
- Remove _aux_needs_reduce and _maybe_add_hidden_state override; replace with
  _maybe_capture_aux which clones residual after the norm.
- Capture residual.clone() at the final norm for end-layer EAGLE3 captures.
- Tighten the mono decode guard: only disable deferral when mono would actually
  activate (MONO_ENABLE + TP4 + DP1 + no EP), not just when the env var is set.
- Drop two flag-only unit tests (TP2 test covers the actual behavior).
- Add pytest.importorskip('flydsl') to the TP2 test.
- Update test toggle: use PP>1 in config instead of MONO_ENABLE at TP2.

Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
vllm#61813 dropped vllm.transformers_utils.configs.minimax_m3.MiniMaxM3Config.

Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
…XFP8 deferred norm

- Capture each aux layer exactly once: drop the pre-loop layer-0 capture on the
  stock path, skip a later PP stage start_layer, send end_layer from non-last
  PP stages, and keep the final-norm capture off the specialized decode path.
- Gate deferral on mono.dispatch.deployment_refusal, the config-only checks
  MonoDecode itself uses, instead of re-deriving TP4/DP1/no-EP.
- Finish a deferred reduce before an MXFP8 input norm through
  allreduce_gemma_rms_norm_mxfp8 so the fused all-reduce + norm kernels apply.
- Tests: MXFP8 input-norm variant at TP2, all aux layers incl. 0 and the final
  norm, the specialized decode loop, a PP2 boundary capture, and both sides of
  the mono gate.

Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
… fused norm helper changes

Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>

# Conflicts:
#	.buildkite/test-amd.yaml
#	.buildkite/test_areas/models_basic.yaml
…el, check the input norm outputs

Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
vorapolsiloai added a commit to vorapolsiloai/vllm that referenced this pull request Nov 16, 2026
… serving

AITER's Gluon paged-attention decode is specialized on its context partition
count (a constexpr, 8 down to ONE_SHOT as rows grow) and on the 16-byte
alignment of the context-length pointer (a prefill's rows follow the decode
rows in the indexer's table buffers). The startup forwards do not reach every
variant, so serving compiled the rest inside user requests. Call the attend
once per partition count and alignment on each layer's own cache and table
buffers during kernel warmup.

Split out of vllm-project#65310.

Signed-off-by: Vorapol Assavasangthong <Vorapol.Assavasangthong@amd.com>
vorapolsiloai added a commit to vorapolsiloai/vllm that referenced this pull request Nov 16, 2026
… input RMSNorm

On FP8-attention checkpoints whose qkv_proj takes a per-token FP8 activation
(kFp8DynamicTokenSym, e.g. AITER's preshuffled per-token FP8 GEMM), the input
RMSNorm wrote BF16 and a separate kernel quantized it. Add a per-token FP8
epilogue to the existing fused add + Gemma RMSNorm Triton kernel (next to the
MXFP8 one) and use it when VLLM_MINIMAX_M3_FUSE_NORM_FP8=1.

Split out of vllm-project#65310.

Signed-off-by: Vorapol Assavasangthong <Vorapol.Assavasangthong@amd.com>
@vorapolsiloai vorapolsiloai changed the title [ROCm][MiniMax-M3] LM-path speedups: fused norm + FP8 quant, dense short MSA prefill, JIT warm-ups [ROCm][MiniMax-M3] Fuse qkv_proj's per-token FP8 input quant into the input RMSNorm Nov 16, 2026
@vorapolsiloai
vorapolsiloai marked this pull request as ready for review November 16, 2026 09:39

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

vorapolsiloai added a commit to vorapolsiloai/vllm that referenced this pull request Nov 17, 2026
… serving

AITER's Gluon paged-attention decode is specialized on its context partition
count (a constexpr, 8 down to ONE_SHOT as rows grow) and on the 16-byte
alignment of the context-length pointer (a prefill's rows follow the decode
rows in the indexer's table buffers). The startup forwards do not reach every
variant, so serving compiled the rest inside user requests. Call the attend
once per partition count and alignment on each layer's own cache and table
buffers during kernel warmup.

Split out of vllm-project#65310.

Signed-off-by: Vorapol Assavasangthong <Vorapol.Assavasangthong@amd.com>
… input RMSNorm

On FP8-attention checkpoints whose qkv_proj takes a per-token FP8 activation
(kFp8DynamicTokenSym, e.g. AITER's preshuffled per-token FP8 GEMM), the input
RMSNorm wrote BF16 and a separate kernel quantized it. Add a per-token FP8
epilogue to the existing fused add + Gemma RMSNorm Triton kernel (next to the
MXFP8 one) and use it when VLLM_MINIMAX_M3_FUSE_NORM_FP8=1.

Split out of vllm-project#65310.

Signed-off-by: Vorapol Assavasangthong <Vorapol.Assavasangthong@amd.com>
@mergify

mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @vorapolsiloai.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants