Skip to content

[FlyDSL] [Perf] Extend MegaMoE internode to EP32 A8W4 and tune the single-kernel pipeline - #8082

Merged
coderfeli merged 7 commits into
mainfrom
dev/megamoe-Internode-single-kernel-tune
Nov 25, 2026
Merged

coderfeli merged 7 commits into
mainfrom
dev/megamoe-Internode-single-kernel-tune

Conversation

@james-huang09

@james-huang09 james-huang09 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Extend MegaMoE internode to physical four-node EP32 and improve the A8W4 dispatch, GEMM, and combine pipeline on MI355X. The operator can run Stage1 and Stage2 in one persistent kernel, overlap GEMM2 activation DMA with weight and scale preloads. The host interface now validates its inputs up front, reads the caller's weights in place, and sizes its receive storage from an explicit limit or the full routing bound.

Motivation

Small-token expert-parallel workloads spend a substantial part of their latency on communication, readiness polling, and the transition between GEMM stages. The Stage1/Stage2 handoff reloads generation state and repeatedly invalidates cache lines. This change reduces that work while retaining per-group readiness and parity-slot protection.

Changes

Pipeline:

  • Extend dispatch, receive metadata, source planes, remote partials, and return credits to four nodes. Separate local payload buffers from bounded NIC windows and pass their bindings through a device table. Retain receive-capacity and coordinated overflow handling.
  • Enable the single-kernel path when Stage1 and Stage2 use compatible eight-wave CTAs. Pass generation and EOS state through the Stage1/Stage2 handoff, invalidate L1 at consumers, and invalidate L2 once per XCD using a generation marker at the handoff. The two-kernel path remains selectable.
  • Stream the first M16 fragments and retain the final pair for reuse; defer B-scale shifts to their consuming K step to preserve weight-prefetch overlap.
  • Add a staged GEMM2 core with activation DMA and weight/scale preloads. Keep the existing GEMM2 implementation for other configurations and include pipeline choices in kernel specialization names.
  • Limit node-reduce/rail/combine workers to 96 CTAs. Rotate remote send/receive order, separate Stage1 sealing from credit return, and use poll backoff for the single-kernel handoff and group-ready waits.
  • Defer Stage2 consumption credits and check generation g-2 before reusing the same parity slot.
  • Add A8W4/A4W4 tuning rows keyed by quantization and topology (EP16 and EP32). For example, EP32 K3 TPR 128 uses Stage1 G3, fanout 12, GEMM2 BM32, and xGMI. Preserve transport gates and disjoint Stage2 scratch spans for SDMA.
  • Include the K3 A8W4 GEMM configuration, masked-EP support, address handling, and tuning/test integration required by the branch.

Performance

Hardware: MI355X (gfx950), two physical nodes with eight GPUs each (EP16). Workload: Kimi K3, hidden 3584, intermediate 3072, 896 experts, TopK 16, A8W4, SiTUv2 (beta=4, linear_beta=25), seed 781.

The table reports complete-forward GPU Event latency, including input quantization, dispatch, expert MLP, and combine. After 10 warmup replays, 40 timed replays are recorded. For each rank, take the minimum of its 40 samples, then average those minima across the 16 ranks: mean(rank min). Values are in microseconds.

EP16 (2 nodes) — K3

tpr quanttype mega smallop (mori) speedup
32 a8w4 265.4 270.3 (v2_ll) 1.02x
64 a8w4 278.1 292.3 (v2_ll) 1.05x
128 a8w4 331.4 376.7 (v2_ll) 1.14x
256 a8w4 432.1 742.5 (v2_ll) 1.72x
512 a8w4 671.4 1340.6 (v2_ll) 2.00x
1024 a8w4 1097.3 2158.0 (v2_ll) 1.97x
2048 a8w4 1879.1 4620.9 (v2_ll) 2.46x
4096 a8w4 3507.2 8225.9 (v2_ll) 2.35x
8192 a8w4 6997.2 15867.2 (v2_ll) 2.27x
16384 a8w4 13594.9 37346.3 (v2_ll) 2.75x
32 a4w4 248.7 372.8 (v1_ll) 1.50x
64 a4w4 255.8 415.2 (v1_ll) 1.62x
128 a4w4 291.9 516.1 (v1_ll) 1.77x
256 a4w4 376.7 702.1 (v1_ll) 1.86x
512 a4w4 581.3 1130.4 (v1_ll) 1.94x
1024 a4w4 920.6 1931.6 (v1_ll) 2.10x
2048 a4w4 1577.6 3595.9 (v1_ll) 2.28x
4096 a4w4 2620.5 7146.2 (v1_ll) 2.73x
8192 a4w4 5180.6 14584.4 (v1_ll) 2.82x
16384 a4w4 9756.6 29302.7 (v1_ll) 3.00x

EP16 (2 nodes) — dsv4.1

tpr quanttype mega smallop (mori) speedup
32 a8w4 167.6 195.5 (v2_ll) 1.17x
64 a8w4 178.0 218.5 (v2_ll) 1.23x
128 a8w4 201.1 302.1 (v2_ll) 1.50x
256 a8w4 265.7 398.6 (v2_ll) 1.50x
512 a8w4 404.7 587.6 (v2_ll) 1.45x
1024 a8w4 553.4 1001.1 (v2_ll) 1.81x
2048 a8w4 1121.5 1733.5 (v2_ll) 1.55x
4096 a8w4 1797.8 3353.9 (v2_ll) 1.87x
8192 a8w4 3247.0 6638.3 (v2_ll) 2.04x
16384 a8w4 6127.3 13349.1 (v2_ll) 2.18x
32 a4w4 163.5 246.5 (v1_ll) 1.51x
64 a4w4 171.1 323.8 (v1_ll) 1.89x
128 a4w4 188.2 396.0 (v1_ll) 2.10x
256 a4w4 235.1 464.6 (v1_ll) 1.98x
512 a4w4 341.1 635.8 (v1_ll) 1.86x
1024 a4w4 461.1 1093.8 (v1_ll) 2.37x
2048 a4w4 933.6 2049.8 (v1_ll) 2.20x
4096 a4w4 1501.4 4003.8 (v1_ll) 2.67x
8192 a4w4 2483.2 7473.4 (v1_ll) 3.01x
16384 a4w4 4771.4 15165.3 (v1_ll) 3.18x

EP32 (4 nodes) — K3

tpr quanttype mega smallop (mori) speedup
64 a8w4 256.4 275.0 (v2_ll) 1.07x
128 a8w4 302.3 347.0 (v2_ll) 1.15x
256 a8w4 463.9 520.4 (v2_ll) 1.12x
512 a8w4 770.1 1490.6 (v2_ll) 1.94x
1024 a8w4 1249.8 2751.4 (v2_ll) 2.20x

These results use the submitted EP16 A8W4 tuning CSV. All buckets use the single-kernel path; intra-node transport is xGMI through TPR 1024 and SDMA from TPR 2048. The sweep covers 20 cases (10 token counts × random/EPLB), with all 320 aggregate checks passing.

MegaMoE validation:

Entry: op_tests/multigpu_tests/test_megamoe_internode.py, launched with torchrun on two (EP16) or four (EP32) physical MI355X (gfx950) nodes, eight workers per node.

Routing: all numbers below use the eplb fixture: deterministic routing where every rank receives the same number of routes (TPR × TopK) and every local expert the same load. The test's default is --fixtures eplb,random, so pass --fixtures eplb explicitly to reproduce the tables. This PR targets balanced routing; the random fixture (rank-balanced, one hot expert per rank) was spot-checked at EP16 K3 A8W4 TPR 128 (MegaMoE 366 µs vs small-op 400 µs, accuracy passed). Skewed-load fixtures (hot-rank0, zipf-*, rank-mixed-skew, permuted) are not tuned in this PR.

Command (per node; $NN = 2 or 4):

torchrun --nnodes $NN --nproc_per_node 8 --node_rank $NODE --master_addr $MASTER --master_port $PORT \
  op_tests/multigpu_tests/test_megamoe_internode.py \
  --network kimi_k3 --fused-quant a8w4 --smallop-quant a8w4 --mori-kernel v2_ll \
  --fmoe-csv aiter/configs/model_configs/kimik3_a8w4_tuned_fmoe.csv \
  --paths fused,smallop --check --fixtures eplb --tpr-list 128 \
  --comm-quant fp8 --mori-num-qp 8 --situ-beta 4 --situ-linear-beta 25 \
  --seed 781 --warmup 10 --iters 40 --timing total --allow-tune-miss

@james-huang09
james-huang09 requested a review from a team November 17, 2026 05:55
@james-huang09
james-huang09 marked this pull request as draft November 17, 2026 05:56
@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 8082 --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.

@github-actions github-actions Bot changed the title [FlyDSL] [Perf] Extend MegaMoE internode to EP32 A8W4 and tune the single-kernel pipeline [CK] [FlyDSL] [Perf] Extend MegaMoE internode to EP32 A8W4 and tune the single-kernel pipeline Nov 17, 2026
@aiter-bot

aiter-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision bd6bdd1b4a52 · 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. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/multigpu_tests/test_megamoe_internode.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

