Repository navigation
[DSV4] Run CSA through Attention Gym gather_attn - #4855
Merged
Merged
Conversation
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
2 times, most recently
from
September 24, 2026 01:05
7c34c5e to
b23ee41
Compare
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
2 times, most recently
from
September 24, 2026 02:24
ad0b755 to
b88792d
Compare
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
from
September 24, 2026 03:20
b88792d to
2b412e6
Compare
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
from
September 24, 2026 03:59
2b412e6 to
67af3c9
Compare
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
from
September 24, 2026 14:28
67af3c9 to
6701f5b
Compare
drisspg
marked this pull request as ready for review
September 24, 2026 18:07
drisspg
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 24, 2026 18:07
This was referenced Sep 24, 2026
Merged
tianyu-l
approved these changes
Sep 25, 2026
Contributor
Author
|
Im going to do 1 more bump of attn-gym before landing since we I just got to tune tile sizes for a10g: meta-pytorch/attention-gym#593 |
CompressedSparseAttention (compress_ratio == 4) no longer concatenates [sliding-window KV, compressed KV, sink] and builds a FlexAttention BlockMask from the indexer top-k. It calls attn_gym.sparse.gather_attn, which fuses the sliding-window branch, the per-query top-k branch over the compressed KV, and the sink softmax denominator. The fused impl picks CuTe (FA4) for supported eager SM100/SM103 shapes and Triton otherwise; CPU uses the reference impl. Since CSA no longer calls FlexAttention, it moves off DSV4FlexInnerAttention onto a new DSV4InnerAttention(InnerAttention) base that owns only the fields gather_attn needs (window_size, compress_ratio, softmax_scale, index_topk) and the gather_attn call itself. The CSA branch and indexer arguments leave DSV4FlexInnerAttention._forward_impl, which now serves sliding-window and HCA layers only. A test checks the wiring (layouts, window, top-k indices, sink, and scale) against dense masked attention, forward and backward, on CPU (reference impl, fp64) and CUDA (fused impl, fp32). It lives under tests/unit_tests/gpu so the GPU unit-test job runs both cases. Kernel numerics are Attention Gym's to test. Bumps attn-gym to 0.0.14, whose Triton gather_attn tiles fit SM86 shared memory (the A10G CI lane runs the Triton backend) and Blackwell tensor memory. Based on #4452 by @floatingtrees. Co-authored-by: Jonathan Zhou <[email protected]>
drisspg
force-pushed
the
drisspg/dsv4-csa-selected-attention
branch
from
September 28, 2026 22:22
6701f5b to
c82a9c1
Compare
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.
Human notes
Step 1 we port over CSA to use the gather_attn impl; supports triton and routes to FA4 cute on B2/300 machines.
full e2e speedups in top of stack
Agent Notes
CompressedSparseAttention (compress_ratio == 4) no longer concatenates
[sliding-window KV, compressed KV, sink] and builds a FlexAttention BlockMask
from the indexer top-k. It calls attn_gym.sparse.selected_attention, which
fuses the sliding-window branch, the per-query top-k branch over the
compressed KV, and the sink softmax denominator. The fused impl picks CuTe
(FA4) for supported eager SM100/SM103 shapes and Triton otherwise; CPU uses
the reference impl. The CSA branch and indexer arguments leave
DSV4FlexInnerAttention._forward_impl, which now serves sliding-window and HCA
layers only.
The GPU test keeps an inline copy of the previous BlockMask formulation and
checks outputs and gradients match it at the default and a non-default
softmax_scale. A second test runs DSV4-shaped CSA (64 heads, head_dim 512,
bf16) through the FA4 CuTe kernels against the fp32 reference implementation
and fails if CuTe is unavailable. The B200 lane runs this file, since the GPU
unit-test lane (A10G) cannot reach the CuTe path.
Based on #4452 by @floatingtrees.
Co-authored-by: Jonathan Zhou [email protected]
Stack created with GitHub Stacks CLI • Give Feedback 💬