2026-11-26 15:48 UTC

FLAT reports up to 3.08× faster linear-attention training on one TPU v6e than H100 FLA

state: seedheat: mediumuncertainty: mediumrelevance: highattention-optimization tpu inference-acceleration linear-attentionTrainStation projectopen-lm-engine

What is this?

TrainStation’s FLAT is an open-source set of Pallas kernels for training linear attention, Mamba-2 and gated linear attention (GLA) on Google TPU v6e, plus a short causal-convolution kernel. The project reports that, at one specified bf16 workload shape, one v6e chip beats an NVIDIA H100 running FLA by up to 3.08× across forward and backward for GLA; the reported advantage is smaller for linear attention and Mamba-2. These are project-reported device-time benchmarks, not evidence of an across-the-board advantage or a separate inference benchmark. The authors say support for DeltaNet, Gated DeltaNet and Kimi Delta Attention is future work.

Why it matters

FLAT is a notable open-source TPU-kernel release: it reports that carefully tuned Pallas kernels can make one TPU v6e outperform an H100 on selected linear-attention training workloads, despite the TPU’s lower measured memory bandwidth. This matters for teams choosing hardware and for the growing ecosystem of non-softmax sequence models. But the headline is a project-reported result at one benchmark shape—not a general TPU advantage, an independent replication, or an inference comparison. The supported kernels also do not yet cover DeltaNet, Gated DeltaNet or Kimi Delta Attention, which the authors identify as future work.

Current assessment

TrainStation’s FLAT provides Pallas kernels for Linear Attention, Mamba-2 and Gated Linear Attention (GLA), plus a short causal-convolution kernel, for training on a single Google TPU v6e. The project reports bf16 device-time comparisons at B=8, S=4096, 16 heads and K=V=128 against FLA on an H100: across forward and backward, FLAT is 1.59× faster for Linear Attention, 1.50× for Mamba-2 and 3.08× for GLA. In a full training-layer comparison, adding its recurrence and convolution kernels yields 2.12×, 2.18× and 2.75× speedups, respectively, over the project’s plain-JAX baseline. The authors attribute the gains to TPU-specific kernel design, including batching heads into systolic-array operations and keeping recurrent state on-chip; they also report that some individual kernels approach the v6e memory-bandwidth ceiling. The release is useful evidence that custom kernels can change the hardware comparison for particular workloads, and may make TPU training more attractive where the model and stack fit. Important limits: these are author-reported measurements on one TPU generation and one main workload shape, with no independent replication in the supplied evidence; the comparison is device time, not a full system cost or throughput-per-dollar analysis. FLAT is presented as training support, so the cited results do not establish inference speedups. The authors say DeltaNet, Gated DeltaNet and Kimi Delta Attention kernels are still future work, and other TPU generations and multi-chip scaling remain untested. Web results include social posts repeating the project’s claims, not independent validation.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady1 platformsage 1018h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

10-15 04:54⭐ origin directly observedFLAT: Flash Linear Attention on TPUs
matt_d on hacker news
—
10-15 04:54amplified on hacker news 👑hn.story.50099321
matt_d
peak 1 · 0 comments · 103% of case engagement
10-15 05:20our radar first saw it · +0.4hdiscovery anchor: hn.story.50099321—
pace: p10 vs 879 stories at the 720h mark (now 1018h old) — behind agent-detects-silent-email-failures (0.5x)

Evidence (1) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hn ⭐FLAT: Flash Linear Attention on TPUs
Retrieved article excerpt

Open article · Retrieved 2026-10-15T06:26:39.633072+00:00

# Introduction

