| Documentation | Paper | Blog | Latest Release | PyPI |
FlyWheel is an attention kernel library for TPU, written in JAX Pallas by heavyball-research. It implements softmax attention (MHA and MQA/GQA) behind flash-attn's API, and the fused linear attention layers of hybrid models (GDN and KDA), for prefill, decode and training on TPU v6e and v7x.
Why FlyWheel?
- Fast: up to 2.32x over RPA v3 on chunked prefill over a paged KV cache (v7x), and 2.25x over RPA v3 and 1.47x over Splash Attention on 16K sliding window prefill (v6e). See the benchmarks.
- flash-attn API:
flash_attn_func,flash_attn_varlen_funcandflash_attn_with_kvcachekeep flash-attn's names and arguments, and take and return JAX arrays. - Serving-ready: paged bf16 and fp8 KV caches, chunked prefill, prefix caching and speculative verify windows.
Core Features
Softmax Attention
- Prefill: dense, varlen (packed sequences), and chunked prefill over a paged KV cache
- Decode: paged or contiguous KV cache, with the K/V append fused into the kernel; speculative verify windows run on the decode kernel
- KV cache formats: bf16, or an fp8 (e4m3, e5m2) paged cache with per-tensor descales
- Attention variants: causal, sliding window that skips fully masked
tiles, softcap, attention sinks (
learnable_sink), and fused rotary embedding - Backward:
jax.gradruns a Pallas backward kernel for MHA and MQA/GQA with causal or full masks
Linear Attention
- Fused GDN and KDA: causal conv1d + silu and the chunked delta rule in one kernel, for Gated DeltaNet (e.g. Qwen3-Next) and Kimi Delta Attention (e.g. Kimi Linear)
- Ragged serving batches: decodes and prefills in one call, with per-request conv and recurrent states in slot caches, prefix caching and speculative verify windows
- ReplaySSM decode: decode from a state checkpoint plus the records of recent tokens, as in ReplaySSM
News
- [2026/11] v0.4.1: optimized decode kernel and GDN conv pools
- [2026/11] Paper on arXiv: FlyWheel: Attention Kernels Built for the TPU
- [2026/10] v0.4.0: fp8 paged KV cache, speculative verify windows on the decode kernel, and attention sinks
- [2026/10] tpu-inference adds FlyWheel as
--attention-backend flywheel(#3837) - [2026/10] v0.3.0: sliding window prefill that skips masked tiles, sliding window and softcap on the paged KV cache, and ReplaySSM decode for GDN/KDA
- [2026/10] v0.2.0: faster chunked prefill, prefix caching and decode over a paged KV cache
- [2026/10] TPU v7x results. Thanks to lk-chen for testing and contributing them!
- [2026/09] v0.1.0: flash-attn-style softmax attention (forward and backward, varlen, KV cache) and fused GDN/KDA linear attention
Getting Started
Installation
pip install flywheel-tpu # CPU, Pallas interpret mode
pip install "flywheel-tpu[tpu]" # TPU VM, adds jax[tpu]>=0.11.2
From source, with uv (needed for the benchmarks and the end-to-end evaluation):
git clone https://github.com/heavyball-research/flywheel-tpu.git && cd flywheel-tpu
uv sync --extra tpu # plain `uv sync` off TPU
source .venv/bin/activate
Quick Start
import jax
import jax.numpy as jnp
from flywheel_tpu import flash_attn_func, flash_attn_with_kvcache
kq, kk, kv = jax.random.split(jax.random.key(0), 3)
# Causal GQA prefill: 32 query heads share 4 KV heads.
# Layout is head-major, (batch, heads, seqlen, head_dim).
q = jax.random.normal(kq, (1, 32, 4096, 128), jnp.bfloat16)
k = jax.random.normal(kk, (1, 4, 4096, 128), jnp.bfloat16)
v = jax.random.normal(kv, (1, 4, 4096, 128), jnp.bfloat16)
out = flash_attn_func(q, k, v, causal=True) # (1, 32, 4096, 128)
# One decode step for 8 sequences: append the new K/V to the cache and attend,
# in one kernel. The cache is token-major, (batch, max_len, heads_k, head_dim),
# and is updated in place: rebind the returned caches.
k_cache = jax.random.normal(kk, (8, 8192, 4, 128), jnp.bfloat16)
v_cache = jax.random.normal(kv, (8, 8192, 4, 128), jnp.bfloat16)
cache_seqlens = jnp.array([4096, 100, 2000, 8000, 1, 512, 3000, 7000], jnp.int32)
q_new = jax.random.normal(kq, (8, 1, 32, 128), jnp.bfloat16)
k_new = jax.random.normal(kk, (8, 1, 4, 128), jnp.bfloat16)
v_new = jax.random.normal(kv, (8, 1, 4, 128), jnp.bfloat16)
out, k_cache, v_cache = flash_attn_with_kvcache(
q_new, k_cache, v_cache, k_new, v_new, cache_seqlens=cache_seqlens, causal=True
) # out: (8, 1, 32, 128)
Off TPU, pass interpret=True to run the Pallas TPU interpreter.
Documentation
- API reference: every argument of the softmax and linear attention kernels, and where the layouts differ from flash-attn's
- Benchmarks on v6e, and the v7x results
- End-to-end evaluation: reproduce the paper's RULER, BABILong and Video-MME results with vLLM
Adoption
FlyWheel powers attention in:
-
tpu-inference (vLLM on TPU), as
--attention-backend flywheel:VLLM_WORKER_MULTIPROC_METHOD=fork vllm serve Qwen/Qwen3.5-0.8B --attention-backend flywheel
Acknowledgement
FlyWheel's API follows FlashAttention. Its GDN and KDA kernels start from tpu-inference's GDN v3 kernel, and its design draws on tpu-inference's RPA v3, Tokamax's Splash Attention and ReplaySSM.
Citation
If you find FlyWheel helpful in your project or research, please cite our paper:
@misc{bao2026flywheelattentionkernelsbuilt,
title={FlyWheel: Attention Kernels Built for the TPU},
author={Zishuo Bao and Zeshen Zhang and Linkun Chen and Yucheng Lu},
year={2026},
eprint={2611.01426},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2611.01426},
}
Metadata
Release files for flywheel-tpu 0.4.1
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 |
|---|---|---|---|---|
| flywheel_tpu-0.4.1.tar.gz | 230.1 kB | Without provenance | Details for flywheel_tpu-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flywheel_tpu-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for flywheel_tpu-0.4.1-py3-none-any.whl |
Total release size: 485.0 kB
Release files / flywheel_tpu-0.4.1.tar.gz
| Download URL | flywheel_tpu-0.4.1.tar.gz |
|---|---|
| Size | 230.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c15b4a8c74ecd431a8f0c27831aafba95fdee593a3763406919a5fb17136b253
|
|
BLAKE2b-256 checksum How to use checksums |
029a1c40c6d07bf352745e17bc9badf932b957d7c9c8a4ff6dfc059fcbe0285b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / flywheel_tpu-0.4.1-py3-none-any.whl
| Download URL | flywheel_tpu-0.4.1-py3-none-any.whl |
|---|---|
| Size | 254.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7bee2806b40b5771aa8ea6459a0e642ee5b22a64021bfd5b5e93a697693abf77
|
|
BLAKE2b-256 checksum How to use checksums |
ee0c4701ecfd8630ad9cb31b59ab02e22cf3e4b233347e7984f21d4d316fbf0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for flywheel-tpu 0.4.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.