Attention Gym
Attention Gym is a collection of kernels, guides, and examples for FlexAttention and other novel attention variants.
📚 Docs | 🎯 Features | 🚀 Getting Started | 💻 Usage | 🛠️ Dev | 🤝 Contributing | ⚖️ License
📖 Overview
Attention Gym began as a library of examples showing the many ways to express attention variants with the FlexAttention API. It is growing into a broader playground for attention, with the addition of sparse attention kernels, linear attention APIs for training and inference as well as showcasing how to use FlexAttention and friends in real workloads.
🎯 Features
- FlexAttention masks and score modifications
- Sparse attention patterns
- APIs and kernels for efficient GDN and KDA
- Utility functions for creating and combining attention masks
- Examples of how to use FlexAttention in real-world scenarios
🚀 Getting Started
Prerequisites
- PyTorch (version 2.5 or higher)
Installation
Install the official wheel from PyPI:
pip install attn-gym
The base package intentionally keeps its runtime dependency surface small: it depends only on PyTorch (unpinned). Optional features live behind extras, so install only what you need:
pip install "attn-gym[linear]" # Linear-attention APIs and kernels
pip install "attn-gym[viz]" # Visualization and example dependencies
💻 Usage
Attention Gym supports three complementary workflows:
- Compose FlexAttention building blocks. Import
mask_modandscore_modfunctions and pass them directly to PyTorch's FlexAttention APIs. - Use sparse and linear-attention APIs and kernels. Build with
gather_attn, GDN and KDA chunk, recurrent, and decode paths, and short-convolution primitives. See the compressed sparse attention and delta-rule (KDA/GDN) training for working examples. - Run real workloads and benchmarks. The
examples/directory covers paged, ring, and variable sparse attention, CUDA Graphs, determinism, compilation, and profiling. Most of this should serve as inspiration for fun things you might build from our building blocks :)
🛠️ Dev
Install dev requirements
pip install -e ".[dev]"
Install and run the repository hooks:
prek install
prek run --all-files
🤝 Contributing
We welcome contributions to Attention Gym, especially new Masks or score mods! Here's how you can contribute:
Contributing Mods
- Create a new file in the attn_gym/masks/ for mask_mods or attn_gym/mods/ for score_mods.
- Implement your function, and add a simple main function that showcases your new function.
- Update the
attn_gym/*/__init__.pyfile to include your new function. - Optionally, add an end-to-end example using your new function in the examples/ directory.
See CONTRIBUTING.md for more details.
⚖️ License
Attention Gym-authored code is released under the BSD 3-Clause License. Vendored third-party components retain the licenses and notices included alongside their source.
Metadata
Release files for attn-gym 0.0.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| attn_gym-0.0.17.tar.gz | 3.8 MB | With provenance | Details for attn_gym-0.0.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| attn_gym-0.0.17-py3-none-any.whl | Python 3 | none | any | Details for attn_gym-0.0.17-py3-none-any.whl |
Total release size: 4.8 MB
Release files / attn_gym-0.0.17.tar.gz
| Download URL | attn_gym-0.0.17.tar.gz |
|---|---|
| Size | 3.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86a6cf8a8c45c86f9a0f61bd2d33af429a346e7f11280db6d6cf1f0524f14e2b
|
|
BLAKE2b-256 checksum How to use checksums |
c594f7536f6314f5f0811e0636c79b7779a07fd1de7597f3f62bf59864682a6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logRelease files / attn_gym-0.0.17-py3-none-any.whl
| Download URL | attn_gym-0.0.17-py3-none-any.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f5365723f58a8f27d4872b170c7f6aa71cdb2af5a98860f76b5adfe85323d64
|
|
BLAKE2b-256 checksum How to use checksums |
d94855cdc87d7bddeae9ef679f97338f71deee0bc81ed1d396708e30ed30cbc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logSecurity for attn-gym 0.0.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for attn_gym-0.0.17.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.