Repository navigation
[HIP] [fix] MLA reduce: LDS race between rows in kn_mla_reduce_v1's massive path - #7912
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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 |
…n row's stage-2 k-tile to K (#7963) kimik3tp8_tuned_grouped_fmoe.csv runs the token=16384 row's stage 2 (K = inter_dim = 384 per TP8 expert slice) with tile_k2 = 512, larger than K. The gfx1250 TDM grouped GEMM then reads past the expert slice and the GPU faults in mxfp4_tdm_fp4_t128x128x512_..._K384_e896 ("Page not present"). ATOM's warmup prefills 2 x 8192 tokens, so Kimi-K3 TP8 hits this row at every server start. Use tile_k2 = 128, which every other row of the table uses and which divides 384. The row came from #7296; the other 14 rows are unchanged. Verified on two MI455X nodes (Kimi-K3 TP8 + DCP8 with DSpark, ATOM main 9fec99786 + ROCm/ATOM#2647 + #2760, aiter main b6f1ff6 + #7912 + #7913 + this change). The server starts where it faulted in warmup before. GSM8K 5-shot is 0.9606 flexible / 0.9613 strict, and the MLPerf Endpoints agentic bench completes 293/293 samples at c4 and 1703/1703 at c64.
|
Review ownership / next action:
I will wait for the MLA primary review rather than approve ahead of it. |
Summary
Fixes an LDS race in
kn_mla_reduce_v1/kn_mla_reduce_v1_ps. When a workgroup reduces several query rows of a tile on the massive path (>= kMassiveThresholdsplits), warp 0 can overwrite rowr's split scales with rowr + kNumThreadGroupPerBh's while another warp is still reading them, and some output elements then mix the scales of two rows. On MI455X (gfx1250)op_tests/test_mla_reduce.pyfails onmainin 5 of 5 runs, and 27 of 60 multi-row decode-shaped reduces give wrong output. With the fix, all pass, at the same speed.Motivation
mla_reduce_v1_impl_massivewalks its rows in a loop. Per row:reduce_lse_massive) computes the row's split weights and writes them top_lds_lse_scale;__syncthreads();reduce_output_massive) readsp_lds_lse_scalewhile accumulating its slice of the output.Nothing separates step 3 of one row from step 1 of the next, so warp 0 can rewrite
p_lds_lse_scalebefore the other warp has read it. The final LSE is computed in warp 0's registers and stays correct; only the output is affected, a small fraction of elements per tile, varying from run to run.It needs more than one row per workgroup and a massive-path tile. That covers:
test_mla_reduce.py(64x[4]with 64 rows per tile,512x[4]with 2);kn_mla_reduce_v1(they do on gfx1250, wherekn_mla_reduce_v1_wideis not selected until [HIP] [gfx1250] MLA reduce: run kn_mla_reduce_v1_wide on wave32 GPUs #7914);Single-row tiles (most decode) and the simple path (2–3 splits, no LDS in the row loop) are not affected. The race does not depend on the target; it shows readily on gfx1250's wave32 workgroups. It may stay hidden elsewhere through timing; gfx9 was not run.
Changes
csrc/include/mla_reduce_kernels.cuh,reduce_lse_massive/mla_reduce_v1_impl_massive:__syncthreads()follows before it stores the final LSE and writesp_lds_lse_scale.Performance (if applicable)
Op-test times, MI455X (gfx1250),
mainvs fix:Two runs of
mainitself differ by up to 11% on the smallest of these shapes (64 heads, 16 tiles x 4 splits: 7.9 and 8.7 us), and by 1–3% from 64 tiles up.An earlier version put the barrier at the end of each row instead, before warp 0 starts the next row's loads. It cost 13% on the 64-row tiles (43.7 → 49.4 us), so it was dropped.
Testing
On MI455X (gfx1250), aiter
mainat111fbd8,module_mla_reducebuilt for gfx950 + gfx1250:python3 op_tests/test_mla_reduce.py(all default dtypes, head dims and cases), 5 runs each.main: SOME FAILED in 5 of 5 (64x[4]h=12 dv=128 every run,512x[4]in 2 of 5). Fix: ALL PASSED in 5 of 5.main: 27 wrong. Fix: 0 wrong.The existing cases cover it; no test is added. They fail intermittently rather than every run, so a new case would not make the race deterministic either.
Documentation
Bug fix with no interface change.
Dependencies
Breaking Changes
None.