Repository navigation
[FlyDSL] [MoE] [gfx1250] give each MX combine chunk its own scale line - #7501
Conversation
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
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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 |
|
LGTM |
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
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_bitspath 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 existingtile_n % 256validation).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-wireWAIT_Nare 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.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
MI250X/MI300X do not apply: the change is limited to the gfx1250 MegaMoE path.
Documentation
The wire is internal to one pipeline (gemm2 epilogue -> reduce); nothing user-facing changes.
Dependencies
Breaking Changes
None. The
comb_inplayout 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 raisesValueErrorat build time; every row oftuned_grouped_fmoe.csvsatisfies it (tile_n2/warp tile in {256/64, 256/128, 512/128, 512/256}), so only*_N2env 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:
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.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:
op_tests/multigpu_tests/test_mega_moe_gfx1250.pydoes not run in this environment: the installed mori predatesPlan.describe()(feat(ep/v2): plans report the arena and staging sizes they need (info + describe) mori#844), and it fails the same way on main.PR-specific question
Changed op tests
None.