Skip to content

Bump attn-gym to 0.0.13 - #4854

Merged
drisspg merged 1 commit into
mainfrom
drisspg/dsv4-deps
Sep 24, 2026
Merged

drisspg merged 1 commit into
mainfrom
drisspg/dsv4-deps

Conversation

@drisspg

@drisspg drisspg commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

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 💬

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@drisspg
drisspg added this pull request to stack #4857 September 24, 2026 00:25
@drisspg
drisspg force-pushed the drisspg/dsv4-deps branch 2 times, most recently from ddfa90d to 5cef9ac Compare September 24, 2026 02:06
@drisspg drisspg changed the title Bump attn-gym to 0.0.11 and install FlashAttention-4 on B200 Bump attn-gym to 0.0.12 and install FlashAttention-4 on B200 Sep 24, 2026
@drisspg drisspg changed the title Bump attn-gym to 0.0.12 and install FlashAttention-4 on B200 Bump attn-gym to 0.0.12 Sep 24, 2026
@drisspg
drisspg marked this pull request as ready for review September 24, 2026 02:25
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label 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 drisspg changed the title Bump attn-gym to 0.0.12 Bump attn-gym to 0.0.13 Sep 24, 2026
@drisspg
drisspg merged commit 223ef63 into main Sep 24, 2026
19 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants