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.
…M1 units GEMM2 of the single kernel was latency bound: each K-tile issued its W2 loads right before its own MFMAs, the base addresses were not uniform (every load sat in a waterfall loop), and every tile waited serially on 4-5 memory round trips before its first weight read. - GEMM2 (BM 64 x 64 columns per wave, static inter_dim): the 9 K-tiles are fully unrolled; the W2 of K-tile kt + 1 is issued per 16-column group right after the MFMAs that free its registers (no extra VGPRs). The load descriptors are made uniform with readfirstlane, so the waterfall loops disappear. The tile issues its metadata and first W2 loads, claims the CTA's next unit, and only then waits for its m-tile's GEMM1 ready signal; GEMM1 output is still read after the signal and an L1 invalidate. The per-accumulator MFMA order is unchanged, so the output is bit-identical. - GEMM1: buckets >= 256 tokens per rank use tile_n 256, so an m-tile takes 18 work units instead of 36. The XCD slice ends move to groups of 512 // tile_n n-tiles, which still keeps every 256-byte scale block written by one XCD. Captured DeepSeek-V4.1-Flash decode routing, 384 tokens/rank, 8x MI355X: 372.3 -> 349.1 us (-5.5%); the per-m-tile cost goes from ~3.27 to ~2.56 us. The output is bit-identical to the previous kernel on uniform, zipf and real routing. Cost: 28 VGPR and 16 SGPR spills, all in the per-tile pre/post processing (none in the K-loop).
…combine reduction Found with GEAK's e2e_workflow (profile -> kernel_workflow) on the DeepSeek-V4.1-Flash DP8+EP8 DSpark decode, where the single kernel was ~47% of the step. - Lower fixed cost per m-tile (~2.56 -> ~2.2 us): - GEMM1's prologue does a single memory round trip; - LDS addresses use an opaque 0 so the compiler does not hoist their computation; - the TILE_ROWS base lives in SGPRs; - the requantizing epilogue handles 8 columns at a time with 8-byte stores; - the GEMM2 scatter decodes routes with readlane. - Light W1 warm-up while waiting for the plan. Heavier W1 / W2 prefetch competes with the P2P payload writes and is slower. - Merged FP8 combine reduction: the loads of all 6 slots are issued before their first use, with 512 reducing threads, and fewer sync / flag round trips (combine 16.7 -> 7.5 us). Captured decode routing (40 layers), 384 tokens/rank, 8x MI355X: 351.7 -> 319.0 us per call (1.103x). Max difference against frozen golden outputs (real routing, uniform, zipf 1.0) is 0, repeated runs are bit-identical, and 21 extra random configurations are bit-identical too.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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.
🔵 Needs a closer look
Scheduler-sensitive EP8 spin waits and pipelining require correctness, graph-replay, whole-grid residency, and paired-performance validation on 8× gfx950 with pinned FlyDSL 0.5.0, since reported testing used only 0.4.2.
No open issues 🎉
What changed in this PR
This stacked PR optimizes MegaMoE’s small-input FlyDSL kernel for DeepSeek decode workloads on gfx950. Building on #8358’s expanded layout support, it targets lower latency while aiming to preserve bit-identical outputs.
Changes:
- Pipelines GEMM2 weight loads and overlaps tile setup with the GEMM1 completion wait.
- Uses wider GEMM1 tiles for larger token buckets and reduces per-tile setup and output-store overhead.
- Issues mixed FP8/BF16 combine loads earlier and increases combine participation to 512 workgroups.
| File | Description |
|---|---|
aiter/ops/flydsl/kernels/mega_moe/mega_moe_v2.py |
Carries #8358’s eligibility expansion for V4.1-Flash and additional expert/top-k layouts. |
aiter/ops/flydsl/kernels/mega_moe/mega_moe_small_m.py |
Optimizes GEMM1, GEMM2 scheduling, scatter, and combine within the single kernel. |
aiter/ops/flydsl/kernels/mega_moe/mega_moe_fused_gemm.py |
Adds optional GEMM2 weight prefetching and a pre-loop callback, retaining existing defaults. |
Review effort: Balanced
Summary
Two performance changes to the MegaMoE small-M single kernel (
mega_moe_small_m.py, plus GEMM2 support inmega_moe_fused_gemm.py). Neither changes the numerics: the output is bit-identical to the previous kernel.Motivation
On DeepSeek-V4.1-Flash DP8+EP8 DSpark decode (8x MI355X), the single kernel is ~47% of every decode step even after #8358. A profile shows it is latency bound rather than compute bound:
Changes
[FlyDSL] [Perf] MegaMoE small-M: pipelined GEMM2 tile, tile_n 256 GEMM1 unitsgemm2_compute_v2(b_prefetch=True)). No extra VGPRs are needed.readfirstlane, so the waterfall loops disappear.pre_loop). GEMM1 output is still read only after that signal and an L1 invalidate.tile_n=256, so each m-tile is 18 work units instead of 36. XCD slice ends now fall on groups of512 // tile_nn-tiles, which still keeps each 256-byte scale block written by a single XCD.[FlyDSL] [Perf] MegaMoE small-M: cut per-m-tile overhead, merged FP8 combine reduction(found with GEAK's e2e_workflow)TILE_ROWSbase is held in SGPRs;readlane.Performance (if applicable)
Single-kernel time on 8x MI355X with CUDA-graph timing. "Real routing" is decode routing captured from a vLLM DeepSeek-V4.1-Flash server; the main model runs 384 tokens/rank and the DSpark draft 320 tokens/rank.
The per-m-tile cost (linear fit over uniform, zipf 0.6, zipf 1.0 and real routing) drops from ~3.27 us before change 1, to ~2.56 us after change 1, to ~2.2 us after change 2.
End to end (vLLM DP8+EP8 DeepSeek-V4.1-Flash, DSpark nst5, 512 concurrent requests, 8K output, pure-decode ITL, on top of #8358 and other vLLM-side optimizations):
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 --time-bs 56,448(V4-Pro shape, unchanged test), and the same test with the network overridden to the V4.1-Flash shapes 384 / top-6, 392 / top-7 and 128 / top-3:[RESULT] ALL PASSfor all four. This covers accuracy against 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.Single-kernel time from the same test, before ([FlyDSL] MegaMoE small-M: DeepSeek-V4.1-Flash, any experts per rank / top-k, fused shared-expert slots #8358 head) -> after (this PR), median of 15, max over ranks, uniform routing. Each "before" and "after" value comes from a separate run:
At 448 tokens/rank every shape is faster (-4% to -10%). At 56 tokens/rank, V4.1-Flash is 1-2% slower; this has not yet been separated from run-to-run noise.
Bit-exactness:
Documentation
Dependencies
Breaking Changes
None. The output is bit-identical, and the API is unchanged (
gemm2_compute_v2gains the optionalb_prefetch/pre_looparguments, which default to the old behavior).PR Self-Review
Reviewed revision
65b7ff0
Behavior and intent
The changes are performance only: the single kernel produces the same output with lower latency.
Validation and unverified scope
vllm/vllm-openai-rocm:nightly9bc16ae6 image); not yet run against the FlyDSL 0.5.0 pin onmain.mega_moe_small_m.pywas reordered byruff --fix(one unused import removed); the rest of the module is unchanged at the AST level.PR-specific question
Changed op tests
None.