Skip to content

[Stacked on #67850][ROCm][DeepSeek-V4.1-Flash] amd_kernels routes for DEP8 on MI355X (fused EP8 MoE, static expert placement) - #69097

Open
Fangzhou-Ai wants to merge 23 commits into
vllm-project:mainfrom
Fangzhou-Ai:fai/akr-dsv41f-dep8-routes
Open

Fangzhou-Ai wants to merge 23 commits into
vllm-project:mainfrom
Fangzhou-Ai:fai/akr-dsv41f-dep8-routes

Conversation

@Fangzhou-Ai

@Fangzhou-Ai Fangzhou-Ai commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

DeepSeek-V4.1-Flash at DEP8 (TP1 x DP8, EP8, DSpark speculative decoding, fp8 KV cache, MXFP8 dense, MXFP4 experts) on MI355X runs 21 of its kernels and kernel chains on amd-kernels through the route framework of #67850 (AmdKernelsConfig, one gate module, lazy amd_kernels imports, stock fallback everywhere), including a fused EP8 MoE (dispatch, both expert GEMMs and combine in one launch per rank). It also adds an opt-in static expert placement with replicas for the MegaMoE experts, the opt-in expert-load counting that feeds it, and a planner that reproduces the shipped plan from those counts. User docs: docs/features/amd_kernels.md.

Stacked on #67850: this PR's own diff is the commits from [ROCm][DeepSeek-V4.1-Flash] amd_kernels routes for DEP8 on MI355X (fused EP8 MoE) on; the commits below it are #67850's, so the branch is rebased once #67850 merges.

Depends on:

Claims

  • 21 routes, on by default for DeepSeek-V4.1 on gfx950 when amd_kernels imports; --kernel-config '{"amd_kernels": {"disabled_routes": [...]}}' turns any of them off, {"amd_kernels": {"enabled": false}} all of them. Other models and other hardware are unaffected (the akr hooks stay None). With the routes on, KV-cache sizing keeps 20 GiB per GPU free for serving transients (serving_transient_gib; at this layout the measured growth is 10.65 GiB, so about 9 GiB per GPU less KV cache than without the floor) and start-up takes about 90 s longer (prefill_warmup); both are configurable (Details). Validated layout: DEP8 (TP1 x DP8, EP8) on MI355X; other layouts of this model (TP8, DP4) and MI350X have not been run, and amd-kernels declines shapes it does not cover.
  • amd_kernels.expert_perm (off by default): static expert placement with replicas. The shipped S = 49 plan takes the per-rank routed-load max/mean from 1.64 (default placement, mean over the 40 MoE layers; 2.09 on the worst layer) to about 1.02-1.03 per decode step, the noise floor of uniform routing; +0.8 GB of weights per rank.
  • End to end, InferenceX AgentX, 3600 s, 8x MI355X, prefill delayer on (current configuration: all routes + the S = 49 plan):
concurrency InferenceX CI (stock vLLM, same serving flags + delayer) this PR delta
c256 total tok/s/GPU 183,986 205,990 +12.0%
output tok/s/GPU 1,291.0 1,414.6 +9.6%
interactivity p90 / p50 (tok/s/user) 143.7 / 169.3 194.8 / 230.9 +36% / +36%
TTFT p50 / p90 (s) 1.91 / 4.30 1.54 / 3.66 -19% / -15%
c512 total tok/s/GPU not available 350,591
output tok/s/GPU not available 2,578.6
interactivity p90 / p50 not available 96.0 / 159.3
TTFT p50 / p90 (s) not available 1.95 / 5.09
c1024 total tok/s/GPU not available (CI's c1024 run produced no data) 508,363
output tok/s/GPU not available 3,780.9
interactivity p90 / p50 not available 29.4 / 56.8
TTFT p50 / p90 (s) not available 2.74 / 5.71

The delta includes upstream changes between the builds: this PR ran on vLLM main 647a768 (0.34.0rc1.dev1133) with FlyDSL 0.5.0; the official InferenceX CI run 43778210028 used vLLM 0.34.0rc1.dev521 with FlyDSL 0.4.2, and the vLLM build of the c256 CI + delayer result is not recorded here. One run per point; no repeat runs at this head, so no spread is given.

For reference only, under a different scheduler setting (cadence prefill scheduling, no delayer), the official InferenceX CI run 43778210028: c256 total 185,582 / output 1,299 tok/s/GPU / p90 interactivity 107.4; c512 total 258,693 / output 2,005 / p90 interactivity 37.3. It is not comparable to the delayer rows above.

  • GSM8K (the InferenceX CI eval: lm-eval 0.4.9.2, gsm8k 5-shot with chat template, all 1319, concurrency 1024; CI passes at >= 0.90 on both metrics), this PR's configuration: strict-match 0.9447 +- 0.0063, flexible-extract 0.9629 +- 0.0052 (one run; +- is lm-eval's standard error): PASS. The CI run's own eval job produced no number.

Validation

End to end. Server: the command below on 8x MI355X, behind vllm-router 0.1.14 (--intra-node-data-parallel-size 8 --policy consistent_hash); client: agentx profile (agentx-harness 1.0.14, dataset semianalysis_cc_traces_weka_062126) at concurrency 256 / 512 / 1024 for 3600 s, one fresh server per point. Stack: vLLM 0.34.0rc1.dev1133 (main 647a768) + this branch at 82800cf + the #65655 port; the later commits add the opt-in counting, the planner, docs, the pin bump, lint fixes and a warning log, with no functional change to the served path while VLLM_AKR_EXPERT_COUNTS is unset. AITER 0.1.29.post1 (incl. ROCm/aiter#7600), FlyDSL 0.5.0, mori 1.2.3.post1, amd-kernels 2184954 (kernel code identical to the pinned ba58826, whose later commits change only tests and READMEs). Speculative decoding uses DSpark with InferenceX's synthetic rejection sampler (acceptance length pinned at 3.51, as in CI), so these numbers do not reflect the draft's real acceptance: a change in draft quality from the draft-side routes (draft_router, main_proj, markov) cannot show here, only their speed. Baseline: the InferenceX CI DEP8 result with the same flags and the prefill delayer (c256).

Serving command
# needs the #65655 prefill delayer (not in main) for --prefill-schedule-policy delayer / --prefill-max-wait-ms
export VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_MOE=1 VLLM_ROCM_QUICK_REDUCE_QUANTIZATION=NONE \
  VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA=True VLLM_USE_BREAKABLE_CUDAGRAPH=1 VLLM_USE_RUST_FRONTEND=1 \
  VLLM_RANDOMIZE_DP_DUMMY_INPUTS=1 MORI_SHMEM_HEAP_SIZE=64G OMP_NUM_THREADS=1
vllm serve deepseek-ai/DeepSeek-V4.1-Flash --port 6100 \
  --all2all-backend mori --attention-config '{"indexer_kv_dtype":"mxfp4","indexer_sparse_logits":true}' \
  --block-size 128 --data-parallel-size 8 --tensor-parallel-size 1 --enable-expert-parallel \
  --engram-config '{"cpu_offload":false,"embedding_across_dp":true}' \
  --gpu-memory-utilization 0.9 --kv-cache-dtype fp8_e4m3 --language-model-only \
  --long-prefill-token-threshold 8192 --max-cudagraph-capture-size 1024 \
  --max-model-len 1048576 --max-num-batched-tokens 32768 --max-num-seqs 128 \
  --moe-backend aiter_mega_moe --prefill-schedule-interval 96 \
  --prefill-schedule-policy delayer --prefill-max-wait-ms 5000 \
  --reasoning-parser deepseek_v41 --tokenizer-mode deepseek_v41 --tool-call-parser deepseek_v41 \
  --enable-auto-tool-choice \
  --speculative-config '{"method":"dspark","num_speculative_tokens":5,"draft_sample_method":"probabilistic","rejection_sample_method":"synthetic","enable_adaptive_verification":false,"synthetic_acceptance_length":3.51}' \
  --kernel-config '{"amd_kernels":{"enabled":true,"expert_perm":"expert_plan_S49.npz"}}'

--max-num-seqs 160 at c1024. Infra note (not vLLM): vllm-router 0.1.14 hard-codes a listen backlog of 128, which resets connections in the c1024 AgentX warm-up burst; the c1024 run raised it to 4096 with an LD_PRELOAD shim. Server log checks on every rank: amd_kernels routes: lists all 21 routes, amd_kernels fused_ep8 on 40 layers, amd_kernels expert placement .../configs/expert_plan_S49.npz sha256=c04d6ac05d76846c with slots per rank {384: 49, 128: 17}, MegaMoE: AITER profile v41_flash_ep8 registered for 49 experts per rank, no amd_kernels route X disabled warning, no tracebacks.

Per-run detail (this PR)
run total tok/s/GPU output tok/s/GPU interactivity p90 / p50 TTFT p50 / p90 s requests
c256 205,990 1,414.6 194.8 / 230.9 1.54 / 3.66 40,447 in 3629 s, 1 failed
c512 350,591 2,578.6 96.0 / 159.3 1.95 / 5.09 72,622 in 3627 s, 0 failed
c1024 508,363 3,780.9 29.4 / 56.8 2.74 / 5.71 110,797 in 3630 s, 0 failed

AIPerf summary per point (ms unless noted; p50 / p90 / p99; one run each):

run ITL (full response) TTFT request latency output tok/s input tok/s spec AL (server log)
c256 4.33 / 5.13 / 8.78 1,539 / 3,659 / 17,604 3,927 / 14,644 / 52,600 11,284 1,631,822 3.51 (synthetic)
c512 6.28 / 10.42 / 28.83 1,946 / 5,085 / 14,597 5,797 / 21,177 / 76,937 20,555 2,774,190 3.51 (synthetic)
c1024 17.60 / 34.06 / 99.54 2,742 / 5,707 / 12,646 11,657 / 45,551 / 168,351 30,164 4,025,472 3.51 (synthetic)

lm_eval (lm-eval 0.4.9.2, --model local-chat-completions --apply_chat_template --tasks infx/evals/gsm8k.yaml --gen_kwargs max_tokens=16384,temperature=0,top_p=1, num_concurrent=1024):

|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.9629|±  |0.0052|
|     |       |strict-match    |     5|exact_match|↑  |0.9447|±  |0.0063|
PASS: gsm8k exact_match,strict-match = 0.9447 (>= 0.9 from default)
PASS: gsm8k exact_match,flexible-extract = 0.9629 (>= 0.9 from default)

Accuracy. lm_eval gsm8k as the InferenceX CI runs it (5-shot, chat template, all 1319, concurrency 1024, temperature 0, max_tokens 16384) against the server above at c256 flags: strict-match 0.9447 +- 0.0063, flexible-extract 0.9629 +- 0.0052, DSpark acceptance length 3.464 (synthetic rejection sampling, as in CI).

Tests, wired into the (MI355) DeepSeek V4 MoE Integration job (.buildkite/test-amd.yaml):

  • tests/models/deepseek_v41/amd/test_amd_kernels_routes.py (CPU): route resolution and prerequisites, every route's row gate, the DP-group-max branch of the collective fused EP8 route, the shared-expert plan and when the seam emits MXFP8 codes, the serial shared expert while routes are on, the draft model's post-load not disabling the target's router, the aux-hidden-state deferral, the warm-up sizes and the serving-transient floor.
  • tests/models/deepseek_v41/amd/test_amd_kernels_routes_gpu.py (one gfx950 GPU, VLLM_ROCM_USE_AITER=1): the glue through the amd-kernels entries against the stock vLLM path it replaces, on linears built and post-processed as the model does (real DeepSeek-V4.1 quant config, random weights), inside and outside each route's rows: dense MXFP8 GEMM (bf16 and MXFP8 input), wq_b on norm_dual's codes, wo_b on bf16, the wo_a -> wo_b chain at 768-1024 rows, grouped wo_a, lm_head, the router and the shared expert (both also under CUDA graph replay), the mHC seam incl. its stream-mean and MXFP8 outputs. The indexer, sparse MLA, compressor, RoPE insert, kv_score, mHC chains and tail, and Markov routes are covered by the end-to-end runs and GSM8K above, not by a unit test.
  • tests/models/deepseek_v41/amd/test_akr_eplb.py (CPU, two GPU tests): plan validation and lookup, the replica tables and their balance, the MegaMoE loader placing replicas, the AITER profile registration, the shipped plan on the measured load, the planner reproducing the shipped plan bit for bit from the committed counts (tests/models/deepseek_v41/amd/data/expert_counts_agentx_c1024.npz, 111 kB), the planner's replica and placement rules, the counting opt-in; on a GPU the remap kernel vs its host reference (eager and graph replay) and the counting kernel under CUDA graph replay and eager steps vs a bincount of the routed ids.
  • tests/models/deepseek_v41/amd/eplb_gpu8.py (8 GPUs, torchrun, not in CI): one MegaMoE layer loaded with the identity and with the S = 49 placement through the vLLM experts class, fused EP8 at 16-1024 rows and staged MegaMoE at 1-4096 rows (DP-max cases included), eager and graph replay: outputs bitwise equal to identity; the same for a DSpark draft layer (S = 17).
# CPU (CUDA_VISIBLE_DEVICES=-1), branch head 773b605f5
pytest -q tests/models/deepseek_v41/amd/test_akr_eplb.py tests/models/deepseek_v41/amd/test_amd_kernels_routes.py
40 passed, 6 skipped in 19.36s   (the 6 skips: "needs a GPU")
# one MI355X, VLLM_ROCM_USE_AITER=1, AITER 0.1.29.post1, FlyDSL 0.5.0, amd-kernels ba58826, branch head 773b605f5
VLLM_ROCM_USE_AITER=1 pytest -q tests/models/deepseek_v41/amd/test_amd_kernels_routes_gpu.py \
  tests/models/deepseek_v41/amd/test_akr_eplb.py tests/models/deepseek_v41/amd/test_amd_kernels_routes.py \
  tests/models/deepseek_v41/amd/mono
100 passed in 88.01s
# 8 x MI355X, mori, the code of e8c2488d4 (the last commit adds only a warning log, docs and a test helper)
torchrun --nproc-per-node 8 tests/models/deepseek_v41/amd/eplb_gpu8.py --layer {2,10,20,39}
  # S = 49, MegaMoE capacity 32768: fused EP8 16-1024 rows + graph replay, staged MegaMoE 1-4096 rows,
  # DP-max cases, staged graph replay -> 18 / 18 cases bitwise equal to the identity placement on each layer, "ALL OK"
torchrun --nproc-per-node 8 tests/models/deepseek_v41/amd/eplb_gpu8.py --draft --layer {41,42}
  # DSpark draft layers, S = 17 -> 11 / 11 cases bitwise equal on each layer, "ALL OK"

pre-commit run on every file the PR changes: clean. Not run: VLLM_GPU_SYNC_CHECK=error on the served configuration. The opt-in counting (VLLM_AKR_EXPERT_COUNTS) is covered by its GPU kernel test under CUDA graph replay and by the planner reproducing the shipped plan from the committed counts, but has not yet run in a full server on this branch (the committed counts were recorded with an earlier implementation of the counter).

Details

Routes and gates (akr_config.GATES; rows = the static, padded token count of the call, so a captured shape takes one branch; fused_ep8 uses the DP-group maximum). Every entry point returns None without launching anything where it does not serve, and the stock kernel runs; an amd_kernels entry that does not cover a call returns its blocker reason, logged once.

Route table
route replaces rows needs
rope_insert q RoPE + fp8 cast and KV RoPE + fp8 SWA insert 1-1024
norm_dual q/kv RMSNorm; q as MXFP8 for both wq_b linears 1-1024
compressor pool + norm + RoPE + main-cache insert + indexer key store 1-1024
kv_score compressor kv_score + indexer weights_proj in one GEMM 1-1024
dense_gemm wq_a+wkv, indexer wq_b (on norm_dual's codes) 1-768 (and the entry's winning rows)
wq_b attention wq_b on norm_dual's codes 769-1024 (AITER's FlyDSL GEMM on the same codes wins below) norm_dual
indexer decode rows of the MXFP4 top-512 indexer; writes the sparse-MLA ragged lists itself 1-768
sparse_mla AITER sparse MLA decode, MXFP8 epilogue 1-768
wo_a grouped wo_a with MXFP8 epilogue (wo_b reads the codes) 1-1024
wo_b wo_b through the dense entry on wo_a's bf16 output 769-1024 wo_a
router / draft_router target (384 experts, top 6) and draft (128, top 3) routers 1-1024
shared_expert gate_up + clamped SiLU-mul as MXFP8 for the mhc_ffn epilogue (standalone the stock chain wins, so it declines) 1-192
fused_ep8 MegaMoE's routed experts in one persistent launch 1-1024 per rank, DP-group max
mhc_seam AITER mega-mHC seam, with MXFP8 output for every consumer of the codes (+ the stream mean for DSpark) 1-288, 513-720 (stream-mean variant up to 4096)
mhc_tail post-mix + collapse + final norm (+ DSpark hidden buffer) 1-1024
mhc_wo_b / mhc_ffn wo_b / shared down + routed add with the post-mix epilogue, then the next seam 1-64 / 1-192 mhc_seam + wo_a / mhc_seam + shared_expert
lm_head bf16 head GEMM 113-128, 496-512
main_proj DSpark MXFP8 input projection 640-1024
markov the 5 sequential Markov draft steps in one launch 1-160 requests

Decode gating. Every gate is the row range where the route measured faster than the stock vLLM path it replaces on the same stack (dev1133 stock kernels incl. AITER's MXFP8 mHC seam, #67906), on one MI355X, graph replay, cold weight copies, median of interleaved A/B rounds. Decode at c1024 reaches 769-1024 rows per rank, so the router, compressor, kv_score, wq_b and wo_b routes cover those rows too; the mHC gates end where AITER's MXFP8 seam catches up.

Gate measurements (us per call, stock vs route)

769-1024 rows, at 784 / 848 / 960 / 1024 rows:

route stock amd_kernels
router (GateLinear + fused_topk_bias) 27.76 / 28.15 / 28.70 / 28.50 17.41 / 17.33 / 17.37 / 17.36
wq_b (stock linear on norm_dual's codes) 45.85 / 46.73 / 50.56 / 51.56 43.75 / 44.30 / 46.47 / 49.50
wo_b (wo_a MXFP8 epilogue + stock wo_b) 86.46 / 85.60 / 88.07 / 93.15 75.15 / 77.57 / 84.94 / 85.90
kv_score + weights_proj, ratio 2 / ratio 1 / weights only 32.76-33.94 / 27.11-27.86 / 9.58-10.08 28.62-29.32 / 22.85-23.88 / 7.18-7.51
compressor tail, ratio 2 / ratio 1 18.23-18.77 / 11.92-12.70 13.43-13.91 / 9.56-10.06

mHC seam (attention + FFN seam with the first GEMM on its codes), 20 rounds:

rows 688 704 720 736 752 768
AITER MXFP8 seam 79.88 80.64 80.91 80.83 81.06 81.37
amd_kernels seam 78.52 79.62 80.49 80.68 81.51 82.21

mHC chains vs the stock GEMM on the seam's codes + the amd_kernels seam (what runs where the chain is off):

rows 1 24 32 48 64 72 96 128 192 208
mhc_wo_b chain 13.90 18.39 19.34 22.38 22.93 29.81 32.51 32.70 38.45 43.09
stock wo_b + seam 15.56 20.51 20.90 22.60 23.32 25.45 26.87 28.87 33.82 38.94
mhc_ffn chain 9.07 10.69 11.03 11.64 13.92 15.79 16.35 17.07 20.61 24.33
stock down + seam 13.65 16.25 16.60 17.83 18.46 17.86 18.47 19.48 21.79 22.85

mhc_tail vs MHCPostOp + collapse + RMSNorm at 16 / 128 / 512 / 848 / 1024 rows: 3.62 / 4.48 / 9.33 / 17.07 / 18.43 vs 25.85 / 36.00 / 53.87 / 67.98 / 73.99.

Why not vLLM's EPLB. vLLM's EPLB rebalances from runtime counts and has no static initial placement. It cannot serve this setup today: (a) --enable-eplb raises NotImplementedError for AITER MegaMoE (deepseek_v4/amd/model.py); (b) it does not cover the fused EP8 route or the DSpark draft layers; (c) DefaultEplbPolicy balances one load vector, while decode and prefill steps here favour different experts and the planner balances both at once; (d) a static plan needs no rebalancing steps, weight moves or extra collectives. The placement uses EPLB's rank-major physical-id convention, so it can become an EPLBConfig static initial-placement file once #61176 (EPLB on AITER MegaMoE) lands; that move is planned as a follow-up. The counting stays an environment variable (VLLM_AKR_EXPERT_COUNTS) because the model-state class is chosen by a static get_model_state_cls() that has no config; it is honoured only by DeepSeek-V4.1 on AITER MegaMoE with the V2 model runner.

Static expert placement (EPLB without the runtime rebalancer). At EP8 the default placement gives rank r experts 48 r .. 48 r + 47, and the busiest rank sets the pace of each MoE dispatch/combine. Counted over 31 minutes of AgentX at c1024 on all 8 DP ranks (121k decode-only and 15k prefill-carrying rank-steps), the per-rank routed load max/mean is 1.64 on average over the 40 layers (decode 1.67, prefill 1.58; worst layer 2.09), and decode and prefill favour different experts (total variation ~0.49 per layer). amd_kernels.expert_perm names a plan: S slots per rank and layer, so 8 S - 384 replicas of the hottest experts.

  • Runtime: the loader copies a checkpoint expert into every local slot that holds it; the routers keep choosing logical ids, and right before the experts run one Triton launch maps each id to l2p[e, hash(token * top_k + k, layer, rank) % count[e]] (deterministic, graph safe, uniform over the replicas; ids < 0 stay). The physical ids are rank-major (owner = id // S), the convention of MegaMoE, the fused EP8 kernel and vLLM's EPLB. Outputs are bitwise identical to the default placement in the 8-rank test (replicas hold the same weights).
  • Shipped plan configs/expert_plan_S49.npz (S = 49, draft S = 17): per-rank load max/mean 1.003 on the fitted counts and about 1.02-1.03 per simulated decode step (324-710 tokens per rank through the runtime's hash), which is the noise floor of uniform routing (the load-balance metric on an even/odd-DP-rank holdout stays within 0.5% of in-sample). Memory +0.8 GB per rank (one 18.8 MB MXFP4 expert per layer, 40 + 3 layers), about 0.6% fewer KV tokens. It is fitted on one workload, so expert_perm stays empty by default; no end-to-end number isolates the placement from the routes.
  • Plan generation: VLLM_AKR_EXPERT_COUNTS=<dir> makes every MegaMoE layer count its routed logical ids (one graph-safe Triton launch per layer, padding rows excluded, decode-only and prefill-carrying steps apart, the step kind set by a DeepseekV41ModelState subclass so the model runner is untouched); python -m vllm.models.deepseek_v41.amd.akr_eplb_plan --counts <dir> --slots 49 --out plan.npz replicates the experts with the largest per-replica load (at most one replica per rank) and places the replicas longest-first on the rank that minimises the larger of its decode and prefill load. The committed counts reproduce the shipped plan bit for bit (test above).
  • AITER keys its tuned MegaMoE profile for this model on 48 experts per rank; [FlyDSL] [MegaMoE] Tune DeepSeek-V4.1-Flash EP8 at 49 experts per rank (EPLB replicas) ROCm/aiter#8453 adds 49, and register_aiter_profile bridges until it ships. With fused_ep8 off, S = 49 also loses AITER's fixed-slot MegaMoE runtime for <= 128 tokens per rank (AITER enables it at 48 per rank only); with fused_ep8 on, the staged MegaMoE only runs above 1024 DP-max rows, where both placements pick the same runtime.

Collective rules. fused_ep8 dispatch/combine is a collective: the branch is decided by akr_config.dp_rows (the step's DP-group maximum), so every EP rank takes the same branch and MegaMoE stays the staged fallback above 1024 rows per rank. Eligibility uses only config and shapes. Building the expert-parallel context and its warm-up are collectives that run in process_weights_after_loading on every rank in the same order, before graph capture. akr_config.fail is process-wide, so only the target model may take a route out for lacking eligible layers.

Serial shared expert. While the MoE-block routes are on, MegaMoE layers run the shared expert after the routed experts on the default stream. The aux-stream overlap put the shared gate_up GEMM beside MegaMoE's persistent, spin-waiting stage-1 kernel; neither got all its workgroups resident and both stalled for 1.3-13.7 ms per occurrence in DEP8 decode traces.

Warm-up. FlyDSL 0.5 traces a kernel variant before it looks up its disk cache, so the first launch of each variant in a process costs 0.3-7 s even with a warm cache, and with DP ranks in lockstep all ranks wait. akr_warmup.prefill_warmup runs from kernel_warmup before graph capture: each distinct linear (target and draft) and the grouped wo_a at one size per AITER GEMM bucket above the captured sizes, then whole-model dummy steps at 10 prefill sizes. It adds ~90 s to start-up; amd_kernels.prefill_warmup=false skips it.

Memory headroom. With the routes on, the extensible KV cache's sizing measured 10.65 GiB of torch growth (stock 14.55), which left 17.5 GiB after sizing; at c1024 a 32k-token prefill chunk beside 96 decodes failed a 2 GiB allocation after ~25 min. amd_kernels.serving_transient_gib (default 20, 0 = off) floors the growth the sizing keeps free.

Code layout. akr_config.py (gates), akr_kernels.py (the only module that touches amd_kernels), one glue module per route group (akr_attn, akr_indexer, akr_mla, akr_moe, akr_experts, akr_mhc, akr_draft, akr_sample), akr_hooks.py (post-load), akr_warmup.py, akr_eplb.py (placement), akr_expert_counts.py (opt-in counting), akr_eplb_plan.py (offline planner, never imported at runtime). Model hooks are akr attributes that default to None on the shared DeepSeek-V4 MoE/MLP/MegaMoE/compressor classes, overrides in the ROCm V4.1 attention class, and a skip_decode flag on the ROCm MXFP4 indexer op. Outside vllm/models/: AmdKernelsConfig fields, one kernel_warmup call, VLLM_AKR_EXPERT_COUNTS in envs.py (left out of the compile hash: this model is not torch.compiled), the *.npz package data and the Dockerfile pin; the model runner and scheduler are untouched.

Caveats.

  • Gates are fitted on MI355X with this checkpoint's shapes; other gfx950 parts and other DSv4.1 sizes are untested (amd-kernels declines shapes it does not cover).
  • Same-settings CI numbers exist only at c256; the c512 and c1024 rows have no CI counterpart with the delayer.
  • The shipped placement is in-sample for AgentX; for other traffic, count and plan as in docs/features/amd_kernels.md.
  • A short-row step at a 1M-entry indexer bound runs 10-20% slower than at a 262144 bound (one static bound per layer; lower --max-model-len or set indexer_max_ctx).
  • eplb_gpu8.py needs 8 GPUs, mori and torchrun, so CI does not run it.
  • The GPU routes test skips when VLLM_ROCM_USE_AITER=1 is unset or the amd-kernels entries are missing; the MI355 job sets the variable and its image installs amd-kernels from the Docker pin, but an image without amd-kernels would pass that file by skipping it.

Not duplicating. Searched open PRs for amd_kernels, DeepSeek-V4.1 MI355X, MegaMoE EPLB, expert placement replicas ROCm, expert load counting. #67850 / #68553 are MiniMax-M3.1 only, #69172 Kimi-K3.1. #61176 enables vLLM's dynamic EPLB on AITER MegaMoE for DeepSeek-V4(-Pro) (--enable-eplb, periodic rebalancing with weight moves); this PR's placement is static, needs no rebalancing steps or extra collectives, covers the DSpark draft layers and the fused EP8 route, and uses the same rank-major physical-id convention, so the counting and planner could seed #61176's initial placement if it lands. #64835 places MegaMoE weights in GPU memory locality domains on NVIDIA (DeepGEMM), not experts across ranks. #68385 (MegaMoE improvements), #67800 (q RoPE fusion) and #67584 (MegaMoEV2 route hint) touch neighbouring code and are independent. This PR's author also has draft PRs #68992, #68993, #68995-#68998, #69017, #69022 that wire AITER ports of several of these kernels into the same call sites one by one; where both cover a call site only one should land, and which (amd-kernels routes here or AITER kernels there) is the reviewers' choice.


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.

AI assistance (Claude Code) was used; Fangzhou Ai is the human owner and reviewed/defends this change.

🤖 Generated with Claude Code

@mergify mergify Bot added ci/build deepseek Related to DeepSeek models minimax rocm Related to AMD ROCm speculative-decoding labels Nov 21, 2026
@mergify mergify Bot added the dflash label Nov 21, 2026
@mergify mergify Bot added the mrv2 Model Runner V2 specific label Nov 21, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Nov 21, 2026
@mergify mergify Bot added the kv-connector label Nov 21, 2026
@mergify mergify Bot added the nixl NIXL KV connector / multi-tiered KV offloading (KVCR) label Nov 21, 2026
@mergify

mergify Bot commented Nov 21, 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, @Fangzhou-Ai.

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

benenzhu and others added 11 commits November 22, 2026 07:16
… MI355X

Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…che for long multi-turn prompts

SimpleCPUOffload: opt-in CPU eviction by last use, tail first, behind
kv_connector_extra_config "cpu_lru_eviction": true (default false keeps the
current order). A CPU lookup stops at the first missing block, so evicting
block 0 drops the whole chain. With the switch, a finished request's
contiguous CPU prefix is requeued as most recent, tail first, once its last
store lands, and CPU blocks released after a load or a dropped lookup pin go
back tail first.

Prefix token cache: a multi-turn chat request carries the whole conversation,
and the HF fast tokenizer encodes the text between added tokens
independently, so the next turn's ids start with the previous turn's ids up
to an added-token cut. The renderer keeps recent long prompts' ids by rolling
digests of those cuts and encodes only the rest; only when special tokens are
explicitly off and the tokenizer's added tokens match the raw text, checked
against a whole encode on the first prompts. On 600 InferenceX AgentX
requests (MiniMax-M3.1, p50 157K tokens): encode p50 196 -> 14 ms, mean
282 -> 59 ms, ids identical on all 583 eligible prompts.

Tests: tests/v1/simple_kv_offload/test_scheduler.py (four LRU cases),
tests/v1/kv_connector/unit/test_simple_cpu_offload_connector.py (opt-in key),
tests/renderers/test_prefix_token_cache.py.

Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…penai image

amd_kernels (https://github.com/Inferact/amd-kernels) holds the FlyDSL
kernels MiniMax-M3.1 runs on gfx950 where the package is installed. It is
pure Python and not on PyPI, so the image pins a tag of its repository
(AMD_KERNELS_TAG), as the stack pins AITER by AITER_BRANCH; --no-deps keeps
the stack's torch, AITER and FlyDSL.

TODO: amd_kernels needs FlyDSL >= 0.5.0, but the stack's AITER v0.1.29 pins
flydsl==0.4.2 (AITER main pins 0.5.0): move AITER_BRANCH to AITER's first
release with 0.5.0. Not built yet.

Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
… tokenizer name, mypy Optionals

check-docstring-style rewrote double backticks in the new docstrings; prefix_token_cache imports regex as re; its test builds a TokenizersBackend; mypy: assert the indexer and the cache are set, annotate BaseRenderer._prefix_token_cache. uvx pre-commit run --hook-stage manual on the changed files passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
…e MoE config

Main's MiniMaxM3VLTextConfig (the upstream Transformers class) has no swiglu_beta or scoring_func: the route's support check read both from the HF config and every worker raised AttributeError at model init. Read alpha / limit / beta from the routed experts' FusedMoEConfig (beta 1.0, as the model passes it) and drop the scoring check (the model always routes by sigmoid).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
Main's MoE modular kernel reads supports_dbo() only under the dispatch-combine-overlap DBO schedule; pure TP runs all-reduce-overlap, so the override no longer does anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Taoyu Zhu <zhutaoyu97@gmail.com>
…sed EP8 MoE)

Extend the amd_kernels route framework of vllm-project#67850 to DeepSeek-V4.1-Flash
at DEP8 (TP1 x DP8, EP8) on gfx950: 20 routes covering attention input
(rope/fp8 KV insert, dual RMSNorm + MXFP8, compressor insert, fused
kv_score + weights_proj, dense MXFP8 GEMMs), the MXFP4 top-512 indexer,
sparse MLA decode, grouped wo_a with an MXFP8 epilogue, routers, the
shared expert, the fused EP8 routed experts, the mHC seams/tail and fused
post-mix epilogues, lm_head, the DSpark main_proj and Markov chain.

All calls go through akr_kernels.py to the shape-agnostic op entries of
amd_kernels (Inferact/amd-kernels#11); a call an entry does not cover
returns its blocker reason and runs the stock path. Collective routes
decide on the DP-group max row count. With routes on, MegaMoE layers run
the shared expert serially, and kernel_warmup traces the prefill-only
FlyDSL 0.5 variants before graph capture.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
…sients at KV sizing

With the routes on, the extensible KV cache's sizing steps measured 10.65 GiB
of torch growth (stock 14.55), leaving 17.5 GiB after sizing; at c1024 a
32k-token prefill chunk beside 96 decodes reached 16.7 GiB and failed a 2 GiB
wq_b allocation. kernel_warmup now floors torch_reserve_growth_bytes at
kernel_config.amd_kernels.serving_transient_gib (default 20, 0 = off).

Pin amd-kernels to the head of Inferact/amd-kernels#12 (the DeepSeek-V4.1
kernels and the #11 op entries) until a release tag has it. GPU glue tests
build their linears as the model does (bf16 default dtype, 32 x 32 block
scales, batched wo_a).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
…ter, compressor, kv_score, wq_b, wo_b

At c1024, 29 of 36 decode steps run at 816-864 rows per rank, above the 768-row gates, so
these routes fell back to the stock kernels there. The amd_kernels rows now reach 1024:

- router, compressor, kv_score: gate 1-1024 (20.5-20.7 us vs 28.6-30.3 us for the router,
  1.24-1.36x for the compressor chain, 1.12-1.40x for the kv_score GEMM at 769-1024 rows).
- wq_b (new route, 769-1024 rows): the 4-wave GEMM on norm_dual's codes; norm_dual allocates
  the scales in the storage of ceil(M / 32) rows so one launch moves them to the kernel's
  layout. Reads the stock linear's preshuffled weight (no copy). 2.3-6.4 us under AITER.
- wo_b (new route, 769-1024 rows, needs wo_a): wo_a writes bf16 and the dense entry runs
  wo_b, 2.4-8.8 us under wo_a's MXFP8 epilogue + AITER per pair.

Each is switchable alone with kernel_config.amd_kernels.disabled_routes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
…with replicas (amd_kernels.expert_perm)

At c1024 the routed load per EP rank is uneven: the hottest rank takes 1.3-2.7x the
mean routes in the measured layers, and the fused EP8 / MegaMoE step waits for it.
kernel_config.amd_kernels.expert_perm names a placement plan (.npz, a bare name is looked
up in vllm/models/deepseek_v41/amd/configs/) that gives every rank S slots per layer and
lets a hot expert hold several slots:

- akr_eplb.py: plan validation (sha256 logged; wrong EP size, a missing backbone layer or
  a logical expert without a slot raise), per-layer logical -> physical tables, and the id
  remap: one Triton launch, graph safe, physical id = l2p[e, hash(token * K + k, layer,
  rank) % count[e]] (uniform over an expert's replicas, deterministic), ids < 0 unchanged.
- DeepseekV4AiterMegaMoEExperts: S slots per rank; the weight loader copies a checkpoint
  expert into every local slot that holds it; forward remaps the routers' logical ids
  right before the fused EP8 route or MegaMoE (rank-major physical ids, owner = id // S).
  Unset: identity placement, nothing imported, one `is None` test per call.
- fused EP8: the expert-parallel context takes S from the layers (48 <= S <= 63 in the
  kernel); a layer with another S stays on MegaMoE.
- configs/expert_plan_S49.npz (sha256 c04d6ac0...): 40 backbone layers S = 49 (392 slots,
  one replica slot per rank) and the 3 DSpark draft layers S = 17, fitted on c1024 AgentX
  expert counts (decode and prefill balanced jointly, hot experts replicated on distinct
  ranks). 8-rank fused EP8 per-call time on routes drawn from the measured counts, us,
  identity -> S = 49: T 324 rows 262-374 -> 233-245, T 710 453-730 -> 416-428,
  T 960 588-942 -> 509-517 (max/mean routes per rank 1.31-2.66 -> 1.02-1.04).
- S = 49 on MegaMoE: AITER keys its tuned DeepSeek-V4.1-Flash EP8 profile
  (`v41_flash_ep8`) on 48 experts per rank only, so S = 49 would run the base config.
  `akr_eplb.register_aiter_profile` registers the same profile for 49 experts per rank
  (copy of the `v41_flash_ep8` entry of mega_moe_config._NETWORKS, then
  build_mega_moe_bundle_plan.cache_clear()) before the runtimes are built; a no-op for any
  other S. Needed upstream in AITER: let EPLB family profiles of a network (here
  experts_per_rank 49) apply its tuner, then this hook goes away.

Tests: tests/models/deepseek_v41/amd/test_akr_eplb.py (plan validation, loader slots,
replica coverage / balance / determinism / pads, the experts class loader, the AITER
profile, the shipped plan on the measured counts, the remap kernel vs its reference
eagerly and under graph replay) and eplb_gpu8.py (8 ranks: the experts class loaded with
identity and with the plan, fused EP8 + staged MegaMoE + graph replay, placed == identity).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
@mergify

mergify Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--69097.org.readthedocs.build/en/69097/

…ecode layer skips

akr_mhc.defer_aux hands the auxiliary hidden state of layer N-1 to the seam of
layer N. With --monokernel, the mono decode layer takes decode steps of up to
48 rows and returns before its seam, so akr_mhc.aux_out stayed None and the
DSpark speculator's torch.cat over aux_hidden_states failed with
"'NoneType' object is not subscriptable" during kernel warmup (TP2, bridge
routes on). Decline the deferral when the next layer's mono decode takes the
step; the stock post-mix and mean then produce the state.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
@Fangzhou-Ai

Copy link
Copy Markdown
Collaborator Author

Pushed 35d5044: with --monokernel the DSpark draft step crashed in kernel warmup at TP2 (TypeError: 'NoneType' object is not subscriptable in _store_hidden_states) when the amd_kernels routes were on. akr_mhc.defer_aux handed the aux hidden state of layer N-1 to the seam of layer N, but the mono decode layer returns before that seam for decode steps of up to 48 rows, so aux_out stayed None. defer_aux now declines when the next layer's mono decode takes the step (new MonoDecodeLayer.takes_step); nothing changes without --monokernel. Checked on 2 x MI355X: TP2, mono decode and all routes on starts, answers correctly, GSM8K 0.945 strict / 0.965 flexible on 200 questions.

@mergify

mergify Bot commented Nov 23, 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, @Fangzhou-Ai.

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 23, 2026
seungrokj added a commit to SemiAnalysisAI/InferenceX that referenced this pull request Nov 25, 2026
- Update the image of the existing MI355X vLLM DeepSeek-V4.1-Flash AgentX entries (TP4/TP2 c1-64, TP8 c1, UMBP c128/c256/c384) from vllm/vllm-openai-rocm:nightly-9c1d45c21836370104d4eb51d3b46eda20719c47 to vllm/vllm-openai-rocm:deepseek-v41-flash-8a13616, which the new DEP8 entry also uses. The image is built from the vllm-project/vllm branch dsv41f-amd-kernels at 8a136163b6: main 647a76866 (which contains 9c1d45c2) plus 50 commits.
- Add dsv41flash-fp4-mi355x-vllm-agentic-dspark-dep8: DEP8 (TP1 x DP8 with expert parallelism over the 8 ranks) behind a consistent-hash vllm-router 0.1.14 at concurrency 256, 512 and 1024. The search spaces and concurrencies of the existing entries are unchanged.
- The existing points add kernel-config amd_kernels.enabled=false, so the amd_kernels bridge in the new image resolves no routes and they keep the stock vLLM kernels. Their other recipe settings are unchanged.
- The DEP8 points run AITER MegaMoE over MoRI (--moe-backend aiter_mega_moe, --all2all-backend mori), the per-tensor FP8 KV cache (--kv-cache-dtype fp8_e4m3), Engram tables in HBM with embedding_across_dp, max-num-seqs 128 (160 at concurrency 1024), max-num-batched-tokens 32768, long-prefill-token-threshold 8192, max-cudagraph-capture-size 1024, monokernel off, and the inherited five-token DSpark.
- The DEP8 points use the cross-DP prefill delayer (--prefill-schedule-policy delayer, --prefill-max-wait-ms 5000, --prefill-schedule-interval 96) and turn on every amd_kernels route (--kernel-config) with the static 49-slot-per-rank expert placement expert_plan_S49.npz shipped in the image.
- The DEP8 router runs with LD_PRELOAD=/opt/dsv41f/lib/listen_backlog_shim.so and LISTEN_BACKLOG_MIN=4096, which raise its listen() backlog from the 128 that vllm-router 0.1.14 hard-codes and that resets connections in the AgentX warm-up burst.
- The mi355x-amds cluster no longer excludes node mia1-p01-g11 from slurm jobs; mia1-p01-g09 stays out of multi-node jobs only, as on main.
- Framework changes in the new image: the amd_kernels DEP8 routes and static expert placement (vllm-project/vllm#69097, stacked on #67850, with the kernels of Inferact/amd-kernels#12), the cross-DP prefill delayer (#65655) and hold (#66927); these four vLLM PRs are unmerged; from main, the fused compressed-KV insert (#67364), the one-launch sparse-MLA ragged top-k (#67365) and the DSpark draft packed_modules_mapping (#65647).
- Draft data type unchanged: the DSpark draft (mtp.0-2 in the target checkpoint) runs as shipped, with FP8 E4M3 32x32 UE8M0 block-scaled attention, shared-expert and main_proj weights run as MXFP8, MXFP4 routed experts (a8w4), BF16 gate, norms and the shared LM head, and the KV cache dtype it inherits from the target (fp8_ds_mla by default, per-tensor fp8_e4m3 at DP2 c128-c384 and DEP8). At DEP8, the amd_kernels routes keep the same MXFP8 and BF16 weight codes, scales and activation formats as the stock path.

- 将现有 MI355X vLLM DeepSeek-V4.1-Flash AgentX 条目(TP4/TP2 c1-64、TP8 c1、UMBP c128/c256/c384)的镜像从 vllm/vllm-openai-rocm:nightly-9c1d45c2 更新为 vllm/vllm-openai-rocm:deepseek-v41-flash-8a13616,新的 DEP8 条目也使用该镜像。该镜像由 vllm-project/vllm 的 dsv41f-amd-kernels 分支 8a136163b6 构建:main 647a76866(包含 9c1d45c2)加 50 个提交。
- 新增 dsv41flash-fp4-mi355x-vllm-agentic-dspark-dep8:DEP8(TP1 x DP8,8 卡专家并行),前置 consistent-hash vllm-router 0.1.14,并发 256、512、1024。现有条目的搜索空间和并发不变。
- 现有点位新增 kernel-config amd_kernels.enabled=false,新镜像中的 amd_kernels 桥接不启用任何路由,保持原生 vLLM 内核;其他配方设置不变。
- DEP8 点位使用基于 MoRI 的 AITER MegaMoE、per-tensor FP8 KV cache(fp8_e4m3)、启用 embedding_across_dp 且驻留 HBM 的 Engram 表、max-num-seqs 128(c1024 为 160)、max-num-batched-tokens 32768、long-prefill-token-threshold 8192、max-cudagraph-capture-size 1024,关闭 monokernel,并继承五 token DSpark。
- DEP8 点位使用跨 DP prefill delayer(最长等待 5000 ms,间隔 96),并启用全部 amd_kernels 路由及镜像自带的静态专家布局 expert_plan_S49.npz(每 rank 49 个槽位)。
- DEP8 router 通过 LD_PRELOAD 垫片和 LISTEN_BACKLOG_MIN=4096 将 listen() backlog 从 vllm-router 0.1.14 写死的 128 提高,避免 AgentX 预热突发时连接被重置。
- mi355x-amds 集群不再在 slurm 作业中排除 mia1-p01-g11;mia1-p01-g09 与 main 一致,仅不参与多节点作业。
- 新镜像中的框架变更:amd_kernels DEP8 路由和静态专家布局(vllm-project/vllm#69097,基于 #67850,内核来自 Inferact/amd-kernels#12)、跨 DP prefill delayer(#65655)和 hold(#66927),这四个 vLLM PR 均未合入;来自 main 的 fused compressed-KV insert(#67364)、单次启动的 sparse-MLA ragged top-k(#67365)和 DSpark 草稿 packed_modules_mapping(#65647)。
- 草稿模型数据类型不变:DSpark 草稿(目标 checkpoint 中的 mtp.0-2)按发布精度运行:FP8 E4M3 32x32 UE8M0 的注意力、共享专家和 main_proj 权重按 MXFP8 运行,MXFP4 路由专家(a8w4),BF16 gate、norm 和共享 LM head;KV cache 继承目标模型类型(默认 fp8_ds_mla,DP2 c128-c384 与 DEP8 为 per-tensor fp8_e4m3)。DEP8 下 amd_kernels 路由保持与原生路径相同的 MXFP8/BF16 权重编码、缩放和激活格式。

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

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

ci/build deepseek Related to DeepSeek models dflash documentation Improvements or additions to documentation kv-connector minimax mrv2 Model Runner V2 specific needs-rebase nixl NIXL KV connector / multi-tiered KV offloading (KVCR) rocm Related to AMD ROCm speculative-decoding

Projects

Status: Todo
Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants