Skip to content

[FlyDSL] [Bugfix] Zero consumed kv in the gfx1250 HCA Phase 2 loop - #7601

Merged
valarLip merged 1 commit into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-flydsl-compress-mask-nan
Nov 7, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
hubertlu-tw:fix/gfx1250-flydsl-compress-mask-nan

Conversation

@hubertlu-tw

@hubertlu-tw hubertlu-tw commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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-L510 on main). Those iterations still load kv_in[max(ragged_id - (127 - k), 0)] and add w_k * kv_k with w_k = 0.

In a batch, those kv_in rows 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 from window_len on, 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: new test_flydsl_compress_attn_masked_nan (Table 5, --masked-nan csa hca, on by default):
    • csa: NaN in ring row 0 of a new sequence's state slot, plan rows [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.
    • hca: plan row [1, 1, 255, 127], finite state, NaN in the other request's kv_in row 0. This is the case fixed here.
    • Both check that the output is finite and matches the torch reference at the sweep's bf16 tolerance, on every architecture the file supports.

Performance (if applicable)

One extra select per element in the HCA Phase 2 loop, and no measurable cost. Numbers are us_kernel from the default sweep of op_tests/test_flydsl_compress_attn.py on gfx1250, as the geometric mean over the sweep's cases (decode: 20 cases, prefill: 3). "Before" is main with #7550 and "after" is this branch; both ran at the same time on two GPUs, each with a fresh FlyDSL cache:

Hardware Workload/configuration Before (µs) After (µs) Change
gfx1250 hca_main decode, single kernel 92.86 92.37 -0.5%
gfx1250 hca_main decode, 2-kernel 12.41 12.41 0.0%
gfx1250 hca_main prefill, single kernel 114.18 113.49 -0.6%
gfx1250 hca_main prefill, 2-kernel 5.98 5.75 -3.9%

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

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Results on gfx1250:

  • This branch: python op_tests/test_flydsl_compress_attn.py --masked-nan csa hca passes. csa/masked_nan nw=1, csa/masked_nan nw=4 and hca/masked_nan are all finite and within tolerance.
  • main kernels 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 with AssertionError: hca/masked_nan nw=None: a masked NaN reached the output.
  • Full python op_tests/test_flydsl_compress_attn.py: no regression. All 115 Table 1 cases match before and after. Three bit-exact cache_scale checks in csa_indexer fail (prefill/single bs=32, legacy(NW=1) bs=2 and bs=8), but they fail the same way on main, so they're not from this PR.
  • gfx950 (CI): full test file passes.

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):

Kernels Result
Unfixed Whole server breaks after 37–535 s; accuracy falls to ~0.5
Phase 1 fix only (#7550) Whole server breaks after 101 s (1,534 requests): 87 of 434 responses corrupted in 30 s, rolling accuracy 0.58. Non-finite sliding-window rows go from 5,248 to 108,558 in 11 s and end at about 1.57M, roughly 198 state slots
Phase 1 + Phase 2 (#7550 + this PR) Clean for 20 min (34,466 requests, ~28.7 req/s), accuracy 0.96. The occasional NaN from elsewhere still hit 3 requests, but each stayed inside its own request (at most 3,200 non-finite window rows) and nothing spread

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

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The API is unchanged, and so is the behavior for finite inputs.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

a71778db3

Behavior 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_in row 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.py from this branch passes with this branch's kernels: all three masked-NaN cases pass and the full sweep shows no regression. With main'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-exact csa_indexer cache_scale checks, identical on main. 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_nan fails on gfx1250: a consumed Phase 2 iteration multiplies the other request's NaN kv_in row by weight 0 and the compressed row comes out NaN. The csa case passes on main since #7550, and is there so that fix stays covered. No existing test catches either: the canonical sweep in this file only puts NaN in kv_in rows 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.py adds test_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.

@hubertlu-tw
hubertlu-tw requested review from a team and valarLip November 7, 2026 03:00
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7601 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot added the FlyDSL label Nov 7, 2026
@aiter-bot

aiter-bot commented Nov 7, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision a71778db3c63 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior 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_in` row 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.py` from this branch passes with this branch's kernels: all three masked-NaN cases pass and the full sweep shows no regression. With `main`'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-exact `csa_indexer` `cache_scale` checks, identical on `main`. 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_nan` fails on gfx1250: a consumed Phase 2 iteration multiplies the other request's NaN `kv_in` row by weight 0 and the compressed row comes out NaN. The csa case passes on `main` since #7550, and is there so that fix stays covered. No existing test catches either: the canonical sweep in this file only puts NaN in `kv_in` rows 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.py` adds `test_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.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@hubertlu-tw hubertlu-tw closed this Nov 7, 2026
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]>
@hubertlu-tw hubertlu-tw reopened this Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7601 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@hubertlu-tw
hubertlu-tw force-pushed the fix/gfx1250-flydsl-compress-mask-nan branch from 5829a15 to a71778d Compare November 7, 2026 05:04
@hubertlu-tw hubertlu-tw changed the title [FlyDSL] [Bugfix] Zero masked K-row values in the compressor kernels [FlyDSL] [Bugfix] Zero consumed kv in the gfx1250 HCA Phase 2 loop Nov 7, 2026
@valarLip
valarLip merged commit 2530d10 into ROCm:main Nov 7, 2026
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants