Repository navigation
[FlyDSL] fused_compress_attn: zero padding kv in Phase 1 - #7550
Conversation
A padding row reads ring 0 of the slot's state and is weighted by zero via a -inf score, but 0 * NaN = NaN, so a stale NaN there poisons the output (ROCM-33841). Select the kv to 0 as well, in all six Phase 1 load sites. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ 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 |
…7601) #7550 zeroes the kv of Phase 1 padding rows. The gfx1250 HCA kernel has one more masked load that it does not cover: the unrolled Phase 2 loop also visits the K rows that Phase 1 already consumed, masks them only by a -inf score, and still accumulates w_k * kv_k. For those rows it loads kv_in[max(ragged_id - (127 - k), 0)], which in a batch belongs to other requests. 0 * NaN is NaN, so one request with a NaN hidden state poisons the HCA entry of every request at the next 127 batch rows when they cross their next 128-token boundary. Zero the value for consumed rows as well, like the Triton path. A consumed row has weight 0, so finite inputs give the same output. op_tests/test_flydsl_compress_attn.py gets a masked-NaN regression check for both masked loads: NaN in ring row 0 of a new CSA sequence's state slot (the #7550 case, single-wave and K-split) and NaN in another request's kv_in row at an HCA 128-boundary. The output must be finite and match the torch reference. Signed-off-by: Hubert Lu <[email protected]>
A padding row reads ring 0 of the slot's state and is weighted by zero via a -inf score, but 0 * NaN = NaN, so a stale NaN there poisons the output (ROCM-33841). Select the kv to 0 as well, in all six Phase 1 load sites. Co-authored-by: Claude Opus 5.5 <[email protected]>
…7601) #7550 zeroes the kv of Phase 1 padding rows. The gfx1250 HCA kernel has one more masked load that it does not cover: the unrolled Phase 2 loop also visits the K rows that Phase 1 already consumed, masks them only by a -inf score, and still accumulates w_k * kv_k. For those rows it loads kv_in[max(ragged_id - (127 - k), 0)], which in a batch belongs to other requests. 0 * NaN is NaN, so one request with a NaN hidden state poisons the HCA entry of every request at the next 127 batch rows when they cross their next 128-token boundary. Zero the value for consumed rows as well, like the Triton path. A consumed row has weight 0, so finite inputs give the same output. op_tests/test_flydsl_compress_attn.py gets a masked-NaN regression check for both masked loads: NaN in ring row 0 of a new CSA sequence's state slot (the #7550 case, single-wave and K-split) and NaN in another request's kv_in row at an HCA 128-boundary. The output must be finite and match the torch reference. Signed-off-by: Hubert Lu <[email protected]>
Summary
FlyDSL fused compress-attn, Phase 1: a padding row (
s < 0) now loads kv as 0, not just score as-inf. The fix is applied to all six Phase 1 load sites:fused_compress_attn.py: legacy and K-split;fused_compress_attn_gfx1250.py: legacy and K-split;fused_compress_attn_hca.py;fused_compress_attn_hca_gfx1250.py.Problem
A padding row's ring index is clamped to 0, and its kv is read from ring 0 of the slot's state. Only the score is masked to
-inf, which gives the row zero weight in the online softmax. But 0 × NaN = NaN.If ring 0 holds NaN (a stale value from whatever last used the slot), the compressed output is NaN even though the row should contribute nothing. In ROCM-33841, ATOM's CUDA graph capture warmup leaves NaN there for slots ≥128 on gfx1250. Every request scheduled onto those slots then decodes garbage, and DeepSeek-V4-Flash GSM8K collapses at high concurrency. The Triton path (
ATOM_FUSED_COMPRESS_USE_FLYDSL=never) does not show the problem.The root cause on the ATOM side is fixed in ROCm/ATOM#3057. This change makes the kernel not depend on padding memory being finite.
Fix
kv = select(is_pad, 0, kv)next to the existing score select. It is one extra select per lane per Phase 1 row, and does not change the result whenever ring 0 is finite.Validation
DeepSeek-V4-Flash TP1 on gfx1250, FlyDSL cache cleared:
🤖 Generated with Claude Code