While the Transformer architecture [[1](https://trainstation-project.github.io/blog/flat/#user-content-fn-attention)] has gained immense adoption, recent production LLMs have adopted variants of Linear Attention [[2](https://trainstation-project.github.io/blog/flat/#user-content-fn-linearattention)]: Kimi K3 [[3](https://trainstation-project.github.io/blog/flat/#user-content-fn-k3)] uses Kimi Delta Attention [[4](https://trainstation-project.github.io/blog/flat/#user-content-fn-kda)], and Qwen 3.5 [[5](https://trainstation-project.github.io/blog/flat/#user-content-fn-qwen-3.5)] interleaves Gated DeltaNet [[6](https://trainstation-project.github.io/blog/flat/#user-content-fn-gdn)] layers with full attention. A linear attention layer replaces attention’s KV-cache, which grows with the context, with a fixed-size recurrent state, so generating a token takes constant time and memory and training costs O(T)O(T)O(T) in the context length TTT.

While GPUs have fast kernels for these layers, such as [FLA (flash-linear-attention)](https://github.com/fla-org/flash-linear-attention) and [Mamba’s CUDA kernels](https://github.com/state-spaces/mamba), Google’s TPUs [[7](https://trainstation-project.github.io/blog/flat/#user-content-fn-tpu2), [8](https://trainstation-project.github.io/blog/flat/#user-content-fn-tpu4)] do not.
Recent TPU work targets inference [[9](https://trainstation-project.github.io/blog/flat/#user-content-fn-tpu-megakernels), [10](https://trainstation-project.github.io/blog/flat/#user-content-fn-flywheel)]; we know of no open-source kernels for *training* these layers on TPUs.
We release [FLAT: Flash Linear Attention on TPUs](https://github.com/open-lm-engine/accelerated-model-architectures), Pallas implementations of Linear Attention [[2](https://trainstation-project.github.io/blog/flat/#user-content-fn-linearattention)], Mamba-2 [[11](https://trainstation-project.github.io/blog/flat/#user-content-fn-mamba2)], and Gated Linear Attention (GLA) [[12](https://trainstation-project.github.io/blog/flat/#user-content-fn-gla)] for TPUs, benchmarked on a [TPU v6e (Trillium) chip](https://docs.cloud.google.com/tpu/docs/v6e). We also release a fast Pallas kernel for the short causal convolution that most linear attention layers apply before the recurrence. Counting the forward and backward together, FLAT on one TPU v6e chip is up to 3×3\times3× faster than FLA on an NVIDIA H100 ([Figure ?](https://trainstation-project.github.io/blog/flat/#fig-la-h100)): 1,982 µs against 6,106 µs for GLA, 1.6×1.6\times1.6× faster for Linear Attention and 1.5×1.5\times1.5× faster for Mamba-2. We use these kernels to train [Rigel](https://open-lm-engine.github.io/blog/rigel/) [[13](https://trainstation-project.github.io/blog/flat/#user-content-fn-mishra2026rigel)] on TPU chips.

Writing these kernels for a TPU turned out to be a different problem from writing them for a GPU ([Section ?](https://trainstation-project.github.io/blog/flat/#gpus-vs-tpus)). Three things kept getting in our way:

1. **The VPU is slow.** The vector unit (VPU) is much slower than the matrix unit (MXU). We measured about 7 TFLOP/s on the VPU, while the MXU is rated at 918 TFLOP/s, and every exponential, mask and prefix sum in linear attention has to run on the VPU.
2. **Instruction slots run out.** There are only so many slots per cycle. The compiler schedules everything ahead of time into fixed-width bundles, so vector math, loads, stores and register spills all compete for the same slots. Once a kernel isn’t waiting on memory, its runtime is simply the number of bundles it issues.
3. **Per-head matmuls are too small.** The MXU is large, and the matmuls in a single head are small. If you issue one matmul per head, most of the systolic array sits idle.

Most of our speedups come from three ideas:

1. **Pack heads into the MXU.** We pack several heads (4, or 8 for GLA) into each MXU matmul instead of running them one at a time.
2. **Do scans on the MXU.** We move the prefix sums over the decay gates off the VPU and onto the MXU, by writing each one as a multiplication with a triangular matrix of ones.
3. **Keep the state on-chip.** Since a v6e chip has a single core, we fuse the state passing and the output into one kernel and keep the recurrent state in VMEM for the whole sequence. FLA on a GPU, by contrast, writes every chunk’s state to HBM and reads it back.

We aim to release training kernels for DeltaNet [[14](https://trainstation-project.github.io/blog/flat/#user-content-fn-deltanet)], Gated DeltaNet [[6](https://trainstation-project.github.io/blog/flat/#user-content-fn-gdn)] and Kimi Delta Attention [[4](https://trainstation-project.github.io/blog/flat/#user-content-fn-kda)] soon.

Device time of every kernel in the forward and the backward (lighter shades) at B=8,S=4096,N=16,K=V=128B{=}8, S{=}4096, N{=}16, K{=}V{=}128B=8,S=4096,N=16,K=V=128 at bf16 precision colored by the role it plays: FLA on H100 vs FLAT on TPU v6e. FLA splits each pass into several kernels to keep the H100’s 132 SMs busy, writing intermediate states to HBM and reading them back in both the forward and the backward. FLAT’s forward is one kernel that keeps the state in VMEM; its backward is two kernels, one that recomputes the chunk states and one that computes the q,k,vq, k, vq,k,v and gate gradients together.

## GPUs vs TPUs

**GPUs** are built from many streaming multiprocessors (SMs), 132 on an H100. Each SM runs many warps of SIMT threads and has tensor cores for matrix multiplies. Its hardware warp schedulers choose a ready warp every cycle, so when one warp stalls on memory, another runs in its place.

**TPUs** are built around the **MXU**, a large systolic array for matrix multiplies. A v6e chip has one TensorCore with two 256×256256 \times 256256×256 MXUs; everything else (elementwise math, reductions, data shuffling) runs on a vector unit, the **VPU**. There is no hardware scheduler: the compiler (XLA, or Mosaic for Pallas kernels) schedules the whole program ahead of time into a static VLIW instruction stream.

#### How a TPU core runs a kernel

Each cycle, a v6e TensorCore issues one instruction *bundle*\*NoteA bundle can be thought of as one wide instruction. with fixed slots: scalar, vector ALU (VPU), transcendental (EUP), cross-lane (rotates, transposes, lane reductions), VMEM loads and stores, and the MXU. A separate DMA engine copies data between HBM and VMEM in the background. Nothing is reordered at runtime, so two pieces of work overlap only if the kernel exposes them as independent.

1. **Registers are 2-D tiles**: a vector register is a grid of 8 sublanes × 128 lanes of 32-bit values (16 sublanes for packed `bf16`), and an array’s last two dimensions are laid out onto that grid. A slice that starts on a 128-lane boundary costs nothing, because it is just a different register. Moving data between sublanes, where consecutive positions of the sequence sit, costs a rotate and a select for every register, and odd shifts of packed `bf16` need extra bit manipulation (6,341 such ops per grid step in our first convolution backward). This matters for our causal convolution kernels.
2. **The MXU is weight-stationary**: one operand is loaded into the array and stays there while the other flows through it. A small matmul pays for that load and then does little work, so our kernels batch several heads into each dot.
3. **Time is bundles, unless it is bytes**: a kernel that is not waiting on HBM runs for (bundles issued) × (clock). The first and final versions of our convolution backward issue 13,016 and 11,617 bundles per grid step; over 64 steps, both match their measured times (486.7 and 431.1 µs) at the same ~1.7 GHz. So the question for any kernel is which resource runs out first: HBM bandwidth, vector slots, store slots (register spills compete with real stores), or the MXU.

#### Why linear attention is hard on a TPU

GPU kernels for linear attention rely on hardware a TPU does not have, so they cannot simply be translated. The features above turn into three problems:

1. **The matmuls are small.** One head’s chunk works on C×CC \times CC×C, C×VC \times VC×V and K×VK \times VK×V blocks, and each chunk’s state depends on the previous one. Every block is small next to the MXU, and a weight-stationary array charges for loading each one. Our first kernels issued one dot per head and the MXU sat waiting; batching several heads into each dot fixed that.
2. **Everything else competes for vector slots.** The decay exponentials, the causal mask, the convolution and SiLU are all vector work, sharing each bundle’s slots with loads, stores and register spills. A GPU overlaps such work with its tensor cores across many warps; on a TPU it adds straight to the bundle count. Our convolution backward was limited by exactly this, and Flywheel Attention [[10](https://trainstation-project.github.io/blog/flat/#user-content-fn-flywheel)] hits the same limit with softmax. Inferact’s Kimi K3 megakernel [[9](https://trainstation-project.github.io/blog/flat/#user-content-fn-tpu-megakernels)] even had to spread residual adds and norms across chips at small batch sizes.
3. **The layout is chosen once.** Tiles and DMA windows align to fixed shapes, so a kernel must commit to where heads and positions live, and an input that arrives in another layout has to be copied first. In a full layer these copies cost us 1.8 ms per step ([Section ?](https://trainstation-project.github.io/blog/flat/#full-linear-attention-layer)).

One property of the TPU works in our favor. A GPU kernel has to spread its work over many SMs, so FLA computes the chunk states in one kernel, writes them to HBM, and reads them back in a second kernel to produce the output. A v6e chip has a single core, and the kernel itself decides what stays in its VMEM, so our forward keeps the recurrent state in VMEM for the whole sequence and computes the states and the output in one kernel ([Figure ?](https://trainstation-project.github.io/blog/flat/#fig-la-h100)). Inferact’s megakernel relies on the same property to prefetch the next layer’s weights into VMEM while the current layer runs [[9](https://trainstation-project.github.io/blog/flat/#user-content-fn-tpu-megakernels)].

## Benchmark Setup

All our measurements are taken on a single TPU v6e chip and report device time. Per-op breakdowns sum each op’s device time from an XProf trace.
Unless stated otherwise, inputs and outputs are in `bf16` [[15](https://trainstation-project.github.io/blog/flat/#user-content-fn-bf16)], and accumulations and reductions are in `fp32`.

We judge every kernel against the two ceilings of a roofline model [[16](https://trainstation-project.github.io/blog/flat/#user-content-fn-roofline)].

1. **Memory.** The v6e’s HBM is rated at 1.638 TB/s, but the best a kernel can practically sustain is what `jnp.copy` achieves, which we time the same way: 1.46 TB/s, 89% of the rating. We report a kernel’s bandwidth as the bytes it must read and write divided by its time. A kernel that streams several operands at once can slightly beat a single copy, reaching about 1.54 TB/s in our measurements.
2. **Compute.** Google publishes the MXU’s peak, 918 `bf16` TFLOP/s, but not the VPU’s. To measure the VPU’s, we wrote a Pallas kernel that loads two tensors from HBM into VMEM, adds them 1,000,000 times and writes the result back. It reaches 7.091 TFLOP/s, which we use as the VPU peak.

A kernel’s arithmetic intensity, the FLOPs it does per byte it moves, decides which ceiling applies. On the MXU the crossover is about 918/1.638≈560918 / 1.638 \approx 560918/1.638≈560 FLOP/byte, and on the VPU it is about 7.091/1.638≈4.37.091 / 1.638 \approx 4.37.091/1.638≈4.3 FLOP/byte.

# Linear Attention

## Layer

The Linear Attention block (left): a residual stream alternating the sequence mixer with a gated MLP. Right: inside the mixer, qt,kt,vtq\_t, k\_t, v\_tqt​,kt​,vt​ each get their own depthwise causal convolution and activation befor
matt_d10

Interpretation history

Decision trace