@james-huang09
james-huang09 force-pushed the dev/megamoe-Internode-single-kernel-tune branch 6 times, most recently from 2e7bdf2 to 85db65e Compare November 20, 2026 04:49
@james-huang09
james-huang09 marked this pull request as ready for review November 22, 2026 17:41
@github-actions github-actions Bot changed the title [CK] [FlyDSL] [Perf] Extend MegaMoE internode to EP32 A8W4 and tune the single-kernel pipeline [FlyDSL] [Perf] Extend MegaMoE internode to EP32 A8W4 and tune the single-kernel pipeline Nov 22, 2026
@github-actions github-actions Bot removed the CK label Nov 22, 2026
@zufayu
zufayu requested a review from GwilliamHu November 23, 2026 10:20
@zufayu zufayu assigned GwilliamHu and unassigned yadaish Nov 23, 2026
james-huang09 and others added 5 commits November 25, 2026 11:17
Extend MegaMoE dispatch, reduction and return credits to four logical nodes
using separate local and bounded rail windows. Support virtual 4x4 through
CROSSNODE/WORLD peers, and bind separate-window SDMA to the local DevComm.
Size inverse maps, counters and scratch spans from the actual topology;
keep RAIL requests disjoint from the SDMA signal epoch.

Include AITER PR #7542 K3 A8W4 tuning and masked EP changes. Restore the
historical Stage1 BM128 M16 schedule after the M32 addition did not show
an overall gain. Retain historical epilogue/quant and Stage2 M16 changes,
EP32 input addressing, and version the restored Stage1 cache identity.

Document physical 4x8 and virtual 4x4 launch configurations and the MORI
b80cbe4 dependency patch. The M32 version plus the scratch fix completed
the physical EP32 K3 numerical sweep; its TPR4096 timing anomaly remains
unresolved. The restored M16 schedule has not been rerun on EP32.

Validation: full base-diff Black 26.10.1, repository Ruff 0.16.0,
Python/shell parsing, whitespace and CK dependency checks, and pytest
8.3.4 CPU pre-checks (117 passed). Nine single-GPU M16 cases match the
historical payload and scales byte for byte. Physical EP16 M16 passed
20 K3 cases plus three targeted repeats: 368 fused and 161 independent
Small-op checks, with the existing 0.05 relL2 threshold.
Support BM96 GEMM1 tile groups and overlap GEMM2 activation DMA with staged weight and scale preloads. Pass the generation through the single-kernel handoff, invalidate L2 once per XCD, and limit node-reduce workers. Separate Stage1 sealing from credit returns and defer Stage2 credits until parity-slot reuse. Select the pipeline and communication geometry through scoped A8W4 tuning rows.

Signed-off-by: james-huang09 <[email protected]>
Move per-GPU GMM1 intermediates into private device storage, align local
CCO allocations for pooled communicators, and support stock MORI window
registration while retaining compatibility with the optional local-only API.

Extend the unrolled GEMM2 pipeline to FP4, select remote fan-out by arrival,
and allow GMM1-skipping CTAs to prepare the SDMA plan. Make quantization and
topology explicit in tuning and respect the selected split-local setting.

Key experimental modes in the compile caches, validate their parameters,
and adapt the existing buffer-address probe for private storage.
Improve dispatch/GEMM1 and GEMM2/reduce/combine scheduling with relaxed
handoff, early SDMA planning and parallel/deferred credit exchange. Keep
GMM1 intermediates in private device storage and use stock MORI window
registration for communication buffers.

Consolidate device helpers and select tile geometry, fanout, local
splitting, communication paths and return chunks through the EP16
A4W4/A8W4 and EP32 A8W4 tuning table.

Extend the existing internode test with real EP16/EP32 launch support,
MORI V2LL reference and small-op paths, replay correctness checks, and
global minimum and mean-of-rank-means over the last 20 timed replays.

Signed-off-by: james-huang09 <[email protected]>
Reuse existing GEMM, scale, address and synchronization helpers and remove
unreachable Stage1 and Stage2 paths. Preserve the active pipeline while
simplifying tile sealing, credit handling and SDMA token-ready reduction.

Size receive storage from the explicit receive-route limit or the full
routing bound. Select bounded rail windows and an owned local communicator
above TPR 1024, including cleanup and xGMI fallback when SDMA is unavailable.

Validate architecture, weight storage, routing tensors, activation options
and launch devices before execution, including FlyDSL-wrapped streams.
Update the existing internode test to size its CCO pool for the new capacity
rules and use multiple windows for larger token capacities.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: james-huang09 <[email protected]>
Prepare the A8W4 small-op gate/up W1 layout from the same quantized
weights used by MegaMoE internode and reuse its A16W4 W2 layout.
Keep the extra W1 tensors optional and create them only for the A8W4
small-op path, removing the test_wide_ep_moe weight helper dependency.
Remove the optional two-launch host branch and its environment switch.
Keep group-ready enabled and reserve independent Stage1 and Stage2 QP
contexts using the existing single-kernel configuration.

Drop stale timing and profiling results from comments while retaining
the technical rationale, and clarify the standalone Stage2 helper docs.
@james-huang09
james-huang09 force-pushed the dev/megamoe-Internode-single-kernel-tune branch from 4254ff0 to bd6bdd1 Compare November 25, 2026 03:22
@coderfeli
coderfeli merged commit 7f1f7d1 into main Nov 25, 2026
60 checks passed
@coderfeli
coderfeli deleted the dev/megamoe-Internode-single-kernel-tune branch November 25, 2026 09:30
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