Skip to main content

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.

Two new Flexys—Sparse Attention and Linear Attention—enter Attention Gym while the original Flexys train

🎯 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:

  1. Compose FlexAttention building blocks. Import mask_mod and score_mod functions and pass them directly to PyTorch's FlexAttention APIs.
  2. 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.
  3. 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

  1. Create a new file in the attn_gym/masks/ for mask_mods or attn_gym/mods/ for score_mods.
  2. Implement your function, and add a simple main function that showcases your new function.
  3. Update the attn_gym/*/__init__.py file to include your new function.
  4. 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.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for attn-gym 0.0.15
File Size Uploaded
attn_gym-0.0.15.tar.gz 3.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for attn-gym 0.0.15
File Interpreter ABI Platform
attn_gym-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 4.8 MB

Release files / attn_gym-0.0.15.tar.gz

Download URL attn_gym-0.0.15.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
f3d58539073283826f9fe454226f8037e013c9e41bc33fb1120565310db90ba7
BLAKE2b-256 checksum
How to use checksums
f799fb62e1fdc91d113f13acda627b3c91851a9696b40f73e90689a2f32b798f
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 2, 2026.

Transparency log

Release files / attn_gym-0.0.15-py3-none-any.whl

Download URL attn_gym-0.0.15-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1ae538b8ab99c4ddbe92bff1539426e32a486e66cd86c7ad3d32b70c70443f00
BLAKE2b-256 checksum
How to use checksums
9b95f5736eb6e71bf12c7851125dc5a0614eb8392c7e5285d4ac9c71e5eff71f
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 2, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.17

2 release files

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page