Repository navigation
[FlyDSL] [Bugfix] Zero consumed kv in the gfx1250 HCA Phase 2 loop - #7601
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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 |
ROCm#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 ROCm#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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
5829a15 to
a71778d
Compare
…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
#7550 fixed the Phase 1 padding rows of the FlyDSL compressor, which used to be masked only through a -inf score while their (possibly NaN) kv still got accumulated. The gfx1250 HCA kernel has one more load with the same problem that #7550 doesn't touch, and it's the one that lets a single bad request poison its neighbours in the batch.
This PR zeroes the kv of those rows too, and adds the masked-NaN regression test that neither PR had, covering both the #7550 case and this one.
Motivation
The gfx1250 HCA kernel (ratio 128, K = 128) unrolls Phase 2 over the whole K range of each wave, and masks the iterations Phase 1 already consumed with a -inf score (
fused_compress_attn_hca_gfx1250.py#L496-L510on main). Those iterations still loadkv_in[max(ragged_id - (127 - k), 0)]and addw_k * kv_kwithw_k = 0.In a batch, those
kv_inrows belong to other requests. So if one request's hidden state has a NaN at this layer, every request at the next 127 batch rows gets a NaN HCA entry the next time it crosses a 128-token boundary, even though it never attends to that request. That's the step that turns one bad request into all of them.We hit this on DeepSeek-V4-Pro served by ATOM on 4 x gfx1250 B0 (ADO 4171957). Under sustained concurrent load, an occasional NaN from elsewhere (tracked separately) spread to every running request, GSM8K dropped from 0.95 to about 0, and the server stayed broken until restart. #7550 fixes the Phase 1 half, but on its own it isn't enough: with only the #7550 kernels the same server still broke after 101 s under load (Testing below). This PR is the Phase 2 half.
The gfx942/gfx950 HCA kernel only runs Phase 2 over
[split, k_end), and the Triton path only reads input rows fromwindow_lenon, so neither has this problem.Changes
aiter/ops/flydsl/kernels/fused_compress_attn_hca_gfx1250.py: in the unrolled Phase 2 loop, also set a consumed row's value to 0 (arith.select(is_consumed, c_zero_f32, kv)), next to the existing score select.op_tests/test_flydsl_compress_attn.py: newtest_flydsl_compress_attn_masked_nan(Table 5,--masked-nan csa hca, on by default):[3, 0, 3, 4]and[7, 1, 103, 4], single-wave and K-split kernels. This is the case [FlyDSL] fused_compress_attn: zero padding kv in Phase 1 #7550 fixed; it had no test.[1, 1, 255, 127], finite state, NaN in the other request'skv_inrow 0. This is the case fixed here.Performance (if applicable)
One extra select per element in the HCA Phase 2 loop, and no measurable cost. Numbers are
us_kernelfrom the default sweep ofop_tests/test_flydsl_compress_attn.pyon gfx1250, as the geometric mean over the sweep's cases (decode: 20 cases, prefill: 3). "Before" ismainwith #7550 and "after" is this branch; both ran at the same time on two GPUs, each with a fresh FlyDSL cache:A second, back-to-back run gave -0.1%, 0.0%, -0.1% and -4.4%. Run-to-run noise is up to about 4%, so this is flat. The CSA shapes aren't touched by this PR.
Testing
Results on gfx1250:
python op_tests/test_flydsl_compress_attn.py --masked-nan csa hcapasses.csa/masked_nan nw=1,csa/masked_nan nw=4andhca/masked_nanare all finite and within tolerance.mainkernels with this branch's test: both csa cases pass, since [FlyDSL] fused_compress_attn: zero padding kv in Phase 1 #7550 fixed them. The hca case fails withAssertionError: hca/masked_nan nw=None: a masked NaN reached the output.python op_tests/test_flydsl_compress_attn.py: no regression. All 115 Table 1 cases match before and after. Three bit-exactcache_scalechecks incsa_indexerfail (prefill/single bs=32,legacy(NW=1) bs=2andbs=8), but they fail the same way onmain, so they're not from this PR.End to end, on 4 x gfx1250 B0 with DeepSeek-V4-Pro on ATOM (
rocm/atom-dev:ub26-dcgpu-rk-10.2.0a20260922.bkc.20261002-pyt2.14.0-tri-main-15164f01-atomsrc-gfx1250-b1012, TP4, 600 requests in flight):The last row used exactly #7550's code plus this PR's change. With an equivalent earlier patch (same Phase 1 and Phase 2 zeroing, written independently of #7550) we also ran the original workload, 6 x 65 lm_eval GSM8K clients, for 15 rounds at 0.946–0.955, and EP4 + DP-attention for 20 min, all clean.
Documentation
The API is unchanged, and so is the behavior for finite inputs.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
a71778db3Behavior and intent
For finite inputs the gfx1250 HCA compressor gives exactly the same output as before, because a consumed row already has weight 0. When the
kv_inrow that a consumed Phase 2 iteration loads holds NaN or Inf, which in a batch is another request's row, the output is now finite instead of NaN, so one bad request no longer poisons the HCA entries of its batch neighbours.Validation and unverified scope
On gfx1250,
python op_tests/test_flydsl_compress_attn.pyfrom this branch passes with this branch's kernels: all three masked-NaN cases pass and the full sweep shows no regression. Withmain's kernels (which include #7550), the csa cases pass and the hca case fails with "a masked NaN reached the output", which is exactly the gap this PR closes. The only other failures are 3 bit-exactcsa_indexercache_scalechecks, identical onmain. Kernel timings are flat (Performance table). End to end on an ATOM DeepSeek-V4-Pro TP4 server under the same load (fast_repro.py --inflight 600 --max-tokens 256), the #7550 kernels alone still let the whole server break after 101 s, while #7550 plus this change stayed clean for 20 min (34,466 requests, accuracy 0.96, the three stray NaN episodes stayed inside their own requests). Still unverified: the change only touches the gfx1250 HCA kernel, so gfx942/gfx950 CI just runs the new test against their unchanged kernels. The end-to-end runs loaded #7550's and this PR's kernel code into the aiter shipped in the ATOM image, not a full build of this branch.PR-specific question
Before this PR, the hca case of
test_flydsl_compress_attn_masked_nanfails on gfx1250: a consumed Phase 2 iteration multiplies the other request's NaNkv_inrow by weight 0 and the compressed row comes out NaN. The csa case passes onmainsince #7550, and is there so that fix stays covered. No existing test catches either: the canonical sweep in this file only puts NaN inkv_inrows past the last valid token (CUDA-graph padding), which no boundary ever reads, and its state rows are always finite, so none of its cases send a NaN through a masked row.Changed op tests
op_tests/test_flydsl_compress_attn.pyaddstest_flydsl_compress_attn_masked_nan. It puts a NaN in exactly the K rows the compressor kernels mask, the CSA Phase 1 padding rows (#7550) and the gfx1250 HCA Phase 2 consumed rows (this PR), and checks that the output stays finite and matches the torch reference. It isn't redundant with the existing sweep, which never reads a NaN row through a masked iteration.