MegaMoEV1 on Gfx950#876
Open
GwilliamHu wants to merge 9 commits into
Open
Conversation
Rebased onto latest main as a single commit: - MegaMoE fused stage1/stage2 + dispatch/combine, packaged as kernels/moe/mega_moe - merge-import fixes (kernels.common.mma, gemm_common_utils) - fix MEGA_TUNING_DIR after packaging (parent.parent.parent) so autotune finds kernels/comm/mega_moe_tuning_config (restores tuned tile_m; ~12% small-batch perf) Co-authored-by: Cursor <cursoragent@cursor.com>
…onstant bad_cast)
…or op, merge combine paths
…comm), update imports + docs
…m2 + mega + comm + profiler)
Formatting-only; fixes the Run ./.github/scripts/check_python_style.sh CI gate (black --check). No functional change.
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.
Motivation
This PR adds MegaMoEV1, a single end-to-end intra-node EP-MoE operator (MegaMoE.forward(x_bf16, wts,
topk_ids) -> bf16) that folds the entire layer — quant → fused stage-1 (dispatch ⊕ group-GEMM1) →
fused stage-2 (GEMM2 ⊕ combine-scatter) → bf16.
Technical Details
New package kernels/mega_moe/. mega_moe.py::MegaMoE drives both stages, each with a non-fused
fallback (enable_fused_stage1/2); stage-1→stage-2 handoff is the stable Stage1Output buffer set;
Fused stage-1 —
P2P writes straight into the GEMM's expert-major layout), fixed-slot
dispatch removes the whole moe_sorting kernel; raw_a_scale folded into the K-loop removes the
scale-sort kernel; expert-major layout removes GEMM gather; A compact
scheme auto-switches from fixedslot by buffer size.
Fused stage-2 —
GEMM2 and the EP combine are fused: Rewrites the GEMM2 epilogue's
local store into a remote P2P buffer_store, inlining the combine Stage-1 per-token scatter
directly into GEMM2's CShuffle epilogue (4 extra i64 peer-buffer addrs on the launcher).
Test Plan
(gfx950): full end-to-end MegaMoE.forward (stage-1 + stage-2) accuracy + CUDAGraph device-time
perf, plus stage-1-only mode, across 3 networks (v4_flash 4096/2048/256, r1_v3 7168/2048/256,
v4_pro 7168/3072/384) × 15 batch sizes (1…32768) × a8w4 / a4w4, vs the unfused ops(dispatch → moe_sorting → scale_sort → GEMM1 → GEMM2->combine).
tests/kernels/mega_moe_perf_baseline.json (golden forward() CUDAGraph latency; passes if measured
≤ golden × 1.05).
Test Result
fused-stage-2 a2 buffer exceeds the 32-bit num_records cap.)
across seeds/bs; relL2(mega, f16) = 0.027 (fp8) / 0.143 (fp4).
Submission Checklist