Repository navigation
[CK] [FlyDSL] [Perf] A4W4 MoE stage 2: LDS-staged scatter epilogue (_ldspa) and tune for M3.1 - #7769
Conversation
…) + MiniMax-M3.1 rows Add the _ldspa variant of the FlyDSL layout-v2 GEMM2 bf16 scatter epilogue. The epilogue writes C to LDS as bf16 row pairs over the A slots. Each thread then writes 16-byte row chunks with non-temporal buffer stores, in place of one 2-byte store per element. The output is bitwise equal to the stock epilogue. The kernel name suffix _ldspa selects the variant. Other names do not change. The stage-2 wrapper, the AOT precompile and the tuners pass the flag. The MiniMax-M3.1 TP4 rows (E=128, top-4, inter_dim 768, 4096 to 32768 tokens) use it. Signed-off-by: Vinayak Gokhale <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
The fused shared-expert rows (E=129, top-5, inter_dim 768) at 16384 and 32768 tokens use the _ldspa scatter epilogue. Stage 2 is 4.5% to 6.8% faster and the output is bitwise equal. Signed-off-by: Vinayak Gokhale <[email protected]>
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
… rows - parse_flydsl_v2_gemm2_kernel raises ValueError for an _ldspa name unless it has an fp4 activation, a bf16 output and the scatter epilogue. get_flydsl_stage2_v2_kernels makes _ldspa only for these. - minimax_m3_fp4_tuned_fmoe.csv: the 6 _ldspa rows now have times measured with _ldspa (MI355X, uniform routing, median of 6 rounds that alternate with the stock kernel in one process). us1 is sort + quant + gemm1, us2 is gemm2 + scatter_reduce, us is the sum. tflops and bw are scaled by the time change. Before, the rows kept the stock times. - New test: test_ldspa_kernel_names_match_the_generator. Signed-off-by: Vinayak Gokhale <[email protected]>
…s pending A/B The 3 rows this branch changes in minimax_m3_fp4_tuned_fmoe.csv (tokens 32, 64 at inter_dim 768 and token 8192 at inter_dim 384) were tuned before the FlyDSL MoE kernel changes in ROCm#7769 and ROCm#7773, and tokens 32/64 raise the stage-2 error ratio from 1.2% to 4.8-4.9%. Restore origin/main's rows; each is re-applied only if a same-session A/B on current main shows it is faster at a comparable error ratio. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Bishwo Adhikari <[email protected]>
…096 tokens, check every kernarg precondition Re-measured against AITER main with ROCm#7769 (_ldspa) on MI355X (gfx950, FlyDSL 0.4.2), uniform routing, device time of the whole stage 2: the atomic kernels (v2ao) and the flat kernels below 4096 tokens are not faster than AITER's own gemm2 there (0.80x at M1024, 0.96x-0.99x at 1536-3072; the 1.17x at M2285 is the tuned row of the 4096 bucket: AITER's atomic_nt kernel takes 184 us where the row's pick takes 215 us). From 4096 tokens the flat and dense kernels are 1.07x-1.37x faster than AITER's best arm, with bit-identical output. Under strongly skewed routing the flat kernel also wins below 4096, so those calls stay with AITER until a replay on captured routing says which side real traffic is on. - pick_kernel: a scatter kernelName2 with block_m 128 and M >= 4096 (dense from 12288). - Ship the two kernels that can be picked (v2n_bm128, v4g8_bm128). gen_t1g2.py builds only those; the code objects are byte-identical to the previous build, the registry and build_info.json are regenerated. - _eligible: one pure function checks every flag, dtype, shape, contiguity and id dtype the kernarg ABI depends on (fp4 data, e8m0 scales, int32 ids, float32 weights, bf16 [M, 6144] moe_out, reverse_sorted present), before any device query. - check_installed(): raise when the registry or a code object is missing. - Tests: the output must match AITER's and its error against an fp32 reference must be at most 1.1x AITER's (the bound was loose); hot-routing cases; a declined call keeps AITER's output; every decline reason on meta tensors. Signed-off-by: Vorapol Assavasangthong <[email protected]>
Summary
This PR adds
_ldspa, a new bf16scatterepilogue for the FlyDSL A4W4 MoE stage-2 GEMM. The stock epilogue uses one 2-byte store per element, and these stores remove the reused W2 and A tiles from L2.Changes
_ldspaselects it. Other kernel signatures are unaffected._ldspa. But any model can use it for prefill._ldspa(bitwise; whole MoE call -3.3% at 16384 and -1.5% at 32768 tokens, uniform routing).Performance
MI355X, M3.1 TP4 MoE (hidden 6144, inter 768), production
aiter.fused_moeon main, us, uniform routing:Skewed routing: -4.1% to -4.5%. Interleaved runs in one process: -4.2% to -5.5% at 16k to 32k.
Testing
test_flydsl_v2_stage2_scatter_ldspa: bitwise equal to the stock epilogue, 4 tiles. On main (MI355X): 24 of 24 pass. On main, production output is bitwise equal with the old and new table (4 token counts, 2 routings).op_tests/test_flydsl_moe_aux.py(pytest calls its functions without arguments:TypeError).Limitations
[4M, hidden]bf16 intermediate is still written and read (1.6 GB each direction at 32k tokens).PR Self-Review
Reviewed revision
5aee658
Behavior and intent
The FlyDSL A4W4 MoE stage-2 GEMM gets an optional bf16
scatterepilogue,_ldspa. It puts C into LDS as bf16 row pairs and writes 16-byte non-temporal rows. The stock epilogue writes one 2-byte element per store, and these stores remove the reused W2 and A tiles from L2. With_ldspa, stage 2 is 4% to 6% faster at 4096 to 32768 tokens. Kernels without the suffix do not change.Validation and unverified scope
_ldspaname unless it has an fp4 activation, a bf16 output and the scatter epilogue; the 6_ldsparows have measured times),pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspaon MI355X: 25 passed.aiter/fused_moe.pyandgemm_moe_tune.py),pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspaon MI355X: 24 passed.pytest op_tests/flydsl_tests/test_flydsl_moe.py -k ldspaon main, MI355X: 24 passed. The_ldspaoutput is bitwise equal to the stock epilogue for 4 tiles.aiter.fused_moeon main: the output is bitwise equal with the old and the new table (4 token counts, uniform and skewed routing). The same is true on v0.1.28.post1.op_tests/test_flydsl_moe_aux.py(pytest calls its functions without arguments)._ldspa), and other models' shapes (no other table row uses_ldspa).PR-specific question
Only a kernel name that ends in
_ldspaselects the new epilogue. The name parser (mxfp4_kname.py) setsscatter_lds_pairsfrom that suffix, and every name without it builds the stock epilogue. Only 6 rows ofminimax_m3_fp4_tuned_fmoe.csvhave the suffix: gfx950 with 256 CUs, bf16 output, MXFP4 weights (per_1x32), hidden 6144, inter 768, E=128 top-4 at 4096 to 32768 tokens and E=129 top-5 at 16384 and 32768 tokens. The epilogue applies only to the A4W4 stage-2 scatter path. The tuner change (gemm_moe_tune.py) only passes the same flag through.Changed op tests
op_tests/flydsl_tests/test_flydsl_moe.py: the newtest_flydsl_v2_stage2_scatter_ldsparuns the_ldspaepilogue and the stock scatter epilogue on the same inputs and requires bitwise equal output for 4 tiles. The newtest_ldspa_kernel_names_match_the_generatorchecks that the parser accepts_ldspaonly on the names thatget_flydsl_stage2_v2_kernelsmakes. No other test runs this epilogue.