Repository navigation
Conversation
The sparse kernel used the query count as the key bound (offs_k < T) and built the block bitmap with ceil(T / block_size). Context parallelism holds a 1/cp_size query shard and the full key sequence. The CP path therefore copied the local queries into a buffer as long as the keys and filled the rest with -1. Those rows launch tiles and allocate a bitmap for the whole sequence, then the kernel skips them. The key bound and the bitmap width now follow k.shape[0]. The query grid still follows the query count. The CP path passes the local queries and the gathered keys directly. When the two lengths are equal, the bounds match the previous kernel. Checked with python3 -m pytest tests/test_qsa_key_length.py. Two queries and eight keys, block size 4, flag key index 6 in block 1. flake8 is clean. The Triton kernels were not executed here; triton is not installed.
hjh0119
reviewed
Oct 9, 2026
| big = torch.iinfo(torch.int32).max | ||
| lo = torch.where(valid, indices, torch.full_like(indices, big)).min(dim=1).values.to(torch.int32) | ||
| hi = torch.where(valid, indices, torch.full_like(indices, -1)).max(dim=1).values.to(torch.int32) | ||
| zeros = torch.zeros(T, dtype=torch.int32, device=q.device) |
Collaborator
There was a problem hiding this comment.
NameError: name 'T' is not defined
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.
The sparse kernel used the query count as the key bound (
offs_k < T) and built the block bitmap withceil(T / block_size). Context parallelism holds a 1/cp_size query shard and the full key sequence. The CP path therefore copied the local queries into a buffer as long as the keys and filled the rest with -1. Those rows launch tiles and allocate a bitmap for the whole sequence, then the kernel skips them.The key bound and the bitmap width now follow
k.shape[0]. The query grid still follows the query count. The CP path passes the local queries and the gathered keys directly. When the two lengths are equal, the bounds match the previous kernel.Checked with
python3 -m pytest tests/test_qsa_key_length.py. Two queries and eight keys, block size 4, flag key index 6 in block 1.flake8is clean. The Triton kernels were not executed here; triton is not installed.