Skip to content

[FlyDSL] MegaMoE small-M: DeepSeek-V4.1-Flash, any experts per rank / top-k, fused shared-expert slots - #8358

Open
zovonoir wants to merge 2 commits into
ROCm:mainfrom
zovonoir:mega-moe-small-m-any-experts-shared-slot
Open

zovonoir wants to merge 2 commits into
ROCm:mainfrom
zovonoir:mega-moe-small-m-any-experts-shared-slot

Conversation

@zovonoir

Copy link
Copy Markdown
Contributor

Draft: opened early to track the work; more validation and op-test coverage will follow.

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:

  • DeepSeek-V4.1-Flash (5120 / 2304, 384 / top-6);
  • its fused-shared-expert layout (392 experts / top-7: 48 routed + 1 shared slot per rank);
  • the DSpark draft MoE (128 experts / top-3, 16 per rank).

Changes

  1. [FlyDSL] MegaMoE small-M: admit DeepSeek-V4.1-Flash (5120 / 2304)
    • small_m_eligible accepts 5120 / 2304 besides 7168 / 3072.
    • small_m_config: buckets <= 8 tokens pick tile_n=256, which gives V4.1-Flash 18 GEMM1 n-tiles and trips the XCD split (N_TILES % 4 == 0); fall back to tile_n=128 (36 n-tiles, as every larger bucket already uses).
  2. [FlyDSL] MegaMoE small-M: any experts per rank, top-1..8, fused shared-expert slots
    • Only _use_direct_fixed_slot really 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_eligible accepts top-1..8.
    • New 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.
    • The cached-weight row threshold scales with the number of routed experts per rank (_CACHED_W_MIN_ROWS is 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).

Hardware Workload/configuration Before (multi-kernel MegaMoEV2) After (single kernel) Change
8x MI355X V4.1-Flash fused shared expert, 392 experts / top-7, 384 tokens/rank, real routing 557.5 us 386.5 us -30.7%
8x MI355X V4.1-Flash DSpark draft MoE, 128 experts / top-3, 320 tokens/rank, real routing 379.4 us 228.9 us -39.7%
8x MI355X V4.1-Flash routed MoE, 384 experts / top-6, 384 tokens/rank, uniform routing 447 us 282 us -36.9%

End to end (vLLM DP8+EP8 DeepSeek-V4.1-Flash, DSpark nst5, 512 concurrent requests, 1K / 100K input, 8K output, pure-decode ITL):

  • Change 1 alone: ITL 38.92 -> 33.67 ms (1K input), 40.35 -> 35.05 ms (100K input); gsm8k 0.907 -> 0.909.
  • Change 2 (the draft MoE moves to the single kernel), measured on top of other vLLM-side optimizations: ITL 32.44 -> 31.87 ms (1K), 33.79 -> 33.31 ms (100K).

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

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.
  • The same test with the network overridden to the V4.1-Flash shapes 384 / top-6, 392 / top-7 and 128 / top-3 (shared_experts=0): [RESULT] ALL PASS for 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.
  • A separate 8-GPU benchmark on captured decode routing: on the 384 / top-6 shape, change 2 is bit-identical to change 1 alone on uniform, zipf and real routing. The 392 / top-7 and 128 / top-3 shapes have an FP32-reference error of 0.0025, the same as 384 / top-6. Repeated runs are bit-identical.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

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

  • Validated with FlyDSL 0.4.2 (the version that amd-aiter 0.1.29 ships, in vllm/vllm-openai-rocm:nightly 9bc16ae6). The two changed files on main are byte-identical to 0.1.29, but this branch has not yet been run against the FlyDSL 0.5.0 pin on main.
  • op_tests/multigpu_tests/test_mega_moe_small_m.py still tests only the V4-Pro network. The V4.1-Flash, fused-shared and draft layouts and shared_experts > 0 are not in the op test yet.
  • Not tested: V4-Pro end to end with these changes; MI300-class GPUs (the small-M path requires 8-XCD gfx950).

PR-specific question

Changed op tests

None.

- 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.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8358 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@zovonoir

Copy link
Copy Markdown
Contributor Author

Follow-up performance changes stacked on this PR: #8360.

@zovonoir
zovonoir marked this pull request as ready for review November 20, 2026 07:01
@zovonoir
zovonoir requested review from a team and a balanced review from Copilot November 20, 2026 07:01
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 621952b1f1b6 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — PR-specific question has no substantive answer

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 SmallMRuntime and 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

Comment on lines +387 to +390
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)
Comment on lines +110 to +112
and experts % world_size == 0
and 1 <= experts // world_size <= 64
and 1 <= topk <= 8

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants