Repository navigation
Conversation
- small_m_eligible: accept model_dim 5120 / inter_dim 2304 besides 7168 / 3072. - small_m_config: buckets <= 8 tokens pick tile_n 256, which gives V4.1-Flash 18 GEMM1 n-tiles; the XCD split needs a multiple of 4, so fall back to tile_n 128 (36 n-tiles, as every larger bucket already uses). V4.1-Flash uses the default small-input config unchanged; checked against an FP32 reference and against the main path on 8x MI355X.
…d-expert slots The single kernel hard-coded 48 experts per rank (EP8 x 384) and top-6. Only _use_direct_fixed_slot really depended on it; the plan scan, route encoding, combine buffers and loops, LDS / dispatch-table sizing, config selection and the 32-bit buffer offsets are already generic. - small_m_eligible / _use_direct_fixed_slot: 1..64 experts per rank (the plan scans one wave lane per local expert) and top-1..8. - SmallMRuntime(shared_experts=N): the last N local slots of every rank hold fused shared experts (vLLM's fuse_shared_expert layout: every token adds a weight-1 route to its own rank's slot). Those slots hold every local token, so the plan keeps them out of the hot-expert test and the FP8-row decision (otherwise every call would switch the rank to FP8 combine rows); they still count toward the cached-weight decision. - The cached-weight row threshold scales with the routed experts of the rank (_CACHED_W_MIN_ROWS is per 48 routed experts). Now the DSpark draft MoE (128 experts / top-3) and the fused-shared-expert layout of DeepSeek-V4.1-Flash (392 / top-7) run on the single kernel. The 384 / top-6 path is unchanged.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
|
Follow-up performance changes stacked on this PR: #8360. |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
MegaMoEV2 does not forward shared-expert counts, allowing shared slots to incorrectly trigger FP8 combine rows, and existing tests do not cover fused-shared routing or the precision-preserving exclusion.
2 open issues
What changed in this PR
Expands MegaMoE’s single-kernel small-input path to DeepSeek-V4.1-Flash and additional expert layouts, reducing reliance on the multi-kernel fallback.
Changes:
- Admits Flash dimensions, 1–64 experts per rank, and top-1–8 routing.
- Adds shared-expert metadata to
SmallMRuntimeand separates shared rows from FP8-selection decisions. - Adjusts small-token tiling and scales the cached-weight threshold by routed expert count.
| File | Description |
|---|---|
aiter/ops/flydsl/kernels/mega_moe/mega_moe_v2.py |
Broadens small-input eligibility to additional model and routing layouts. |
aiter/ops/flydsl/kernels/mega_moe/mega_moe_small_m.py |
Adds shared-slot handling, generalizes expert counts, and adjusts tiling and cache thresholds. |
Review effort: Balanced
| if const_expr(fz_routed_epr < fz_epr): | ||
| routed_count = (lane < fx.Int32(fz_routed_epr)).select(safe_count, fx.Int32(0)) | ||
| routed_rows = fx.Int32( | ||
| fx.rocdl.readlane(T.i32, _wave_inclusive_scan_i32(routed_count, lane), fz_epr - 1) |
| and experts % world_size == 0 | ||
| and 1 <= experts // world_size <= 64 | ||
| and 1 <= topk <= 8 |

Summary
Opens the MegaMoE small-M single kernel (
SmallMRuntime/forward_small_m) to DeepSeek-V4.1-Flash and to any expert layout with 1..64 experts per rank and top-1..8, and lets it run vLLM's fused-shared-expert layout (the shared expert as an extra local expert slot on every rank).Motivation
The single kernel (quant + dispatch + GEMM1 + GEMM2 + combine in one launch) only accepted DeepSeek-V4-Pro's routed MoE: 7168 / 3072, 384 experts (48 per rank on EP8), top-6. Everything else falls back to the multi-kernel MegaMoEV2 path, including:
Changes
[FlyDSL] MegaMoE small-M: admit DeepSeek-V4.1-Flash (5120 / 2304)small_m_eligibleaccepts 5120 / 2304 besides 7168 / 3072.small_m_config: buckets <= 8 tokens picktile_n=256, which gives V4.1-Flash 18 GEMM1 n-tiles and trips the XCD split (N_TILES % 4 == 0); fall back totile_n=128(36 n-tiles, as every larger bucket already uses).[FlyDSL] MegaMoE small-M: any experts per rank, top-1..8, fused shared-expert slots_use_direct_fixed_slotreally required 48 experts per rank; the plan scan, route encoding, combine buffers/loops, LDS and dispatch-table sizing, config selection and 32-bit buffer offsets are already generic. It now accepts 1..64 experts per rank (the plan scans one wave lane per local expert);small_m_eligibleaccepts top-1..8.SmallMRuntime(..., shared_experts=N)(default 0): the last N local slots of every rank are fused shared experts. They receive every local token, so the plan keeps them out of the hot-expert test and the FP8-row decision; otherwise every call switches the rank to FP8 combine rows (FP32-reference error 0.0025 -> 0.0265). They still count toward the cached-weight decision._CACHED_W_MIN_ROWSis defined for 48).The 384 / top-6 code path and its numerics are unchanged. Only
aiter/ops/flydsl/kernels/mega_moe/{mega_moe_small_m.py,mega_moe_v2.py}change.Performance (if applicable)
8x MI355X (gfx950, 256 CU), EP8, MXFP4 weights / MXFP8 activations, CUDA-graph timing. "Real routing" is decode routing captured from a vLLM DeepSeek-V4.1-Flash server (1K input, 64 requests per rank, DSpark nst5).
End to end (vLLM DP8+EP8 DeepSeek-V4.1-Flash, DSpark nst5, 512 concurrent requests, 1K / 100K input, 8K output, pure-decode ITL):
Testing
Tested on 8x MI355X (gfx950):
AITER_MEGA_SMALL_M=1 torchrun --nproc-per-node 8 op_tests/multigpu_tests/test_mega_moe_small_m.py(V4-Pro shape, unchanged test):[RESULT] ALL PASS, which covers accuracy vs the FP32 reference and the main path on uneven, idle and padded ranks; edge cases; 600-step weight rebinding; epoch wrap; and CUDA graph replay.shared_experts=0):[RESULT] ALL PASSfor each. Relative L2 error is 0.052 vs the FP32 reference and 0.027 vs the main path, about the same as V4-Pro's 0.053 / 0.027. Paired timing in the same test, main path -> single kernel (bs/rank 56 and 448): 384 / top-6 309.7 -> 177.5 us and 457.5 -> 310.7 us; 392 / top-7 334.6 -> 185.7 us and 516.9 -> 367.7 us; 128 / top-3 199.4 -> 94.6 us and 298.2 -> 178.8 us.Documentation
Dependencies
Breaking Changes
None.
SmallMRuntime(shared_experts=0)is the default, and layouts that were eligible before keep the same path and results.PR Self-Review
Reviewed revision
621952b
Behavior and intent
More layouts now run on the small-M single kernel: V4.1-Flash, 1..64 experts per rank, top-1..8, and fused shared-expert slots. Before this change they all fell back to the multi-kernel path.
Validation and unverified scope
vllm/vllm-openai-rocm:nightly9bc16ae6). The two changed files onmainare byte-identical to 0.1.29, but this branch has not yet been run against the FlyDSL 0.5.0 pin onmain.op_tests/multigpu_tests/test_mega_moe_small_m.pystill tests only the V4-Pro network. The V4.1-Flash, fused-shared and draft layouts andshared_experts> 0 are not in the op test yet.PR-specific question
Changed op tests
None.