Repository navigation
Conversation
…ch half's X DMA before the barrier In compile_mixed_moe_gemm1_common's interleaved main loop, each half issues the next X tile's DMA into LDS (buffer_load ... lds), then the scale and B loads, and the next half waits with s_waitcnt vmcnt(body_vmcnt_before_barrier) and s_barrier before other waves read that tile. The threshold counts the X tile and the B loads, which covers the DMA only if that many loads are issued after it. In the compiled first half the scale loads land between the two X DMAs (32-row tile: DMA, scale, scale, DMA, then four B loads), so vmcnt(5) lets the second DMA (rows 16-31) still be in flight at the barrier. Seen as intermittent output deviations in fused_moe with FlyDSL stage 1 (t32x128x256 / t64x128x256, fp8 X, fp4 interleaved W, use_async_copy=True as _flydsl_stage1_wrapper passes): runs of neighbouring tokens off by 2-13% relative L2, gone with use_async_copy=False or with vmcnt(0). Fix (ordinary async kernels; the heterogeneous path already waits vmcnt(0)): a sched_barrier right after each half's X DMA, so no later load is scheduled between or above the DMAs, and the wait counts only the B loads, which always follow them. Module name gains '_dmaw' so cached kernels are recompiled.
…e pad in both stages When the intermediate dim is padded (intermediate_pad > 0; e.g. 576 real columns per rank padded to 640 for DeepSeek-V4.1-Flash at TP4), both FlyDSL stages load the pad: stage 1 computes the pad's N tile (w1 and its scales), and stage 2 reads the pad's K cells of w2. Their contribution is zero. With AITER_MOE_SKIP_INTER_PAD=1 (default off; off leaves the IR unchanged): - stage 1 (gate/up interleaved, fp4/fp8 W): an N tile wholly in the pad reads w1 and its scales through zero-sized buffer resources. Every load returns 0 without touching memory; the tile still writes the zeros stage 2 reads. Module name gains '_padskip'. - stage 2, cshuffle (fp4 B): B cells at K >= inter_dim - inter_dim_pad are read through an out-of-range offset. Tagged '_padskip<K>'. - stage 2, layout v2 (gemm2_a4w4_port, fp4 B): the B view's buffer is bounded at K_REAL/32 cells per 16-row group, so K >= K_REAL reads zero. Tagged '_kr<K>'; inter_dim_pad reaches it through _flydsl_v2_stage2_wrapper. The pad's MFMAs still run (their operands are zero); only its loads go.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
MI355X results (the open item in the test plan). Setup. vLLM serving DeepSeek-V4.1-Flash at TP4 on MI355X (gfx950):
Correctness. GSM8K (1,319, real speculative acceptance, 3 runs each), counts correct:
C8, per-request median ratios against the control, by input length. "Better" and "worse" mean outside the control's own point-to-point spread.
TTFT is flat in every bucket, and no cell is worse. End-to-end latency summed over requests: −0.5%. C32:
The verdicts are the same as on MI350: a keep at C8 and a Pareto point at C32. |
|
No activity for 15 days, so this is now labelled |
Summary
Two changes to the FlyDSL 2-stage fused MoE (fp8 activations × MXFP4 weights, gate/up interleaved), found while optimizing DeepSeek-V4.1-Flash (E=384, topk=6, model_dim 5120, intermediate 576 per rank padded to 640 at TP4) on gfx950:
interleaved_halfDMAs the next X tile into LDS (buffer_load ... lds). Then it issues the scale and B loads. The next half waits withs_waitcnt vmcnt(body_vmcnt_before_barrier)ands_barrierbefore other waves read that tile. The threshold (tile_m//32//fp4_ratio + tile_n//32*gui_ratio*mult, 5 for a 32×128×256 tile) covers the DMA only if that many loads are issued after it. The compiler does not guarantee that. In one half of the compiled loop only 4 loads follow the last DMA, sovmcnt(5)lets it still be in flight at the barrier, and rows of the next tile are read stale.use_async_copy=Falseor withvmcnt(0).vmcnt(0).sched_barrierright after each half's X DMA, so no later load is scheduled between or above the DMAs._dmaw, so cached kernels are recompiled.vmcnt(0)instead cost up to 10.8% per call.AITER_MOE_SKIP_INTER_PAD=1(opt-in, default off; off leaves the IR unchanged): stop loading the intermediate pad whenintermediate_pad > 0. Today stage 1 computes the pad's N tile (w1 and its scales), and stage 2 reads the pad's K cells of w2, all zeros._padskip._padskip<K>.gemm2_a4w4_port, fp4 B): the B view's buffer is bounded atK_REAL/32cells per 16-row group, so K ≥ K_REAL reads zero.inter_dim_padreaches it through_flydsl_v2_stage2_wrapperandmxfp4_moe_gemm2(D_INTER_PAD=...). Tag_kr<K>.The two commits are independent, and the fix can be taken alone.
Test plan
All on MI350 (gfx950, 256 CUs). The data are
fused_moecalls captured from DeepSeek-V4.1-Flash serving (one MoE layer, rank 0 of TP4), replayed with the call's own routing. The table is the DSV4.1-Flash FlyDSL rows (e.g.flydsl_moe1_afp8_wfp4_bf16_t32x128x256_w4_gui_fp8withflydsl_moe2_afp8_wfp4_bf16_t32x128x128_atomic_bnt2orflydsl_moe2_layout_afp8_wfp4_bf16_t32x256x128_atomic_nt_sbm32).On this branch (main
5b2f7d1+ the two commits;flydsl==0.3.4.1,PREBUILD_KERNELS=0):ISA (FlyDSL's final ISA; for every
s_barrierafter an X DMA, is there avmcnt(N)with N ≤ the loads issued after the DMA):Repeated runs on identical inputs: 24 runs × 2 calls per tier; rows off the elementwise median by more than 2% of its maximum.
Accuracy against an fp32 reference built from the checkpoint (MXFP4 dequant, MXFP8 activations; five runs; tiers 8–256, 2,048, 8,192): this branch, with and without the pad skip, has main's max-abs and relative-L2 error at every tier: identical at 128, 2,048 and 8,192, within the run-to-run variation of stage 2's atomic accumulation elsewhere. Max-abs differences from main's outputs are 1–2 bf16 ulps, as between main's own runs.
µs per
fused_moecall (median over calls and three launches):black (26.10) clean on the touched files; ruff 0.16.0 reports nothing beyond main's own findings on these files.
The same changes, as a patch on v0.1.21.post2 (
flydsl==0.3.2, the vLLM DeepSeek-V4.1-Flash image), in more depth:kw4) kernel included.Not changed here, found on the way: in the K-split (
k_wave > 1) stage 1, the loop's last half issues one X DMA past the wave's K range. The check isnext_k_dma_py < int(k_dim), the full K, not the wave's share. That DMA lands in the buffer the K-wave reduction later reuses. In the compiled kernels I checked, a wait the compiler inserts for a register dependency covers it.🤖 Generated with Claude Code