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
[!WARNING] Attention Gym is under active development. We reserve the right to make backward-incompatible changes between releases. If you depend on a particular API or kernel behavior, hard-pin the version you test, for example:
pip install "attn-gym[linear]==X.Y.Z".
💻 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
selected_attention, GDN and KDA chunk, recurrent, and decode paths, and short-convolution primitives. See the compressed sparse attention and KDA 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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file attn_gym-0.0.7.tar.gz.
File metadata
- Download URL: attn_gym-0.0.7.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99cd65d33036748e1eaf7ca6428576c8e5faa5f3bd37aedc4671e108a6e3f5f3
|
|
| MD5 |
3e041bae44dbe6955e34420703cb3f52
|
|
| BLAKE2b-256 |
f50f905b8da79cfaf7163a2bbfc6abdf0513125bf9fac619106bab128562e6b9
|
Provenance
The following attestation bundles were made for attn_gym-0.0.7.tar.gz:
Publisher:
publish-to-pypi.yml on meta-pytorch/attention-gym
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
attn_gym-0.0.7.tar.gz -
Subject digest:
99cd65d33036748e1eaf7ca6428576c8e5faa5f3bd37aedc4671e108a6e3f5f3 - Sigstore transparency entry: 2690989848
- Sigstore integration time:
-
Permalink:
meta-pytorch/attention-gym@b56ea8e7021d6b6ef610001e80cf85f24f6ed2dd -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/meta-pytorch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@b56ea8e7021d6b6ef610001e80cf85f24f6ed2dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file attn_gym-0.0.7-py3-none-any.whl.
File metadata
- Download URL: attn_gym-0.0.7-py3-none-any.whl
- Upload date:
- Size: 667.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f36ca9ea63b1170ddac51cada0fbab724c284698509358de38a18be94ab44d81
|
|
| MD5 |
ced3eb772ea01c744b3332ac32853bdb
|
|
| BLAKE2b-256 |
5eb79dd255c84752eb095e370887df2f6582af86880ce7b59928cefac44d7dff
|
Provenance
The following attestation bundles were made for attn_gym-0.0.7-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on meta-pytorch/attention-gym
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
attn_gym-0.0.7-py3-none-any.whl -
Subject digest:
f36ca9ea63b1170ddac51cada0fbab724c284698509358de38a18be94ab44d81 - Sigstore transparency entry: 2690990072
- Sigstore integration time:
-
Permalink:
meta-pytorch/attention-gym@b56ea8e7021d6b6ef610001e80cf85f24f6ed2dd -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/meta-pytorch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@b56ea8e7021d6b6ef610001e80cf85f24f6ed2dd -
Trigger Event:
push
-
Statement type: