Repository navigation
[Stacked on #67850][ROCm][DeepSeek-V4.1-Flash] amd_kernels routes for DEP8 on MI355X (fused EP8 MoE, static expert placement) - #69097
Conversation
|
This pull request has merge conflicts that must be resolved before it can be |
5cd28d5 to
663767d
Compare
… 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>
|
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>
|
Pushed 35d5044: with |
|
This pull request has merge conflicts that must be resolved before it can be |
- 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>
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, lazyamd_kernelsimports, 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:
docker/Dockerfile.rocmamd-kernels install, AITER v0.1.29.post1 with FlyDSL 0.5.0.amd_kernels.<category>.<op>,<op>_blocker,<op>_shapes,gemm.mxfp8_common.gemm), never a shape package.docker/Dockerfile.rocmpinsAMD_KERNELS_TAGto that PR's head, ba58826; a pin to an unmerged PR's commit is fragile, so it is replaced by an amd-kernels release tag that contains Implement preemption via recomputation & Refactor scheduling logic #12 before this PR merges.v41_flash_ep8MegaMoE profile at 49 experts per rank. Until the pinned AITER has it,akr_eplb.register_aiter_profileregisters the same profile for S = 49 at startup (only when a plan with S = 49 is configured).Claims
amd_kernelsimports;--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 (theakrhooks stayNone). 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.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.
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, datasetsemianalysis_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 whileVLLM_AKR_EXPERT_COUNTSis 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
--max-num-seqs 160at 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 anLD_PRELOADshim. 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=c04d6ac05d76846cwith slots per rank{384: 49, 128: 17},MegaMoE: AITER profile v41_flash_ep8 registered for 49 experts per rank, noamd_kernels route X disabledwarning, no tracebacks.Per-run detail (this PR)
AIPerf summary per point (ms unless noted; p50 / p90 / p99; one run each):
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):Accuracy.
lm_evalgsm8k 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 Integrationjob (.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_bonnorm_dual's codes,wo_bon bf16, thewo_a->wo_bchain at 768-1024 rows, groupedwo_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).pre-commit runon every file the PR changes: clean. Not run:VLLM_GPU_SYNC_CHECK=erroron 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_ep8uses the DP-group maximum). Every entry point returnsNonewithout launching anything where it does not serve, and the stock kernel runs; anamd_kernelsentry that does not cover a call returns its blocker reason, logged once.Route table
rope_insertnorm_dualcompressorkv_scoredense_gemmnorm_dual's codes)wq_bnorm_dual's codesnorm_dualindexersparse_mlawo_awo_bwo_arouter/draft_routershared_expertmhc_ffnepilogue (standalone the stock chain wins, so it declines)fused_ep8mhc_seammhc_tailmhc_wo_b/mhc_ffnmhc_seam+wo_a/mhc_seam+shared_expertlm_headmain_projmarkovDecode 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:
norm_dual's codes)mHC seam (attention + FFN seam with the first GEMM on its codes), 20 rounds:
mHC chains vs the stock GEMM on the seam's codes + the amd_kernels seam (what runs where the chain is off):
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-eplbraisesNotImplementedErrorfor AITER MegaMoE (deepseek_v4/amd/model.py); (b) it does not cover the fused EP8 route or the DSpark draft layers; (c)DefaultEplbPolicybalances 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 anEPLBConfigstatic 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 staticget_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
rexperts48 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_permnames a plan: S slots per rank and layer, so8 S - 384replicas of the hottest experts.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).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, soexpert_permstays empty by default; no end-to-end number isolates the placement from the routes.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 aDeepseekV41ModelStatesubclass so the model runner is untouched);python -m vllm.models.deepseek_v41.amd.akr_eplb_plan --counts <dir> --slots 49 --out plan.npzreplicates 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).register_aiter_profilebridges until it ships. Withfused_ep8off, S = 49 also loses AITER's fixed-slot MegaMoE runtime for <= 128 tokens per rank (AITER enables it at 48 per rank only); withfused_ep8on, the staged MegaMoE only runs above 1024 DP-max rows, where both placements pick the same runtime.Collective rules.
fused_ep8dispatch/combine is a collective: the branch is decided byakr_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 inprocess_weights_after_loadingon every rank in the same order, before graph capture.akr_config.failis 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_warmupruns fromkernel_warmupbefore 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=falseskips 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 touchesamd_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 areakrattributes that default toNoneon the shared DeepSeek-V4 MoE/MLP/MegaMoE/compressor classes, overrides in the ROCm V4.1 attention class, and askip_decodeflag on the ROCm MXFP4 indexer op. Outsidevllm/models/:AmdKernelsConfigfields, onekernel_warmupcall,VLLM_AKR_EXPERT_COUNTSinenvs.py(left out of the compile hash: this model is not torch.compiled), the*.npzpackage data and the Dockerfile pin; the model runner and scheduler are untouched.Caveats.
docs/features/amd_kernels.md.--max-model-lenor setindexer_max_ctx).eplb_gpu8.pyneeds 8 GPUs, mori and torchrun, so CI does not run it.VLLM_ROCM_USE_AITER=1is 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-checklistskill. (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