Skip to content

NSA compression: suppress aliased O1 store for static short queries - #599

Draft
mgoldfarb-nvidia wants to merge 1 commit into
NVIDIA:developfrom
mgoldfarb-nvidia:mgoldfarb/fix-nsa-compression-short-q
Draft

NSA compression: suppress aliased O1 store for static short queries#599
mgoldfarb-nvidia wants to merge 1 commit into
NVIDIA:developfrom
mgoldfarb-nvidia:mgoldfarb/fix-nsa-compression-short-q

Conversation

@mgoldfarb-nvidia

@mgoldfarb-nvidia mgoldfarb-nvidia commented Aug 14, 2026

Copy link
Copy Markdown

Before submitting

  • I agree to license this contribution under the terms of LICENSE.txt.
  • I ran pre-commit run and committed any formatting changes.
  • I added GitHub labels: one cat-*, one or more mod-*, and one orig-*. Maintainer action requested: cat-bug, mod-cutedsl, and orig-nv-eng; the contributor token cannot add upstream labels.

Affected area

FE OSS kernels or CuTeDSL

Summary

  • Compile out the second 128-row NSA compression output store only when the query extent is statically known to contain one MMA tile or less.
  • Keep both correction/epilogue pipeline stages consumed and released, with the TMA wait count adjusted to the number of committed stores.
  • Add a JAX static-specialization regression at query lengths 127, 128, 129, and 300.

Why

Each compression CTA processes two 128-row query tiles. When a statically specialized query extent contains only one tile, flat_divide canonicalizes the singleton residual tile mode to stride zero. The unconditional O1 TMA store therefore aliases O0 and overwrites valid output instead of remaining out of bounds.

The guard checks the layout extent with cute.is_static and evaluates the tile-count condition with cutlass.const_expr. Dynamic extents and static multi-tile extents retain the original O1 store/wait path; only the static singleton specialization prunes the aliased store. Both correction pipeline handles are still consumed and released unconditionally.

Related issues

None.

API and compatibility impact

None. This is a correctness fix for the SM100 NSA compression kernel and does not change its public API. The guard folds during tracing, so the dynamic path adds no runtime comparison or branch. The short static specialization removes one invalid TMA store and commit.

Testing

  • NVIDIA B200, CUDA 13.0, CuTeDSL 4.7.0, JAX 0.10.2:
    • Before the fix, seqlen_q=128 failed against the FP32 reference with max absolute error 0.27612305; seqlen_q=129 passed.
    • cd test/python && pytest -q fe_api/nsa/test_NSA_compression_attention_jax.py -m L0: 4 passed (127, 128, 129, 300).
    • The supplied bridge/direct repro produced zero difference at 128, 200, 256, and 300.
    • Direct dynamic outputs at 128, 129, and 300 were bit-identical to the unmodified cuDNN Frontend 1.25 kernel.
  • uvx pre-commit run --files python/cudnn/native_sparse_attention/compression/fmha.py test/python/fe_api/nsa/test_NSA_compression_attention_jax.py: passed.
  • python3 -m py_compile python/cudnn/native_sparse_attention/compression/fmha.py test/python/fe_api/nsa/test_NSA_compression_attention_jax.py: passed.
  • git diff --check: passed.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b7e9d382-6887-4495-890c-9e0696282d95

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

When the query extent is statically at most one 128-row MMA tile,
flat_divide folds the residual tile stride to zero. The unconditional O1
TMA store then aliases O0 and overwrites valid output.

Compile out only that aliased store while always consuming and releasing
both correction pipeline stages. Dynamic and multi-tile extents retain the
original store and wait sequence. Add JAX regression coverage at 127, 128,
129, and 300 rows.
@mgoldfarb-nvidia
mgoldfarb-nvidia force-pushed the mgoldfarb/fix-nsa-compression-short-q branch from 6e63b5d to 376f7de Compare August 14, 2026 20:42
@mgoldfarb-nvidia mgoldfarb-nvidia changed the title NSA compression: suppress invalid Q1 stores for short queries NSA compression: suppress aliased O1 store for static short queries Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant