Skip to content

[ROCm][DSv41] MegaMoE improvements for DEP8 - #68385

Open
heachary wants to merge 1 commit into
vllm-project:mainfrom
heachary:heachary/dsv41flash/megamoe-improvements
Open

heachary wants to merge 1 commit into
vllm-project:mainfrom
heachary:heachary/dsv41flash/megamoe-improvements

Conversation

@heachary

@heachary heachary commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

AITER MegaMoE for DeepSeek-V4.1-Flash has scope for improvement:

  • No overlap between dispatch and GEMM1. A rank cannot tell whether more tokens will arrive for an expert, so it waits for every rank's dispatch to finish before computing.
  • No overlap between GEMM1 and GEMM2. The two run as separate stages.
  • Kernel selection. A4W4 ran generic configs that are not tuned for this shape.

The companion AITER PR addresses all three, but only for A4W4 activations with the MXFP4 combine, and vLLM cannot select either today: DeepseekV4AiterMegaMoEExperts hard-codes quant="a8w4" and leaves the combine format on AITER's auto (BF16, or FP8 from 1024 tokens per rank). This PR makes both selectable. It adds no kernels: A4W4 MegaMoE is already in AITER v0.1.29, and the MXFP4 combine and the optimizations are in the AITER PR.

This is work done in collaboration with @maslan-coop26

Summary of changes

  • vllm/envs.py: add VLLM_ROCM_AITER_MEGA_MOE_QUANT (a8w4 default | a4w4) and VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT (auto default | none | fp8_blockwise_1x32 | fp4_blockwise_1x32), validated with env_with_choices.
  • vllm/models/deepseek_v4/amd/mega_moe.py: pass the quant and combine format to MegaMoEV2, and to build_mega_moe_bundle_plan when probing for fixed-slot dispatch. Both are added to the shared runtime's cache key. The MXFP4 weights are prepared the same way for both quants.
  • With both variables unset, behaviour is unchanged (a8w4, auto). fp4_blockwise_1x32 needs an AITER that includes the companion PR.

Companion AITER PR: ROCm/aiter#8186

How to enable

Everything is opt-in. To run the full set:

  1. An AITER with [FlyDSL] [DSV41] MegaMoE improvements for DEP8 ROCm/aiter#8186 (AITER main needs FlyDSL 0.5.0).
  2. The MegaMoE backend (gfx950, DP attention with expert parallel MoE, TP=1, PP=1, no EPLB):
    --moe-backend aiter_mega_moe --enable-expert-parallel --data-parallel-size 8 --all2all-backend mori_high_throughput with VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_MOE=1.
  3. This PR's switches: VLLM_ROCM_AITER_MEGA_MOE_QUANT=a4w4 VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT=fp4_blockwise_1x32.
  4. AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023, read by AITER directly: it gives decode its 512-token fixed-slot runtime (the default limit of 255 gives a 128-token one).

With steps 3 and 4 on DeepSeek-V4.1-Flash EP8 (48 routed experts per rank), AITER applies the tuned configs and the MegaMoE improvements (early GEMM1 tiles, light release, GEMM2 fused into Stage1, resident grid, tuned GEMM1/GEMM2) on its own; they are part of its config selection and need no further switches.

Timing

Before

image

After

image

Figures above show a breakdown at 224 tokens / rank. Theres a good improvement from 261us -> 204us.

Results

Measured with AITER PR revision 11b1cc53a, where the MegaMoE improvements were AITER_MEGA_S1_* / AITER_MEGA_S2_* environment switches. The current AITER PR revision applies them through its configs instead and matches 11b1cc53a within 1.5% with bitwise-equal outputs at the MoE-layer sizes below; these numbers will be refreshed on it.

DeepSeek-V4.1-Flash MoE layer (DeepseekV4AiterMegaMoEExperts, EP8, VLLM_ROCM_AITER_MEGA_MOE_QUANT=a4w4, VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT=fp4_blockwise_1x32) on 8x MI355X, vLLM nightly 7c3a9302 with this PR and the AITER PR, CUDA-graph replay, slowest rank. Outputs are bitwise identical to the baseline at every size.

Tokens per rank Phase Baseline (µs) This PR (µs) Improvement
160 decode 247.0 209.7 15.1%
192 decode 260.3 212.3 18.4%
224 decode 284.8 213.9 24.9%
1024 prefill 519.8 507.0 2.5%
2048 prefill 848.6 728.0 14.2%
4096 prefill 1246.9 1249.7 −0.2%

End to End results

Fixed length Perf results

DeepSeek-V4.1-Flash, 8x MI355X, DEP8, 1k in / 8k out, concurrency 256, DSpark k=6, max_num_batched_tokens=4096. Both arms: A4W4 MegaMoE with MXFP4 combine. Test arm: MegaMoE improvements enabled.

Metric Baseline Test Delta
Output token throughput (tok/s) 32,397 39,605 +22.2%
Total token throughput (tok/s) 36,447 44,556 +22.2%
Benchmark duration (s) 258.9 211.8 -18.2%
Mean TTFT (ms) 3,797.6 1,151.4 -69.7%
Median TTFT (ms) 154.4 152.1 -1.5%
P99 TTFT (ms) 17,025.7 14,788.1 -13.1%
Mean TPOT (ms) 6.29 5.61 -10.8%
Median TPOT (ms) 4.79 4.91 +2.4%
P90 TPOT (ms) 10.95 8.58 -21.6%
P99 TPOT (ms) 13.80 10.58 -23.3%
Median ITL (ms) 25.05 23.92 -4.5%
Mean E2EL (ms) 55,287 47,073 -14.9%
P99 E2EL (ms) 120,438 87,497 -27.4%
Spec decode acceptance length 6.19 6.22

Reproduction

Image: vllm/vllm-openai-rocm:nightly-rocm100-7c3a9302f5ac2441ad199134129e973d22a46797, with this PR, the AITER PR (aiter/ops/flydsl from heachary/dsv41flash/megamoe-improvements) and FlyDSL 0.5.0 applied.

Server:

export VLLM_ROCM_USE_AITER=1
export VLLM_ROCM_USE_AITER_MOE=1
export VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA=True
export VLLM_USE_BREAKABLE_CUDAGRAPH=1
export VLLM_USE_RUST_FRONTEND=1

# Both arms: A4W4 MegaMoE with the MXFP4 combine, 512-token fixed-slot decode runtime
export VLLM_ROCM_AITER_MEGA_MOE_QUANT=a4w4
export VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT=fp4_blockwise_1x32
export AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023

# Test arm: with the current AITER PR, the settings above turn the MegaMoE
# improvements on; nothing else is needed. The results above were measured on
# AITER PR revision 11b1cc53a, whose test arm also set
#   AITER_MEGA_S1_FIXED_FUSED_STAGE2=1 AITER_MEGA_S1_FIXED_EARLY_TILES=1
#   AITER_MEGA_S1_FIXED_LIGHT_RELEASE=1 AITER_MEGA_S1_FIXED_RESIDENT_GRID=1
#   AITER_MEGA_S1_FIXED_TUNED_GEMM1=1 AITER_MEGA_S1_FIXED_TUNED_GEMM1_WIDE=1
#   AITER_MEGA_S1_FIXED_TUNED_GEMM1_V2=1 AITER_MEGA_S2_FIXED_TUNED_GEMM2=1
#   AITER_MEGA_S2_FIXED_TUNED_GEMM2_V2=1
# and whose baseline arm left them unset.

vllm serve /model/DeepSeek-V4.1-Flash \
  --served-model-name deepseek-ai/DeepSeek-V4.1-Flash \
  --port 8000 \
  --tensor-parallel-size 1 \
  --data-parallel-size 8 \
  --enable-expert-parallel \
  --all2all-backend mori_high_throughput \
  --moe-backend aiter_mega_moe \
  --max-model-len 16384 \
  --gpu-memory-utilization 0.9 \
  --max-num-batched-tokens 4096 \
  --max-cudagraph-capture-size 1024 \
  --block-size 128 \
  --speculative-config '{"method":"dspark","num_speculative_tokens":6}' \
  --tokenizer-mode deepseek_v41 \
  --tool-call-parser deepseek_v41 \
  --reasoning-parser deepseek_v41 \
  --enable-auto-tool-choice \
  --language-model-only \
  --no-swa-bounded-replay \
  --no-enable-prefix-caching \
  --disable-uvicorn-access-log \
  --attention-config '{"indexer_kv_dtype":"mxfp4","indexer_sparse_logits":true}'

Benchmark (after a 256-prompt warmup of the same shape):

vllm bench serve \
  --model deepseek-ai/DeepSeek-V4.1-Flash \
  --tokenizer /model/DeepSeek-V4.1-Flash \
  --dataset-name random \
  --random-input-len 1024 \
  --random-output-len 8192 \
  --ignore-eos \
  --num-prompts 1024 \
  --max-concurrency 256 \
  --temperature 0 \
  --seed 0 \
  --percentile-metrics ttft,tpot,itl,e2el \
  --metric-percentiles 50,90,99

Accuracy

lm_eval --model local-chat-completions --apply_chat_template --tasks infx/evals/gsm8k.yaml \
  --model_args "model=deepseek-ai/DeepSeek-V4.1-Flash,base_url=http://localhost:8000/v1/chat/completions,api_key=EMPTY,eos_string=</s>,max_retries=5,num_concurrent=64,timeout=1800,tokenized_requests=False,max_length=32768" \
  --gen_kwargs "max_tokens=8192,temperature=0,top_p=1,thinking=false"
GSM8K (5-shot) Baseline Test Delta
strict-match 0.9712 ± 0.0046 0.9765 ± 0.0042 +0.0053
flexible-extract 0.9704 ± 0.0047 0.9757 ± 0.0042 +0.0053

Agent-x Perf results for c-256

