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
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.

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".
Attention Gym supports three complementary workflows:
mask_mod and score_mod functions and pass them directly
to PyTorch's FlexAttention APIs.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.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 :)Install dev requirements
pip install -e ".[dev]"
Install and run the repository hooks:
prek install
prek run --all-files
We welcome contributions to Attention Gym, especially new Masks or score mods! Here's how you can contribute:
attn_gym/*/__init__.py file to include your new function.See CONTRIBUTING.md for more details.
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.
Python
100.0%
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
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.

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".
Attention Gym supports three complementary workflows:
mask_mod and score_mod functions and pass them directly
to PyTorch's FlexAttention APIs.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.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 :)Install dev requirements
pip install -e ".[dev]"
Install and run the repository hooks:
prek install
prek run --all-files
We welcome contributions to Attention Gym, especially new Masks or score mods! Here's how you can contribute:
attn_gym/*/__init__.py file to include your new function.See CONTRIBUTING.md for more details.
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.
Python
100.0%