Open-source project
tensorgi/TPA avatar
tensorgi/TPA

TPA (T6): Tensor Product Attention as a Drop-In Replacement for KV Caching in nanoGPT-Style Pretraining

[NeurIPS 2025 Spotlight] TPA: Tensor ProducT ATTenTion Transformer (https://arxiv.org/abs/2501.06425)

463 stars41 forksPythonMIT

At a glance

What is it?
TPA is the official code release for the NeurIPS 2025 spotlight paper Tensor Product Attention Is All You Need. It is a research pretraining stack, not a library, and it assumes eight 80GB GPUs before you can run anything.
Who is it for?
Adopt TPA if you are reproducing the T6 results on an 8x80GB node and your interest is the attention mechanism itself, since the repository is the paper's artifact and the FlashTPA decode files under ./decode are the part that is hard to reimplement from a description.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 11 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The problem TPA targets: the KV cache, not the attention math

The README states the goal plainly: T6 is a transformer that uses Tensor Product Attention to improve performance and reduce KV cache size. That second clause is the operative one. During autoregressive decoding, every layer stores a key and a value vector per token, so memory grows linearly with context length and batch size. TPA reformulates how those keys and values are represented, compressing them through a tensor product decomposition rather than storing a full per-head vector for every position. The repository is aimed at people who care about that specific cost, which in practice means pretraining researchers and inference engineers working on long-context models. It is not aimed at application developers who want to fine-tune a chat model. There is no model card, no weights download in the README, and no inference server. What you get is data preparation scripts, a pretraining loop, and evaluation wiring. If your problem is prompt engineering or retrieval, this repository has nothing for you.

What the code actually does: a nanoGPT fork with a different attention block

The acknowledgements section is the most informative part of the README for understanding the architecture of the codebase. T6 is built on Karpathy's nanoGPT as the foundational codebase. That tells you the shape of everything: a train script at the repository root, a config directory holding Python files that define model and optimizer settings, and dataset preparation scripts that tokenize text into a binary shard format. The README names config/train_T6_medium_adam_80g8.py as the configuration used in the torchrun example, and the filename encodes the setup: a medium-size model, the Adam optimizer, and eight 80GB GPUs. Training is launched through train_adam_fw.py, which is the nanoGPT-style training entry point adapted for the TPA attention module. Data flows from Hugging Face datasets through the preparation scripts into local shards, then through the training loop, then into lm-evaluation-harness for benchmarking. The FlashTPA work is separate from the training path: the README points to Algorithm 2 and 3 in the bundled paper PDF and to the ./decode directory for Python and Triton implementations of the decoding kernels, with news entries dated 06/13/2025 and 07/04/2025 marking when decoding and prefilling code landed. That split matters. The training code and the fast decode kernels are two different pieces of the repository with different maturity.

Getting it running: the exact commands and the hardware floor

Installation is a clone, a virtual environment, and one pip line: pip install torch==2.4.0 numpy transformers datasets tiktoken wandb tqdm. Python 3.10 or higher is required, and the README pins PyTorch at 2.4.0. That pin is worth respecting rather than relaxing, because Triton kernels in ./decode are sensitive to the PyTorch and Triton versions they were written against. Data preparation differs by dataset. For Fineweb-Edu-100B you cd into data/fineweb-edu, run python fineweb-edu.py, then move the output up one level with mv fineweb-edu100B .. and cd back out. For OpenWebText you run python data/openwebtext/prepare.py from the repository root, with the README warning that OpenWebText is sizable and needs sufficient storage and compute. Pretraining has two entry points. bash pretrain.sh runs the provided script. For control, the README gives torchrun --standalone --nproc_per_node=8 train_adam_fw.py config/train_T6_medium_adam_80g8.py, where the process count should match the GPU count. Evaluation means cd lm-evaluation-harness and following the instructions inside that directory, which is a vendored copy rather than a package you install. The hardware requirement is stated without hedging: A100 and H100 are recommended, and at least 8*80G VRAM is needed. That is a 640GB floor. There is no documented single-GPU path.

Where TPA is the wrong tool

The 8*80G requirement is the first filter, and it is not a soft recommendation phrased as a suggestion. The README says at least 8*80G VRAM is needed, which means a single 24GB card cannot run the documented configuration, and the config filename train_T6_medium_adam_80g8.py is written around exactly eight 80GB devices. A second limitation is that this is a pretraining repository with no released checkpoints in the material provided. There is no from_pretrained example, no Hugging Face model identifier for T6 weights, and no inference script in the README. If you wanted to use TPA as an attention layer inside an existing model, you would be extracting the attention module yourself from a nanoGPT fork, and the README does not document that module's interface. A third issue is maintenance surface: the repository has no releases retrieved, and the evaluation path depends on a vendored copy of lm-evaluation-harness, so upstream harness changes do not reach you automatically and you inherit whatever version was copied in. Finally, the FlashTPA decode kernels are recent additions (June and July 2025) and are presented as implementations of paper algorithms rather than as a stable API. Treat them as reference code to read alongside the PDF, not as a production inference library.

TPA against nanoGPT: same skeleton, different bet

The honest comparison is with nanoGPT itself, since the acknowledgements state that T6 is built on it. Both give you a small, readable training loop, config files as Python modules, and a tokenized-shard data pipeline. The difference is what each optimizes for. nanoGPT is a teaching and reproduction codebase for standard multi-head attention; it runs on modest hardware and its value is legibility. TPA keeps that skeleton but replaces the attention computation and raises the hardware bar to a multi-node-class 8x80G setup, because the point is to demonstrate a mechanism that pays off at scale in KV cache terms. If you want to understand how transformers train, nanoGPT is the better starting point and the TPA repository will be harder to read because the attention block is the novel part. If you specifically want to evaluate tensor product attention, using nanoGPT means reimplementing the mechanism from the paper, whereas this repository already contains it along with the FlashTPA kernels. A second reference point is the pretrained-model route: if your actual goal is a working language model rather than an architecture experiment, downloading an existing open-weights model is far cheaper than a pretraining run at this scale, and TPA does not compete there because it ships training code, not weights.

Licence, maintenance and the cost of staying current

The repository is MIT licensed, which is permissive and permits commercial use, modification and redistribution provided the copyright notice and permission notice are retained. The README also asks that you cite the paper if you use TPA or T6 in research or applications, which is a request rather than a licence term. Note that MIT covers this repository's code; the datasets it pulls in (Fineweb-Edu-100B, OpenWebText) and the vendored lm-evaluation-harness carry their own terms, and the bundled paper PDF is the authors' copyright. This is a general observation about the stack, not legal advice. On maintenance: there are no releases retrieved for this repository, so there is no versioned artifact to pin against and you track the main branch. The last push date in the repository metadata is 2026-09-04, and the README news entries run from the January 2025 open-sourcing through the September 2025 NeurIPS spotlight acceptance, with the FlashTPA decoding and prefilling code landing in June and July 2025. The practical upgrade cost is that a torch==2.4.0 pin plus Triton kernels means moving to a newer PyTorch is a deliberate migration, not a routine bump, and you should expect to re-validate the decode kernels if you do it.

Editorial conclusion

Adopt TPA if you are reproducing the T6 results on an 8x80GB node and your interest is the attention mechanism itself, since the repository is the paper's artifact and the FlashTPA decode files under ./decode are the part that is hard to reimplement from a description. Do not adopt it as a general training framework: the README recommends A100 or H100 with at least 8*80G VRAM, the install line pins torch==2.4.0, and the evaluation path is a vendored lm-evaluation-harness rather than a maintained dependency. Before committing GPU time, verify that your node matches the 8*80G figure, that config/train_T6_medium_adam_80g8.py exists at the path the README names, and that Fineweb-Edu-100B fits your storage budget after the move step.

Official sources

  1. Issues
  2. License: MIT
  3. Project website
  4. README
  5. tensorgi/TPA on GitHub
Community notes

Community notes