Repository navigation
perf(dsa): compute indexer scores with the cuDNN kernel - #8154
Open
JackRao123 wants to merge 3 commits into
Open
JackRao123 wants to merge 3 commits into
JackRao123 wants to merge 3 commits into
Conversation
_compute_indexer_scores_chunk_with_global_rows computed indexer scores with a per-head fp32 PyTorch loop that runs on SIMT instead of tensor cores. It serves chunked top-k whenever a chunk does not cover every row or carries explicit lengths, and the full-score varlen branch of _indexer_topk_bshd. Compute the scores with the cuDNN indexer kernel instead. Plain causal chunks pass q_causal_offsets=row_start, which is the reference mask. Chunks with explicit lengths run with the tightest causal offset that covers every row, computed on device, then apply the exact per-row prefix, so masked positions match the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jack Rao <jack.rao@baseten.co>
JackRao123
force-pushed
the
jackrao/upstream-dsa-cudnn-chunked-indexer-scores
branch
from
October 13, 2026 18:30
1de576b to
e4ee673
Compare
…unks cuDNN frontend >= 1.27 rejects seqlen_q > seqlen_k * ratio. Pooled-key chunks (for example 2312 query rows against 578 pooled keys at ratio 1) hit this check when explicit seq_lens are passed to _compute_indexer_scores_chunk_with_global_rows. Explicit seq_lens replace the kernel's causal mask through the masked_fill_ that follows the kernel call, so any ratio that covers them is valid. Raise the ratio to ceil(sq / sk) before the causal offset is computed from it: the offset (seq_lens * ratio - row - 1) then still makes row i keep at least seq_lens[i] keys under the ratio the kernel actually uses. Add test cases with more query rows than pooled keys * ratio, and make the number of rows a test parameter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jack Rao <jack.rao@baseten.co>
The cuDNN indexer fake kernels in test_dsa_native_parity.py did not accept the q_causal_offsets argument that the chunked score path now passes, so seven tests failed with a TypeError or wrong selections. Add a shared fake that emulates the kernel's ratio causal mask from q_causal_offsets, and use it where the old stubs either ignored the offsets or asserted that the kernel is never called: the explicit seq_lens chunk path now scores with the kernel and applies seq_lens afterwards. Stubs that return fixed scores just accept the new argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jack Rao <jack.rao@baseten.co>
Author
|
Two follow-up commits:
|
JackRao123
marked this pull request as ready for review
October 22, 2026 16:48
This was referenced Oct 26, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_compute_indexer_scores_chunk_with_global_rowscomputed indexer scores with a per-head fp32 PyTorch loop:bmm, thenrelu_,mul_andadd_for each indexer head, all on SIMT rather than tensor cores. It serves two callers:_indexer_topk_from_score_chunks, whenever a chunk doesn't cover every row or carries explicit lengths: long causal calls that need chunking, and calls with varlen bounds;_indexer_topk_bshd.This PR computes the scores with
indexer_forward_wrapperinstead, under the same name, and deletes the loop:q_causal_offsets=row_start, which is the reference mask ((row_start + i + 1) // ratio).q_causal_offsetsis available in the pinnednvidia-cudnn-frontend==1.29.0.Numerics
test_dsa_cudnn_indexer_scores.py: compares against a direct einsum reference over 9 cases: causal at ratio 1 and 4, unaligned row offsets, pooled bounds, empty rows, non-monotonic lengths, lengths beyondsk, packed resets.-infmask is identical in every case; max abs diff ≤ 1.2e-4 on scores up to ~300.nvidia-cudnn-frontend==1.29.0, 9/9 passing.Performance
Measured on a downstream fork with a model whose indexer always passes explicit bounds (a 4:1 pooled-key indexer). 262k tokens on 8x GB300, CP4 EP8:
Upstream models gain wherever they hit chunked scoring with explicit bounds, long causal calls, or the full-score varlen branch; I haven't benchmarked an upstream model.
🤖 Generated with Claude Code