Skip to content

[FlyDSL] [MoE] [gfx1250] give each MX combine chunk its own scale line - #7501

Merged
coderfeli merged 1 commit into
mainfrom
wjx/mega-moe-combine-scale-line
Nov 9, 2026
Merged

coderfeli merged 1 commit into
mainfrom
wjx/mega-moe-combine-scale-line

Conversation

@lalala-sh

@lalala-sh lalala-sh commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lay out the MegaMoE gfx1250 fused-combine MX wire per 256-feature chunk, each chunk's payload followed by one 128 B line holding its e8m0 scales, so every gemm2 scatter write and every reduce load covers whole cache lines. Results are bit-identical; per-layer time drops on every token count measured.

Motivation

The fused scatter combine wrote each token's MX slot as two planes: the fp8/fp4 payload, then hidden/32 e8m0 bytes. Each gemm2 tile row therefore went to its peer as a payload store plus an 8 B scale store landing in the middle of a cache line. A partial-line remote write over xGMI costs far more than its bytes. On 4 x gfx1250 at 1024 tokens/rank (mxfp8), gemm2 took 93 us with the scatter, 74 us with only the scale stores dropped (wrong results, timing only) and 61 us writing locally. Folding the scales into the payload store as unaligned 272 B chunks made it worse (106 us), so the cost is the partial lines, not the store count. With whole-line chunks gemm2 takes 81 us.

Changes

  • mega_moe_gfx1250/types.py: the wire layout is defined once (COMBINE_CHUNK = 256, COMBINE_SCALE_LINE = 128, combine_chunk_bytes()), shared by the writer and the reader.
  • mxfp4_preshuffle_gfx1250_tdm.py (gemm2 epilogue, ep_quant_bits path only): a tile row is staged in LDS exactly as it goes on the wire, scale lines included, and scattered in one gather-store. The separate scale-plane LDS region and its second gather-store are removed. Quantized combine now also requires each warp's columns to sit inside one 256-column chunk (checked with the existing tile_n % 256 validation).
  • mega_moe_gfx1250/combine.py (reduce): one TDM load per trip instead of two; each scale is read right behind its chunk's payload. The scale-plane load, its LDS region and the per-wire WAIT_N are removed.
  • mega_moe_gfx1250/recipe.py: combine_wire_nbytes() follows the new layout. At hidden 7168 the mxfp8 slot grows 7392 -> 10752 B (stride 8192 -> 16384) and the mxfp4 slot 3808 -> 7168 B (stride 4096 -> 8192). The arena is already cut to the bf16 pitch, so its size does not change.
  • stages/combine_fused.py: comments only. The MX reduce tile ceilings stay at T=8, C=4; the bf16 ceiling (T=16, C=1) makes the MX reduce 4-14% slower.

Net -59 lines. The bf16 wire, the mori combine and the non-EP gemm paths are untouched.

Performance (if applicable)

Per-layer us from op_tests/multigpu_tests/bench_mega_moe.py -e 256 -k 8 -hd 7168 -id 2048 -tpr <T> --layers 12 --warmup 10 --iters 30 -q a4w4_mxfp4 --combine_quant <wire> --stage1_fused true --stage2_fused true, main = 790fae1, FlyDSL 0.4.2.

Hardware Workload/configuration Before After Change
2 x gfx1250 mxfp8, 32 tokens/rank 255.0 250.7 -1.7%
2 x gfx1250 mxfp8, 128 tokens/rank 294.5 286.9 -2.6%
2 x gfx1250 mxfp8, 1024 tokens/rank 391.2 377.2 -3.6%
2 x gfx1250 mxfp8, 2048 tokens/rank 611.0 606.7 -0.7%
2 x gfx1250 mxfp8, 4096 tokens/rank 1068.4 1060.8 -0.7%
2 x gfx1250 mxfp4, 32 tokens/rank 255.6 251.4 -1.6%
2 x gfx1250 mxfp4, 128 tokens/rank 292.8 284.5 -2.8%
2 x gfx1250 mxfp4, 1024 tokens/rank 389.1 376.4 -3.3%
2 x gfx1250 mxfp4, 2048 tokens/rank 600.1 595.5 -0.8%
2 x gfx1250 mxfp4, 4096 tokens/rank 1050.9 1049.2 -0.2%
4 x gfx1250 mxfp8, 128 tokens/rank (prototype, see below) 202.5 196.7 -2.9%
4 x gfx1250 mxfp8, 512 tokens/rank (prototype) 251.5 247.8 -1.5%
4 x gfx1250 mxfp8, 1024 tokens/rank (prototype) 307.6 297.0 -3.4%
4 x gfx1250 mxfp8, 1536 tokens/rank (prototype) 421.9 392.6 -7.0%
4 x gfx1250 mxfp8, 2048 tokens/rank (prototype) 526.8 504.6 -4.2%

Where it comes from (2 x gfx1250, mxfp8): gemm2 122.2 -> 106.2 us at 1024 tokens/rank and 168.9 -> 145.5 us at 2048; the reduce, reading the wider wire, 7.4 -> 8.1 us and 12.2 -> 16.5 us. The gain therefore narrows as tokens grow.

Measurement notes: the 2-GPU rows are one run per point on GPUs 2,3 while another job held GPUs 0,1, measured on the same wire layout one revision before the planar path was deleted; spot checks on this head (mxfp8 1024/2048, mxfp4 2048) agree within 0.5%. The 4-GPU rows are the same mxfp8 layout as an env-gated prototype on afdc60b.

Testing

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

MI250X/MI300X do not apply: the change is limited to the gfx1250 MegaMoE path.

Documentation

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

The wire is internal to one pipeline (gemm2 epilogue -> reduce); nothing user-facing changes.

Dependencies

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

Breaking Changes

None. The comb_inp layout is private to the gemm2 scatter and the reduce of the same step. A quantized-combine gemm2 build whose warp tile does not divide 256 columns now raises ValueError at build time; every row of tuned_grouped_fmoe.csv satisfies it (tile_n2/warp tile in {256/64, 256/128, 512/128, 512/256}), so only *_N2 env overrides can hit it.

PR Self-Review

Reviewed revision

769b7ac

Behavior and intent

The MX combine wire changes from two planes (payload, then scales) to per-chunk payload + scale line. Previously every gemm2 tile row also issued an 8 B remote write into the middle of a cache line, which is expensive over xGMI out of proportion to its size; now every remote write is whole lines and the reduce needs one load per trip. Numerics are unchanged: the same quantized bytes land in different offsets.

Validation and unverified scope

Run on this head, 2 x gfx1250, ROCm 10.1, torch 2.11, FlyDSL 0.4.2:

  • Accuracy, HIP_VISIBLE_DEVICES=2,3 torchrun --nproc_per_node=2 op_tests/multigpu_tests/bench_mega_moe.py -e 256 -k 8 -hd 7168 -id 2048 -tpr <T> --layers 2 --acc_verify 1 -q a4w4_mxfp4 --combine_quant <wire> --stage1_fused true --stage2_fused true: MEGA-CHECK PASS with logits_diff identical to main at every point (mxfp8: 0.042645 at 128, 0.042693 at 1024; mxfp4: 0.054980 at 128, 0.054772 at 1024).
  • pytest op_tests/tuning_tests/test_grouped_gemm_launch_abi.py: 13 passed.
  • black and ruff clean on the changed files.

On earlier revisions of the same layout: mxfp8 accuracy identical to main at 2048 tokens/rank (2 ranks) and at 128/2048 (4 ranks); a deliberately wrong scale offset in the reduce turns MEGA-CHECK to NaN, so the new read path is the one exercised.

Unverified:

PR-specific question

Changed op tests

None.

The fused scatter combine's MX slot was two planes: the fp8/fp4 payload, then
hidden/32 e8m0 bytes. Each gemm2 tile row thus went out as a payload store
plus an 8 B scale store into the middle of a peer's cache line, and a
partial-line remote write over xGMI costs far more than its bytes.

Lay the slot out per 256 features instead: the chunk's payload, then one
128 B line whose first 8 bytes are its scales. The epilogue stages a tile row
exactly that way in LDS and scatters it in one gather-store of whole lines;
the reduce loads one plane per trip and reads each scale right behind its
chunk. The planar layout, its second store and its second load go away.

The wire grows (mxfp8 7392 -> 10752 B, mxfp4 3808 -> 7168 B at hidden 7168)
but still fits the arena's bf16-sized slots, and the results are
bit-identical.

2 x gfx1250, 256 experts, topk 8, hidden 7168, a4w4 mxfp4, per-layer us:
  tokens/rank        32     128    1024   2048   4096
  mxfp8  before    255.0  294.5  391.2  611.0  1068.4
         after     250.7  286.9  377.2  606.7  1060.8
  mxfp4  before    255.6  292.8  389.1  600.1  1050.9
         after     251.4  284.5  376.4  595.5  1049.2
@lalala-sh
lalala-sh requested a review from a team November 5, 2026 08:21
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 7501 --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.

@github-actions github-actions Bot changed the title [Flydsl][MoE] [gfx1250] give each MX combine chunk its own scale line [FlyDSL] [MoE] [gfx1250] give each MX combine chunk its own scale line Nov 5, 2026
@github-actions github-actions Bot added the FlyDSL label Nov 5, 2026
@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 769b7ace94a5 · 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.

@XingerZhu

Copy link
Copy Markdown
Contributor

LGTM

@yadaish yadaish 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.

LGTM

@coderfeli
coderfeli merged commit f9d1fd7 into main Nov 9, 2026
@coderfeli
coderfeli deleted the wjx/mega-moe-combine-scale-line branch November 9, 2026 09:49
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
The fused scatter combine's MX slot was two planes: the fp8/fp4 payload, then
hidden/32 e8m0 bytes. Each gemm2 tile row thus went out as a payload store
plus an 8 B scale store into the middle of a peer's cache line, and a
partial-line remote write over xGMI costs far more than its bytes.

Lay the slot out per 256 features instead: the chunk's payload, then one
128 B line whose first 8 bytes are its scales. The epilogue stages a tile row
exactly that way in LDS and scatters it in one gather-store of whole lines;
the reduce loads one plane per trip and reads each scale right behind its
chunk. The planar layout, its second store and its second load go away.

The wire grows (mxfp8 7392 -> 10752 B, mxfp4 3808 -> 7168 B at hidden 7168)
but still fits the arena's bf16-sized slots, and the results are
bit-identical.

2 x gfx1250, 256 experts, topk 8, hidden 7168, a4w4 mxfp4, per-layer us:
  tokens/rank        32     128    1024   2048   4096
  mxfp8  before    255.0  294.5  391.2  611.0  1068.4
         after     250.7  286.9  377.2  606.7  1060.8
  mxfp4  before    255.6  292.8  389.1  600.1  1050.9
         after     251.4  284.5  376.4  595.5  1049.2
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