Attnax
Attention kernels and transformer components for JAX.
Installation | Quick start | Documentation | Examples | Citation
Overview
Attnax is built on JAX and Flax and provides:
- Attention kernels as pure JAX functions sharing a single
AttentionFnprotocol:standard_attention,memory_efficient_attention,flash_attention,linear_attention,ring_attention,pallas_flash_attention,paged_attention,lite_attention. ScoreMod/MaskModconstructors for ALiBi, sliding window, prefix-LM, document masks, and arbitrary additive biases — composed withcompose_score_mods.MultiHeadAttentionwith MHA, GQA, MQA, RoPE, sliding window, and optional contiguous or paged KV caching (KVLayerCache,PagedKVCache).EncoderBlock,DecoderBlock,TransformerEncoder,TransformerDecoder,VisionTransformer,FeedForward,MixtureOfExperts,RMSNorm, RoPE and the usual positional embeddings.
Documentation on Attnax can be found at attnax.readthedocs.io.
Installation
pip install attnax
From source:
git clone https://github.com/glibtkachenko/attnax.git
cd attnax
pip install -e .
Requires Python 3.10+, JAX 0.10.0+, and Flax 0.12.7+.
Quick start
Attention kernels are pure JAX functions:
import jax, jax.numpy as jnp
from attnax import standard_attention
q = jax.random.normal(jax.random.key(0), (1, 4, 64, 32))
k = jax.random.normal(jax.random.key(1), (1, 4, 64, 32))
v = jax.random.normal(jax.random.key(2), (1, 4, 64, 32))
out = standard_attention(q, k, v)
Biases compose as ScoreMods:
from attnax import alibi_mod, compose_score_mods, sliding_window_mod
mod = compose_score_mods(
alibi_mod(num_heads=4),
sliding_window_mod(window_size=128, causal=True),
)
out = standard_attention(q, k, v, score_mod=mod)
Any kernel matching AttentionFn plugs into MultiHeadAttention:
import flax.nnx as nnx
from attnax import MultiHeadAttention, pallas_flash_attention
attn = MultiHeadAttention(
nnx.Rngs(0),
num_heads=8,
in_features=512,
attention_fn=pallas_flash_attention,
)
A full transformer stack:
from attnax import TransformerConfig, TransformerEncoder
config = TransformerConfig(
vocab_size=32000, d_model=512, num_heads=8, num_layers=6,
)
model = TransformerEncoder(nnx.Rngs(0), config)
y = model(jnp.ones((2, 16), dtype=jnp.int32), deterministic=True)
See the getting-started notebook for a walkthrough covering score-mods, custom kernels, KV caching, paged caching, Mixture-of-Experts, the Vision Transformer, and training.
Citing Attnax
@software{attnax2025github,
author = {Glib Tkachenko},
title = {{Attnax}: Attention Kernels and Transformer Components for {JAX}},
url = {https://github.com/glibtkachenko/attnax},
version = {0.2.0},
year = {2025},
}
Metadata
Release files for attnax 0.2.0
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 |
|---|---|---|---|---|
| attnax-0.2.0.tar.gz | 50.3 kB | With provenance | Details for attnax-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| attnax-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for attnax-0.2.0-py3-none-any.whl |
Total release size: 96.4 kB
Release files / attnax-0.2.0.tar.gz
| Download URL | attnax-0.2.0.tar.gz |
|---|---|
| Size | 50.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f25a45d975425b14eb8be20c3376000508cd7f342e7044b15ddae1417ebad2a1
|
|
BLAKE2b-256 checksum How to use checksums |
9e87b8d52f1b6b93d89b66ab0f97daeee50beeee2119e8dd358c24d4f82627a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 25, 2026.
Transparency logRelease files / attnax-0.2.0-py3-none-any.whl
| Download URL | attnax-0.2.0-py3-none-any.whl |
|---|---|
| Size | 46.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3ee1d9091f6fb84eb266b358edc709ad34987678a6013bc10b1cb1376eb926f
|
|
BLAKE2b-256 checksum How to use checksums |
4e4ed4ae07fec7a7462116958dbb3b463c52cd6af1ea83389574a2d5a9bb8586
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 25, 2026.
Transparency logSecurity for attnax 0.2.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for attnax-0.2.0.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 May 25, 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.