Repository navigation
Bump attn-gym to 0.0.13 - #4854
Merged
Merged
Conversation
drisspg
force-pushed
the
drisspg/dsv4-deps
branch
2 times, most recently
from
September 24, 2026 02:06
ddfa90d to
5cef9ac
Compare
drisspg
force-pushed
the
drisspg/dsv4-deps
branch
from
September 24, 2026 02:24
5cef9ac to
fe9543d
Compare
drisspg
marked this pull request as ready for review
September 24, 2026 02:25
drisspg
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 24, 2026 02:25
tianyu-l
approved these changes
Sep 24, 2026
attn-gym 0.0.13 lets CuTe gather attention take 1..128 query heads and run on SM103, which DeepSeek-V4 CSA needs for its 64 heads and TP shards (with flash-attn-4>=4.0.0b32 installed). It also makes the gather_attn sink gradient and the lightning_indexer top-k deterministic under torch.use_deterministic_algorithms, which DeepSeek-V4 needs for bitwise reproducible runs with --debug.deterministic. Since 0.0.11, bound_gate and chunk_kda default to fastmath=True (#578), so Kimi K3 KDA now uses fast math. On GB300 its outputs and gradients differ from exact math by ~1.5e-4 relative RMS, well below bf16 resolution.
drisspg
force-pushed
the
drisspg/dsv4-deps
branch
from
September 24, 2026 03:20
fe9543d to
130ea9b
Compare
drisspg
added a commit
that referenced
this pull request
Sep 30, 2026
### Human note Lets gather attention the whole thang! Reason being is that flex doesnt have non triton 512 support so it uses triton for swa which is very slow. gather_attn i built for CSA, but SWA (empty top-k) and HCA (all causal compressed blocks) are just special cases of it, so this PR moves both onto it and drops FlexAttention from DSV4 entirely Massive speedups from this shown below with the fullstack at least for the lil setup I testd we are 8x >> in perf and would be much higher as we increase seqlens Why the extra memory mr driss? FA4 writes the softmax probabilities p as [tokens, heads, gathered keys] in bf16, and keeps for backward ( this We need the new version. In a newer fa4 we can configure this opiton if we want to save the memory; but it doesnt workyet for hdim<128 ## Agent Note Sliding-window and HCA layers no longer concatenate [swa_k, cmp_k, sink], build a FlexAttention BlockMask, and run compiled flex_attention. All three DeepSeek-V4 attention cores now call gather_attn and differ only in the compressed positions each query attends to: none for SWA, every causal compressed block for HCA, and the indexer's top-k for CSA. This matches the DeepSeek reference, which runs every layer through one gather-based sparse attention kernel. The Flex path was the dominant cost: at head_dim 512 each SWA/HCA layer runs dense-shaped attention over the full sequence to keep a 128-token window, and on GB300 default Flex kernels at head_dim 512 fault, forcing small tiles. FlexAttention's FLASH backend cannot take over either: it rejects the learnable sink captured in score_mod, and its block-sparse head_dim 512 kernel does not fit SM100 tensor memory. DSV4FlexInnerAttention becomes DSV4InnerAttention (an InnerAttention, not a FlexInnerAttention), dropping its block_size/kernel_options fields and the BlockMask builder. The wiring test covers SWA, HCA, and CSA against dense masked attention on CPU and CUDA; the BlockMask formulation test goes with the code it tested. ## Performance End to end, the full stack (#4854 -> #4858) is 7.9x faster than main on a 6-layer DeepSeek-V4-flash-shaped model (2x each of SWA, CSA, HCA; 64 heads, head_dim 512, 8 experts, seq 4096, bf16, 1x GB300, CUDA graphs). Both runs used the same config at the same time on full-clock GPUs. | | main `9e159aed7` (Flex, attn-gym 0.0.10) | this stack `028a9fb3d` (attn-gym 0.0.13) | |---|---|---| | tokens/s, steps 7-10 (higher is better) | 2,355 | **18,520** | | GPU time in annotated regions, step 10 (ms, lower is better) | 3,370.6 | **334.2** | | peak reserved memory | 96.24 GiB | 102.13 GiB | Attention-core GPU time per step, summed over the two layers of each type (ms, lower is better): | region | main | this stack | |---|---|---| | CSA core bwd / fwd | 2,089.6 / 27.3 | 7.0 / 3.1 | | HCA core bwd / fwd | 507.8 / 7.7 | 3.2 / 1.9 | | SWA core bwd / fwd | 407.6 / 7.6 | 2.2 / 1.3 | | CSA indexer.select | 8.8 | 0.6 | There is a massive difference in swa perf I think part of this is due to inefficient impl in triton btw Every non-attention region matches to within 0.1 ms. Caveat: on GB300, default Flex kernels at head_dim 512 fault, so main runs Flex with forced 32x32 tiles; a tuned Flex baseline would narrow the ratio. Merged before/after trace with per-layer region annotations (fwd and bwd): https://fburl.com/perfetto/dqoy5wdi --- <sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
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.
attn-gym 0.0.11 lets CuTe selected attention take 1..128 query heads and run
on SM103, which DeepSeek-V4 CSA needs for its 64 heads and TP shards. The
B200 lane installs flash-attn-4 4.0.0b32, the first release with sparse-MLA
head padding, the same way it installs torchao: explicitly, since neither is
a torchtitan dependency.
attn-gym 0.0.11 also flips the fastmath default of bound_gate and chunk_kda
to True (#578). Kimi K3 KDA now passes fastmath=False, which reproduces the
0.0.10 output and gradients bitwise on GB300.
Stack created with GitHub Stacks CLI • Give Feedback 💬