Repository navigation
[ROCm][DSv4.1] Opt-in AITER FlyDSL a8w4 experts op for the MXFP4 MoE (aiter backend) - #68995
Draft
Fangzhou-Ai wants to merge 2 commits into
Draft
Fangzhou-Ai wants to merge 2 commits into
Fangzhou-Ai wants to merge 2 commits into
Conversation
…hind a flag With VLLM_ROCM_USE_AITER_FLYDSL_MOE_A8W4=1 (default off), AiterMxfp4Experts sends the calls that aiter.ops.flydsl.moe_a8w4_experts supports (DeepSeek-V4.1-Flash routed experts: hidden 5120, intermediate 2304, top-3/top-6, <= 63 local experts, 1-1024 tokens, SwiGLU limit 10, gfx950) to that op instead of aiter.fused_moe. It reads the same preshuffled weights without a copy. Under expert parallelism the global ids are mapped to local ids with the expert mask, and the op is only used up to 192 (top-6) / 48 (top-3) tokens, where it was measured faster. The op is imported lazily; AITER builds without it, other shapes, DBO, prequantized inputs and uncompiled shapes under graph capture keep aiter.fused_moe. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
…, real-op tests - Pass each layer's own ready-counter workspace (allocated on the first eager call, before capture) to the op instead of relying on the op's shared per-device workspace. - Hook the op in through a small AiterExperts._fast_path_experts method instead of overriding apply(). - Apply the EP token caps only on EP8, where they were measured, and set them to 160 (top-6) and 96 (top-3) from layer-rotated measurements. - Require AITER_BF16_FP8_MOE_BOUND <= tokens, i.e. the a8w4 path that aiter.fused_moe takes and the op matches. - Check the graph-capture preconditions before enqueuing the id mapping. - Replace the stand-in dispatch tests with a real-op parametrization (cap boundaries, EP4, no SwiGLU limit) that compares against the op's own output, and use _assert_deterministic; fixes the mypy errors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
6 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds an opt-in call site,
VLLM_ROCM_USE_AITER_FLYDSL_MOE_A8W4=1(default off), for AITER's new FlyDSL a8w4 routed-experts op. With the flag on,AiterMxfp4Experts(the--moe-backend aiterMXFP4 path) sends the calls the op supports toaiter.ops.flydsl.moe_a8w4_expertsinstead ofaiter.fused_moe. These calls are the DeepSeek-V4.1-Flash routed experts of the target model and of the DSpark draft.Depends on ROCm/aiter#8381 (not merged or released yet). The op is imported lazily, so on any AITER without it nothing changes and
aiter.fused_moekeeps running.Who runs this path. Only deployments that serve DeepSeek-V4.1-Flash's MXFP4 experts with
--moe-backend aiteruse it: TP or EP with the default all-gather / reduce-scatter dispatch (for example DP8 + EP8 with--moe-backend aiter), or a single GPU. The DSv4.1-Flash DEP8 recipe that uses--moe-backend aiter_mega_moe(MegaMoE) does not reach this code. The sibling PRs #68998 (AITER FusedEPMoE foraiter_mega_moesmall batches) and #68997 (FlyDSL MoE router) cover that deployment. Under EP8 this PR only takes calls up to 160 (top-6) or 96 (top-3) gathered rows. With DSpark (6 rows per request, every DP rank padded to the same count) that is at most 3 target requests per rank, so it helps low-concurrency decode.Claims
Scope. The flag routes a call only when all of these hold:
VLLM_ROCM_USE_AITER_MOE_A4W4_DSV4), andAITER_BF16_FP8_MOE_BOUND<= tokens. That is the condition under whichaiter.fused_moeruns a8w4. The DeepSeek-V4 weight conversion sets the bound to 0.expert_tokens_meta, no DBO.All other calls keep
aiter.fused_moe.Same weights, same math. The op reads the tensors
AiterMxfp4Expertsalready holds, without a copy (shuffle_weight_a16w4/shuffle_scale_a16w4layouts). Its numerics are the a8w4 math thataiter.fused_moeruns here: MXFP8 input,silu(min(gate, 10)) * clamp(up, -10, 10), MXFP8 intermediate. It sums the top-k slots in a fixed order, without atomics, so its outputs are bitwise repeatable.Speed at the call site. These are microbenchmarks with graph replay on MI355X, with 8 layers' weights rotated (tables below):
aiter.fused_moeties or wins, which is why the caps exist.End to end: not measured yet, see E2E status. No end-to-end speedup or accuracy result is claimed.
Validation
Hardware and stack:
04f7a4b42, on vLLM main8e45c458f. The vLLM Python tree was imported over the compiled extensions of a ROCm build of vLLM0.34.0rc1.dev897.3662841e9, based on ROCm/aiter9569fb31a, with FlyDSL 0.5.0 (the version AITER and vLLM main pin). Between that base and current ROCm/aiter main044e23329,aiter/fused_moe.py, MoE sorting and the shuffle ops are unchanged. The only MoE config changes are fp4-activation (a4w4) rows indsv41_fp4_tuned_fmoe.csvand gfx1250 rows intuned_grouped_fmoe.csv, and the a8w4 path reads neither. So theaiter.fused_moebaseline below is the same as on current AITER main for these shapes.Lint.
pre-commit run --files <the 4 changed files>: all hooks pass, including mypy.New tests (in
tests/kernels/moe/test_rocm_aiter_moe.py, which already runs in the AMD kernels CI step):test_aiter_flydsl_moe_a8w4_off_by_default_and_needs_the_op: the flag is off by default, and with the flag on, an AITER whose op module does not import gives no op, soaiter.fused_moeruns.test_aiter_mxfp4_experts_flydsl_a8w4_matches_fused_moe(9 cases, gfx950, skips without the op) runs real weights through the production conversion (convert_weight_to_mxfp4_moe_kernel_format(AITER_MXFP4_BF16)) and the real op. No stand-ins or mocks.determine_expert_mapgives, bit for bit, exactly when the call should take the op. The cases cover:aiter.fused_moe(flag off), no NaN, and zero rows for tokens with no local expert._assert_deterministic), and a CUDA graph captured after the first eager call replays new inputs to the op's result, bit for bit.On the 0.9998 bound: both paths quantize to MXFP8, and each is at cosine about 0.9988 from an fp32 reference with dequantized weights. They agree with each other to >= 0.99999 from 16 tokens, and to >= 0.99985 below that, where
aiter.fused_moepicks other stage kernels.Whole file, no regressions.
pytest tests/kernels/moe/test_rocm_aiter_moe.py:The 29 failures are the same set on both. They are CK-based tests whose JIT modules cannot build in this AITER source checkout (
ck_tile/core.hppnot found), so they are environment failures, not caused by this change.Call-site performance
AiterMxfp4Experts.applywas timed with the flag off (aiter.fused_moe) and with the flag on, on the same AITER. Method:AiterMxfp4Experts. Each layer is called once eagerly before capture.Noise: rows above a cap run
aiter.fused_moein both columns, and they agree to 0.0-0.4 %. Two back-to-back runs of the EP8 rows agreed to within 1 %. An earlier version of this benchmark reused one layer's weights for every call, which flattered the op by up to about 4 points at 64-192 rows.EP8, as shipped (
_FLYDSL_A8W4_EP8_MAX_TOKENS = {6: 160, 3: 96}):aiter.fused_moe(us)aiter.fused_moe)aiter.fused_moe)The rows at 5-7, 24, 40, 48 and 144 come from two follow-up runs in the same session, on the same code. With CUDA graphs, vLLM pads every DP rank to the same token count, so under DP8 the gathered rows are a multiple of 8. Of the slow window, only 8 rows (one token per rank, decode without speculation) occurs there.
Why the caps exist. These rows were measured with the caps lifted, so the op takes every call. Add
rocm_aiter_moe._FLYDSL_A8W4_EP8_MAX_TOKENS = {6: 1024, 3: 1024}before running the script, or passliftto it:aiter.fused_moe(us)Under DP+EP with the all-gather dispatch, every rank's experts see all gathered rows, but only about 1/8 of the routes are local. The op sizes its sort and blocks by token count, while
aiter.fused_moe's cost follows the local routes. So the op stops winning at 192 rows (top-6) and 128 rows (top-3), and top-6 is a tie at 192. The caps sit at the last measured win.All experts local (no expert mask):
aiter.fused_moe(us)Kernel-level numbers and the roofline are in ROCm/aiter#8381.
Benchmark script (run from the repo root on one gfx950 GPU with ROCm/aiter#8381 installed)
Commands used:
Details
Why this is not a duplicate. Searching vllm-project/vllm PRs for "a8w4 experts flydsl", "moe_a8w4", "AiterMxfp4Experts flydsl" and "DeepSeek-V4.1 MoE flydsl rocm" finds no PR that calls this op. The AITER op itself is new in ROCm/aiter#8381.
Where the call site is.
AiterExperts.applygains a small_fast_path_expertshook, tried for calls with unquantized input. The base class returns None, andAiterMxfp4Expertsoverrides it.rocm_aiter_ops.flydsl_moe_a8w4()holds the flag and the lazy import, following the existing FlyDSL sparse-MLA hook.Graph safety. The gate reads only host metadata: shapes, configs, the flag, the AITER bound and
dbo_enabled(). The decision is therefore fixed per captured token count, and adds no host-device sync.flydsl_moe_a8w4_experts_warmup, which compiles every token tier of the op and takes seconds. It also allocates the layer's ready-counter workspace (112 KB), and under EP its global-to-local id table. vLLM's CUDA-graph warm-up runs an eager pass per batch size before capturing it, so this happens before serving. With--enforce-eager, the first eligible decode step stalls for the compile, and the other DP ranks wait for it at the all-gather.aiter.fused_moe, with a warning. The check comes before any kernel is enqueued.index_select), which is included in the timings above.Concurrency. Each layer passes its own counter workspace (
ready_counters=) to the op, so calls of different layers, including the target and draft models, never share counters. DBO stays excluded, because its two micro-batches can run the same layer at the same time. The op has no collectives, so a per-rank decision cannot desynchronize DP/EP ranks. Under the DP all-gather dispatch, all ranks see the same token count anyway.Not covered:
--moe-backend aiter_mega_moe) is untouched (see [ROCm][Perf][DSv4.1] Run aiter_mega_moe layers on AITER FusedEPMoE for small batches #68998).a1q_scale,expert_tokens_meta) are not handled. If [ROCm] MXFP8 dispatch for AITER MXFP4 MoE under data parallelism #66771 lands, its MXFP8 all-gather only quantizes outside graph capture and above8*256/topktokens, which is beyond the caps here.Why an env flag. The op is not in a released AITER, and DeepSeek-V4.1-Flash end-to-end accuracy and throughput with it are still pending. When AITER ships it and the e2e results confirm it, the flag can become the default for these shapes, or be removed.
Known limitations:
aiter.fused_moe.aiter.fused_moe, which has a fast tuned kernel there. Under DP8 only the 8-row point occurs.vllm bench serveresult yet, flag off vs on with--moe-backend aiter. That run is needed before this leaves draft.Related:
--moe-backend aiter_mega_moesmall batches (the MegaMoE counterpart of this PR).E2E status
End-to-end DSv4.1-Flash DEP8 AgentX results pending. In particular, gsm8k lm_eval and a low-concurrency
vllm bench serverun with--moe-backend aiter, flag off vs on, have not been run yet. They will be added here, with full commands and commit IDs, before review is requested.AI assistance (Claude Code) was used to write this change; Fangzhou Ai is the human owner and will review/defend it end-to-end.
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. (End-to-end serving and accuracy results are pending.)
🤖 Generated with Claude Code