Skip to content

[CI deps] Bump attn-gym pin to v0.0.19 (0d0197fb) - #6017

Merged
shuhuayu merged 1 commit into
pytorch:mainfrom
shuhuayu:attn-gym-pin-0d0197f
Nov 11, 2026
Merged

shuhuayu merged 1 commit into
pytorch:mainfrom
shuhuayu:attn-gym-pin-0d0197f

Conversation

@shuhuayu

Copy link
Copy Markdown
Contributor

Why

The Qwen3.8-Flash-Next QSA attention (#5782) will use gather_attn's grouped-KV / separate-V Triton kernels. They first appear in attention-gym v0.0.19, after attention-gym #678, #701, #702, #713, #714, #715 and #703. torchtitan pins 26beb363, which predates all of these. This PR only bumps the pin; the Flash-Next change stays in #5782.

What changed (all mechanical)

Before After
attn-gym pin 26beb363 (#704 merge) 0d0197fb (v0.0.19 tag, #703 merge)
  • .ci/docker/requirements.txt (root requirements.txt symlinks to it): new SHA. The TODO now says to switch to the PyPI release once v0.0.19 is published there (PyPI's newest is 0.0.18). fix error in #701 #704, which the old TODO waited on, is already included in both pins.
  • torchtitan/models/common/attn_gym.py (install hint) and tests/unit_tests/cpu/models/common/test_optional_imports.py (2 asserts): same SHA.

Why v0.0.19 rather than attention-gym main

26beb363..0d0197fb changes only attn_gym/sparse/gather_attn (plus its tests and docs). I diffed the two installed attn_gym trees to confirm this. GDN, KDA, short_conv, the indexer, MLA and the CuTe backend are byte-identical, so qwen3_5, qwen3_8, kimi and the deepseek_v4 indexer can't change. main would also pull in the warpdrive rewrite and the indexer/delta-H ports (~28 _delta_rule files).

Numerics

The only gather_attn consumer is torchtitan/models/deepseek_v4/attention.py. Old vs new pin, 10 steps, seed 42, deterministic, loss and grad_norm read from TensorBoard via scripts/loss_compare.py, on GB300:

Config GPUs Result
deepseek_v4_debugmodel_fsdp4_ep4 (DistMuon) 4 bitwise identical*
deepseek_v4_debugmodel_fsdp2_tp2_ep2_pp2 with dp_shard=1 (host has 4 GPUs) 4 bitwise identical*

* With gather_attn's Triton tuners pinned to the same candidate in both runs. Without pinning, deepseek_v4 isn't run-to-run reproducible on either pin when the autotune cache is cold. _FWD_TMA and _BWD_DLOCAL_KV_TMA choose num_warps 4 vs 8 by timing, and the two give different bits. Ranks and cold-cache runs can pick different winners, and torch's deterministic flag doesn't control this. This already happens on main. I filed it upstream as meta-pytorch/attention-gym#777, with a single-GPU repro. Because of it, this PR adds no deepseek_v4 golden; see follow-ups.

Testing

  • pre-commit run --all-files passes, including pyrefly-check.
  • pytest tests/unit_tests/cpu/models/common plus the deepseek_v4, qwen3_5, qwen3_8 and kimi_k3 CPU tests: 416 passed. The same 9 tests fail with both the old and new pin on this aarch64 host (test_lora_forward and 8 qwen3_5 tests). The one I inspected, test_lora_forward, fails with "torch.compile on current platform is not supported for CPU".

Known issues / follow-ups

  • deepseek_v4 golden numerics: add once attention-gym#777 lets us fix the tile config. The golden then has to be exported on CI's A10G runners, not on GB300.

v0.0.19 adds gather_attn's grouped-KV / separate-V Triton kernels
(attention-gym pytorch#678, pytorch#701, pytorch#702, pytorch#713, pytorch#714, pytorch#715, pytorch#703), which the
Qwen3.8-Flash-Next QSA attention will use. Only attn_gym/sparse/gather_attn
changes between the two pins.
@pytorch-bot pytorch-bot Bot added ciflow/docker ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Nov 10, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026
shuhuayu added a commit to shuhuayu/torchtitan that referenced this pull request Nov 11, 2026
Replace the per-16-query checkpointed gather + MATH SDPA loop with one
gather_attn call: selected blocks and the incomplete tail are sparse KV
indices into the packed sequence (no sliding window), with separate values
and grouped KV heads. CUDA uses the fused kernel (Triton grouped schedule,
SM100/SM103); CPU uses the reference implementation, as in DeepSeek-V4.
The indexer and the no-grad indexer teacher are unchanged.

Requires the attn-gym pin at 0d0197fb (pytorch#6017) for sparse_v and the grouped
fused kernels.

Numerics (GB300, released 125B-A6B QSA shapes, T=4096, bf16 vs fp64 oracle,
relative error out/dq/dk/dv): fused 3.4e-3/4.4e-3/4.4e-3/3.6e-3, previous
eager 3.1e-3/4.0e-3/9.1e-3/8.2e-3. Fused outputs and gradients are bitwise
identical across processes and cold Triton caches. Forward+backward per QSA
layer: 3.3 ms vs ~10 s. Debug model, 2 GPUs, seed 42, 10 steps: losses match
to ~1e-3 (step 10: 7.49278 vs 7.49127).

Drop the attention test's saved-storage budget, which guarded the removed
checkpoint; keep its dense masked-SDPA output and gradient check.
@shuhuayu
shuhuayu merged commit b9abea0 into pytorch:main Nov 11, 2026
drisspg added a commit that referenced this pull request Nov 12, 2026
… API (#6063)

<!--
Reviewers need to be convinced, not just informed. Delete sections you
don't need.
Agents: follow .claude/skills/pr-description/SKILL.md. Never fill in the
Summary.
-->

## Summary (human-written)
bump the pin and make disable autotune under determ. we made some good
changes to kda and need to change
numeric ref

## Why
attention-gym v0.0.20 fixes meta-pytorch/attention-gym#777: kernels
whose launch configuration is picked by timing (the `gather_attn` Triton
kernels DeepSeek-V4 uses, among others) gave different output bits from
run to run, even under `torch.use_deterministic_algorithms(True)`. #6017
could not add a DeepSeek-V4 golden because of it. From v0.0.20, every
tuned attn-gym operation launches one fixed configuration in
deterministic mode.

The fix came with an API change (meta-pytorch/attention-gym#809):
`autotune` is no longer a keyword argument; it is a key of
`kernel_options`. torchtitan has to follow it to take the release.

**Example.**
```python
# before (v0.0.19): torchtitan decides whether to tune
autotune = not torch.are_deterministic_algorithms_enabled()
q = l2norm(q, autotune=autotune)
out, _ = chunk_kda(q, k, v, g, beta, cu_seqlens=cu, autotune=autotune, kernel_options=opts)

# after (v0.0.20): attn-gym pins its tuned kernels in deterministic mode itself
q = l2norm(q)
out, _ = chunk_kda(q, k, v, g, beta, cu_seqlens=cu, kernel_options=opts)
```

## What changed
| | Before | After |
| --- | --- | --- |
| attn-gym pin | git SHA `0d0197fb` (v0.0.19 tag) |
`attn-gym[linear,cudnn]==0.0.20` from PyPI (tag `7adfbadb`) |

- **Pin (mechanical):** `.ci/docker/requirements.txt` (root
`requirements.txt` symlinks to it), the install hint in
`torchtitan/models/common/attn_gym.py`, and 2 asserts in
`tests/unit_tests/cpu/models/common/test_optional_imports.py`. v0.0.20
is on PyPI, so the pin is a version again and the `TODO` about the git
pin is removed; PyPI no longer blocks a torchtitan release on this
dependency.
- **`l2norm`, `chunk_kda`**
(`models/common/attention/{gdn,kda,cp_gdn}.py`): drop `autotune=` and
the `autotune = not torch.are_deterministic_algorithms_enabled()` lines.
attn-gym applies the same rule.
- **`recurrent_gdn`** in batch-invariant mode
(`models/common/attention/gdn.py`, `rl/generator/attention/gdn.py`):
`kernel_options={"batch_invariant": True, "autotune": False}`, the same
request as before.
- **`paged_mla_decode`** (`rl/generator/vllm/attention/mla.py`):
`kernel_options={"autotune": True}`, the same request as before.
- **Test:**
`test_deterministic_backward_bypasses_normalization_autotuner` patched a
`triton.autotune` object that no longer exists. It now fails if any
attn-gym Triton kernel takes the tuned launch path in deterministic
mode.

## User-facing changes
| Before | After |
| --- | --- |
| `chunk_gdn`, `gather_attn`, the context-parallel KDA/GDN operations
and `paged_mla_decode` tuned by timing in deterministic mode | They
launch a fixed configuration in deterministic mode; unchanged otherwise
|
| Tuned winners cached on disk from v0.0.19 | Re-tuned once after the
upgrade (the cache key changed) |

## Numerics
v0.0.19 -> v0.0.20 changes `chunk_kda` bits, so the Kimi K3 golden
changes. I bisected the 12 attention-gym commits that touch the kernels
torchtitan calls, with tuning off and deterministic mode on (GB200,
torchtitan's call pattern: `bound_gate`, `l2norm`, `chunk_kda` forward
and all input gradients, BF16 and FP16):

| Kernel | v0.0.19 -> v0.0.20 |
| --- | --- |
| `l2norm`, `bound_gate`, `causal_conv1d`, `chunk_gdn` | bitwise
identical |
| `chunk_kda` BF16 forward and gradients | change (forward max abs diff
1.2e-4 on values up to 6e-2) |
| `chunk_kda` FP16 | only the gate gradient changes |

One commit causes all of it, and both changes are intended:
- meta-pytorch/attention-gym#764 rewrote the KDA forward intra-chunk
kernel with a different rebase point per 16-token strip. Its
measurements against FP64: unchanged error at typical gates, up to 5.4x
lower output error at gates near the documented bound.
- meta-pytorch/attention-gym#767 fixes the backward gate gradient at
gates steeper than about -5.82 nats per token, where one row in 16 lost
its in-strip terms.

The `kernel_options` change itself (#809) is bitwise identical to the
commit before it on this path.

`kimi_k3_mm_muon` (B200, 2 GPUs, FSDP=2, EP=2, exact golden):
`tests/assets/losses/real_pg/kimi_k3_b200.txt` is regenerated in this
PR. The values come from this branch's first B200 run, and the B200 run
on the commit with the new file reproduces them bit for bit.

| Step | Loss, old golden | Loss, attn-gym 0.0.20 | Grad norm, old |
Grad norm, new |
| --- | --- | --- | --- | --- |
| 1 | 8.107099533081055 | 8.107158660888672 | 2.890625 | 2.890625 |
| 2 | 7.700622081756592 | 7.69891357421875 | 4.09375 | 4.125 |
| 3 | 7.474788665771484 | 7.475809574127197 | 6.25 | 6.25 |
| 4 | 7.444936752319336 | 7.446145057678223 | 5.03125 | 5.03125 |
| 5 | 7.1190619468688965 | 7.12349796295166 | 8.5625 | 8.5 |
| 6 | 6.984208106994629 | 6.983041286468506 | 8.75 | 8.75 |
| 7 | 5.781412124633789 | 5.781435012817383 | 13.4375 | 13.4375 |
| 8 | 6.867074966430664 | 6.866772651672363 | 8.8125 | 8.8125 |
| 9 | 6.368958950042725 | 6.368622779846191 | 11.9375 | 11.9375 |
| 10 | 5.942665100097656 | 5.940550804138184 | 12.3125 | 12.3125 |

The largest loss difference is 0.0044 (step 5); the gradient norm
differs at steps 2 and 5. Runs: [old golden
mismatch](https://github.com/pytorch/torchtitan/actions/runs/43270645434),
[new golden
passes](https://github.com/pytorch/torchtitan/actions/runs/43273222858).

No other golden covers a model that calls KDA.

## Testing
On a GB200 with attn-gym at the v0.0.20 tag:
- `tests/unit_tests/gpu/models/common`,
`.../qwen3_5/test_qwen3_5_deltanet.py`, `.../deepseek_v4`,
`tests/unit_tests/cpu/models/common/test_optional_imports.py`: 149
passed. The 2 failures need the cuDNN backend, which that environment
lacks; they pass in an environment that has it.
- The rewritten determinism test fails when `l2norm` is made to ignore
deterministic mode, and passes otherwise.
- `pre-commit` passes except `pyrefly-check`, which is not installed
locally.

Not run locally (missing `vllm`, `monarch`, `openai`, `transformers`):
the RL generator tests, the Kimi K3 GPU tests and the integration tests.
CI is their first run against the new API.

## Known issues / follow-ups
- A DeepSeek-V4 golden is now possible (attention-gym#777 is fixed);
separate PR.
shuhuayu added a commit that referenced this pull request Nov 13, 2026
Replace the per-16-query checkpointed gather + MATH SDPA loop with one
gather_attn call: selected blocks and the incomplete tail are sparse KV
indices into the packed sequence (no sliding window), with separate values
and grouped KV heads. CUDA uses the fused kernel (Triton grouped schedule,
SM100/SM103); CPU uses the reference implementation, as in DeepSeek-V4.
The indexer and the no-grad indexer teacher are unchanged.

Requires the attn-gym pin at 0d0197fb (#6017) for sparse_v and the grouped
fused kernels.

Numerics (GB300, released 125B-A6B QSA shapes, T=4096, bf16 vs fp64 oracle,
relative error out/dq/dk/dv): fused 3.4e-3/4.4e-3/4.4e-3/3.6e-3, previous
eager 3.1e-3/4.0e-3/9.1e-3/8.2e-3. Fused outputs and gradients are bitwise
identical across processes and cold Triton caches. Forward+backward per QSA
layer: 3.3 ms vs ~10 s. Debug model, 2 GPUs, seed 42, 10 steps: losses match
to ~1e-3 (step 10: 7.49278 vs 7.49127).

Drop the attention test's saved-storage budget, which guarded the removed
checkpoint; keep its dense masked-SDPA output and gradient check.
shuhuayu added a commit that referenced this pull request Nov 17, 2026
Replace the per-16-query checkpointed gather + MATH SDPA loop with one
gather_attn call: selected blocks and the incomplete tail are sparse KV
indices into the packed sequence (no sliding window), with separate values
and grouped KV heads. CUDA uses the fused kernel (Triton grouped schedule,
SM100/SM103); CPU uses the reference implementation, as in DeepSeek-V4.
The indexer and the no-grad indexer teacher are unchanged.

Requires the attn-gym pin at 0d0197fb (#6017) for sparse_v and the grouped
fused kernels.

Numerics (GB300, released 125B-A6B QSA shapes, T=4096, bf16 vs fp64 oracle,
relative error out/dq/dk/dv): fused 3.4e-3/4.4e-3/4.4e-3/3.6e-3, previous
eager 3.1e-3/4.0e-3/9.1e-3/8.2e-3. Fused outputs and gradients are bitwise
identical across processes and cold Triton caches. Forward+backward per QSA
layer: 3.3 ms vs ~10 s. Debug model, 2 GPUs, seed 42, 10 steps: losses match
to ~1e-3 (step 10: 7.49278 vs 7.49127).

Drop the attention test's saved-storage budget, which guarded the removed
checkpoint; keep its dense masked-SDPA output and gradient check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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