SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2501.06425 · NeurIPS · 2025

Tensor Product Attention Is All You Need

Quanquan Gu, Zhen Qin, Yifan Zhang, Yang Yuan, Huizhuo Yuan, Yifeng Liu, A. C. Yao

arXiv · PDF · Open in the Atlas

Code that ran

8 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 1 violated it and 2 have no contract verdict; 5 failures of our instrument; 1 no recorded run), measured 2026-11-24; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2501.06425.json · badge: /api/ran/2501.06425.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
tensorgi/t6 canonical (classifier label)
classifier basis not recorded on the link
5 ran · 1 no recorded run
tensorgi/tpa canonical (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
tensorgi/TPA canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
apply_rotary_emb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
tensorgi/t6/model/T6_infer.py
pointer only (licence: MIT); the stored copy get_code serves, from meituan-automl/visionllama, is pointer only (licence: NONE) · get_code("b47d48e431b34acd")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from meituan-automl/visionllama, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

apply_rotary_emb Ran
ran on a synthesized input
tensorgi/t6/model/T6_kvonly_partialrope.py
code served (permissive licence) · get_code("c2a8d2ee1e68a6db")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 7) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function applies rotary embeddings to tensor x using cos and sin tensors
# x should have shape (..., rotary_dim + extra_dims)
# cos and sin should have shape (..., rotary_dim // 2)

# Create small tensors
batch_size = 2
rotary_half_dim = 2
rotary_dim = rotary_half_dim * 2
extra_dims = 3

# x: shape (batch, rotary_dim + extra_dims) = (2, 7)
x = torch.randn(batch_size, rotary_dim + extra_dims)

# cos: shape (batch, rotary_half_dim) = (2, 2)
cos = torch.randn(batch_size, rotary_half_dim)

# sin: shape (batch, rotary_half_dim) = (2, 2)
sin = torch.randn(batch_size, rotary_half_dim)

ARGS = {
    "x": x,
    "cos": cos,
    "sin": sin,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 7) — shape (2, 7) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
apply_rotary_emb Ran
ran on a synthesized input
tensorgi/t6/model/T6_linearattn_kvonly_partialrope_decay.py
code served (permissive licence) · get_code("31eead4c21084b8b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 6) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Analyze the function:
# - x: tensor that gets sliced and transformed
# - cos: tensor used in rotation, shape[-1] * 2 gives rotary_dim
# - sin: tensor used in rotation, same shape as cos
# - decay: scalar tensor or float used to scale output

# Let's construct valid tensors:
# cos and sin should have the same shape, and their last dimension * 2 = rotary_dim
# x should have rotary_dim + some extra dimensions for x_pass

# Set rotary_dim = 4, so cos.shape[-1] = 2
batch_size = 2
seq_len = 3
cos_dim = 2
rotary_dim = cos_dim * 2  # 4

# x needs at least rotary_dim dimensions, let's make it have rotary_dim + 2 extra
x_dim = rotary_dim + 2  # 6

# Build tensors
x = torch.randn(batch_size, seq_len, x_dim)
cos = torch.randn(batch_size, seq_len, cos_dim)
sin = torch.randn(batch_size, seq_len, cos_dim)
decay = torch.tensor(0.9)

ARGS = {
    "x": x,
    "cos": cos,
    "sin": sin,
    "decay": decay,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 6) — shape (2, 3, 6) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
flashtpa_decode_torch Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
tensorgi/tpa/decode/flashtpa_decode_torch.py
code served (permissive licence) · get_code("46c4b171da8b3c7a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 4, dtype family float, shape (2, 1, 3, 7) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F

torch.manual_seed(0)

# Define tensor dimensions with distinct sizes
B = 2  # batch size
N = 1  # sequence length (must be 1 for decode)
H = 3  # head dimension
R = 4  # rank for A tensors
M = 5  # key/value sequence length
D = 6  # dimension for B tensors
E = 7  # output dimension for values

# Construct tensors with the required shapes
aq = torch.randn(B, N, H, R)  # (2, 1, 3, 4)
ak = torch.randn(B, M, H)     # (2, 5, 3)
av = torch.randn(B, M, H)     # (2, 5, 3)
bq = torch.randn(B, N, R, D)  # (2, 1, 4, 6)
bk = torch.randn(B, M, D)     # (2, 5, 6)
bv = torch.randn(B, M, E)     # (2, 5, 7)

# Optional parameters
scale = None
scale_q = None
scale_k = None
scale_v = None
cu_seqlens = None

ARGS = {
    "aq": aq,
    "ak": ak,
    "av": av,
    "bq": bq,
    "bk": bk,
    "bv": bv,
    "scale": scale,
    "scale_q": scale_q,
    "scale_k": scale_k,
    "scale_v": scale_v,
    "cu_seqlens": cu_seqlens,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 1, 3, 7) — shape (2, 1, 3, 7) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
precompute_freqs_cis Ran
ran, violated the contract we drafted
tensorgi/t6/model/T6_infer.py
code served (permissive licence) · get_code("e93cc5b705c2eb3b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (4, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

ARGS = {
    "dim": 8,
    "end": 4,
    "theta": 10000.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (4, 4) — shape (4, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
request_caching_arg_to_dict Ran
ran; our contract draft was wrong, not the code
tensorgi/TPA/lm-evaluation-harness/lm_eval/evaluator.py
code served (permissive licence) · get_code("c44830a7722ff5f7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

ARGS = {
    'cache_requests': 'true'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
reshape_for_broadcast Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
tensorgi/t6/model/T6_infer.py
pointer only (licence: MIT); the stored copy get_code serves, from alpha-vllm/llama2-accessory, is pointer only (licence: NOASSERTION) · get_code("70bf6ebaafd266c4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from alpha-vllm/llama2-accessory, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

tpa_decode_naive_torch Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
tensorgi/tpa/decode/flashtpa_decode_torch.py
code served (permissive licence) · get_code("05f139bc4395fbd8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 4, dtype family float, shape (2, 1, 3, 7) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F

torch.manual_seed(0)

# Set up tensor dimensions
B = 2  # batch size
N = 1  # sequence length (must be 1 per assertion)
H = 3  # head dimension
R = 4  # rank for query A
M = 5  # key/value sequence length
D = 6  # dimension for key B
E = 7  # dimension for value B

# Create tensors with the required shapes
aq = torch.randn(B, N, H, R)  # (2, 1, 3, 4)
ak = torch.randn(B, M, H)      # (2, 5, 3)
av = torch.randn(B, M, H)      # (2, 5, 3)
bq = torch.randn(B, N, R, D)   # (2, 1, 4, 6)
bk = torch.randn(B, M, D)      # (2, 5, 6)
bv = torch.randn(B, M, E)      # (2, 5, 7)

# Optional parameters
scale = None
scale_q = None
scale_k = None
scale_v = None
cu_seqlens = None

ARGS = {
    "aq": aq,
    "ak": ak,
    "av": av,
    "bq": bq,
    "bk": bk,
    "bv": bv,
    "scale": scale,
    "scale_q": scale_q,
    "scale_k": scale_k,
    "scale_v": scale_v,
    "cu_seqlens": cu_seqlens,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 1, 3, 7) — shape (2, 1, 3, 7) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
apply_rotary_emb Not yet run
unverified (harvested, no recorded run)
tensorgi/t6/model/T6.py
code served (permissive licence) · get_code("0f4f2333e89a6c8c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 4 the same month, 5 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
reshape_for_broadcast 58 other papers
49 dated earlier, 2 the same month, 6 later, 1 same year, order not determinable · 2 only as an assembly brick
2023.emnlp-main.534 (2023 (year only))
Disentangling Transformer Language Models as Superposed Topic Models
2303.09736 (2023-03)
Dynamic Structure Pruning for Compressing CNNs
2307.09288 (2023-07)
Llama 2: Open Foundation and Fine-Tuned Chat Models
and 55 more not named here
apply_rotary_emb 55 other papers
45 dated earlier, 1 the same month, 8 later, 1 same year, order not determinable · 1 only as an assembly brick
2023.emnlp-main.534 (2023 (year only))
Disentangling Transformer Language Models as Superposed Topic Models
2303.09736 (2023-03)
Dynamic Structure Pruning for Compressing CNNs
2307.09288 (2023-07)
Llama 2: Open Foundation and Fine-Tuned Chat Models
and 52 more not named here
request_caching_arg_to_dict 17 other papers
5 dated earlier, 1 the same month, 10 later, 1 same year, order not determinable
2005.14165 (2020-05)
Language Models are Few-Shot Learners
2405.07938 (2024-05)
EconLogicQA: A Question-Answering Benchmark for Evaluating Large Language Models in Economic Sequential Reasoning
2411.07176 (2024-11)
More Expressive Attention with Negative Weights
and 14 more not named here
precompute_freqs_cis 10 other papers
6 dated earlier, 1 the same month, 3 later · 1 only as an assembly brick
2308.12950 (2023-08)
Code Llama: Open Foundation Models for Code
2402.06700 (2024-02)
Entropy-Regularized Token-Level Policy Optimization for Language Agent Reinforcement
2408.01933 (2024-08)
DiReCT: Diagnostic Reasoning for Clinical Notes via Large Language Models
and 7 more not named here
apply_rotary_emb 2 other papers
2 later
2604.01472 (2026-04)
The Newton-Muon Optimizer
2605.17109 (2026-05)
DynMuon: A Dynamic Spectral Shaping View of Muon

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Scaling language models to handle longer input sequences typically necessitates large key-value (KV) caches, resulting in substantial memory overhead during inference. In this paper, we propose Tensor Product Attention (TPA), a novel attention mechanism that uses tensor decompositions to represent queries, keys, and values compactly, substantially shrinking the KV cache size at inference time. By factorizing these representations into contextual low-rank components and seamlessly integrating with RoPE and any possible position encoding mechanisms, TPA achieves improved model quality alongside memory efficiency. Based on TPA, we introduce the Tensor ProducT ATTenTion Transformer (T6), a new model architecture for sequence modeling. Through extensive empirical evaluation on language modeling tasks, we demonstrate that T6 surpasses or matches the performance of standard Transformer baselines, including Multi-Head Attention (MHA), Multi-Query Attention (MQA), Grouped-Query Attention (GQA), and Multi-Head Latent Attention (MLA) across various metrics, including perplexity and a range of established evaluation benchmarks. Notably, TPA's memory efficiency and computational efficiency at the decoding stage enable processing longer sequences under fixed resource constraints, addressing a critical scalability challenge in modern language models. Project

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2501.06425")
get_code_for_paper("2501.06425")
have("2501.06425")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2501.06425.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2501.06425.svg)](https://syntology.ai/paper/2501.06425)

Connect an agent — have() is free.