Baseline here refers to this PR which enables DEP8 for DSv4.1 : SemiAnalysisAI/InferenceX#5056. The baseline and test branch were run on the same machine. The baseline reproduces the numbers for c-256, DEP8 from the inf-x PR.

Same server command (agentic.yaml:override_dep8_c256, DSpark K5, synthetic acceptance length 3.51) on vLLM ROCm nightly 7c3a9302.

Metric Baseline This PR Change
Successful requests 37,129 39,179 +5.5%
Total throughput per GPU (tok/s) 184,676 199,134 +7.8%
Output throughput per GPU (tok/s) 1,296 1,374 +6.0%
Interactivity, median (tok/s per user) 159.9 192.2 +20.2%
Interactivity, p90 (tok/s per user) 106 148 +39.7%
TPOT, median / p95 (ms) 6.25 / 11.4 5.20 / 7.99 −17% / −30%
TTFT, median / p90 (s) 1.87 / 3.81 1.53 / 2.97 −18% / −22%
End-to-end latency, median (s) 5.2 4.2 −19%

…he environment

DeepseekV4AiterMegaMoEExperts builds MegaMoEV2 with quant="a8w4" and AITER's
"auto" combine. Two variables choose them:

  VLLM_ROCM_AITER_MEGA_MOE_QUANT      a8w4 (default) | a4w4
  VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT  auto (default) | none | fp8_blockwise_1x32
                                      | fp4_blockwise_1x32

The weights are MXFP4 and prepared the same way for both quants. The
fixed-slot bundle plan now gets the activation dtype and the combine format,
and both are in the shared runtime's cache key. fp4_blockwise_1x32 needs an
AITER with the MegaMoE MXFP4 combine.

Signed-off-by: Hemanth Acharya <heachary@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Mehmet Aslan <Mehmet.Aslan+amdeng@amd.com>
@mergify mergify Bot added deepseek Related to DeepSeek models quantization rocm Related to AMD ROCm labels Nov 18, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Nov 18, 2026
@heachary heachary changed the title [ROCm][DSv4] AITER MegaMoE activation quant and combine format from the environment [ROCm][DSv41Flash] MegaMoE improvements for DEP8 Nov 18, 2026
@heachary heachary changed the title [ROCm][DSv41Flash] MegaMoE improvements for DEP8 [ROCm][DSv41] MegaMoE improvements for DEP8 Nov 18, 2026
@heachary
heachary marked this pull request as ready for review November 18, 2026 12:00

@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.

@Fangzhou-Ai Fangzhou-Ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

require ROCm/aiter#8186

Comment thread vllm/envs.py
"VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT": env_with_choices(
"VLLM_ROCM_AITER_MEGA_MOE_P2P_QUANT",
"auto",
["auto", "none", "fp8_blockwise_1x32", "fp4_blockwise_1x32"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"none" is documented as BF16, but AITER rejects it whenever a runtime's plan contains the 8192 bucket, because that bucket's aligned-pair Stage2 only emits FP8 rows (aiter v0.1.29 mega_moe_config.py:382 and :1033). That bucket is present for any max_num_batched_tokens above 4096, and MI355X defaults to 16384 (arg_utils.py:3020). So VLLM_ROCM_AITER_MEGA_MOE_QUANT=a4w4 with P2P_QUANT=none fails at load on V4.1-Flash with "p2p_quant='none' conflicts with aligned-pair Stage2". a8w4 hits the same error with the fused shared expert (49 experts per rank) or on V4-Pro shapes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. The aligned-pair Stage2 that AITER uses for the 8192 bucket only writes FP8 rows. With none, any runtime whose plan includes that bucket fails unless the network's tuner turns aligned-pair off first. That covers V4.1-Flash A4W4, the 49-expert fused shared-expert case, and V4-Pro A8W4.

I've fixed it in AITER rather than vLLM. A non-FP8 combine now falls back to the plain Stage2, which already writes BF16, instead of raising. #8186 already did this for FP4: ROCm/aiter@11b1cc53a8 (#8186). I compared the bundle plans before and after, and only the combinations that used to raise changed.

experts=self.num_experts,
topk=self.top_k,
quant="a8w4",
quant=self.quant,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#63040 (draft) makes the same change on these lines (a_dtype in the fixed-slot probe, quant in the cache key, quant=self.quant) but reads a different env, VLLM_ROCM_EP_MEGA_MOE_QUANT. #63229 moves this class to fused_moe/experts/aiter_mega_moe.py, and its copy hard-codes quant="a8w4" (:297). Whichever lands second has to port both knobs, or the envs stay in envs.py with nothing reading them. Could you agree on one env name? cc @LiuYinfeng01 @micah-wil

@heachary

Copy link
Copy Markdown
Contributor Author

@Fangzhou-Ai I have run agentx with this PR and updated the results in the table. Im seeing good uplifts there compared to the baseline.

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

Labels

deepseek Related to DeepSeek models quantization rocm Related to AMD ROCm

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants