Skip to content

[FlyDSL] fused_compress_attn: zero padding kv in Phase 1 - #7550

Merged
valarLip merged 1 commit into
ROCm:mainfrom
yhl-amd:hyi/flydsl-compress-mask-pad
Nov 7, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
yhl-amd:hyi/flydsl-compress-mask-pad

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • With more than 128 concurrent requests, the requests on the polluted slots answer correctly again.
  • GSM8K at high concurrency recovers fully together with [V4] Reset the cache CUDA graph capture wrote before admitting requests ATOM#3057; with this PR alone it recovers only partly, because ATOM's capture also leaves a second reader of the polluted state, which is fixed on the ATOM side.
  • Low-concurrency accuracy is unchanged.
  • black and ruff are clean.

🤖 Generated with Claude Code

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]>
@github-actions

github-actions Bot commented Nov 6, 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 7550 --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 6, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 9b45acdb68e6 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer

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

@valarLip
valarLip merged commit d67fc6d into ROCm:main Nov 7, 2026
valarLip pushed a commit that referenced this pull request Nov 7, 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]>
@yzhou103 yzhou103 mentioned this pull request Nov 8, 2026
1 task
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
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]>
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