SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2410.23168 · ICLR · 2025

TokenFormer: Rethinking Transformer Scaling with Tokenized Model Parameters

Federico Tombari, Liwei Wang, Jan Lenssen, Muhammad Ferjad Naeem, Yongqin Xian, Bernt Schiele, Haiyang Wang, Yue Fan

arXiv · PDF · Open in the Atlas

Code that ran

7 of 11 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, 0 violated it and 0 have no contract verdict; 7 failures of our instrument; 4 no recorded run), measured 2026-11-23; 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/2410.23168.json · badge: /api/ran/2410.23168.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
Haiyang-W/TokenFormer canonical (classifier label)
classifier basis: census
7 ran · 4 no recorded run
FunctionStatusWhere it lives
filter_instances Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_runner.py
code served (permissive licence) · get_code("d0d48b0ed10415a4")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 re

def filter_instances(instance_list, tpu_prefix):
    for instance in instance_list:
        if instance.split(',')[0] == tpu_prefix:
            return [instance]
    re_pattern = tpu_prefix + '-[0-9]+'
    return [instance for instance in instance_list if re.fullmatch(re_pattern, instance.split(',')[0])]


ARGS = {
    'instance_list': [
        'tpu-0,192.168.1.1',
        'tpu-1,192.168.1.2',
        'gpu-0,192.168.1.3',
        'tpu-2,192.168.1.4'
    ],
    'tpu_prefix': 'tpu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
fmt_size Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/MaxText/convert_gpt3_ckpt_from_paxml.py
code served (permissive licence) · get_code("9deb7b7f6b8bd358")
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 str. 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
import numpy as np

# fmt_size takes a single parameter: num_bytes (int)
# The function divides num_bytes by 1024 repeatedly and formats the output
# It requires num_bytes > 0

ARGS = {
    'num_bytes': 2048000  # A valid positive integer representing bytes
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
gpt2_attention_mask_func Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/megatron/model/tokenformer_model.py
code served (permissive licence) · get_code("835e9eaf895dece7")
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, 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)

# attention_scores: a tensor of attention scores that will be masked
# Shape: (batch, seq_len, seq_len) or similar - using (2, 4, 4) for small tensors
attention_scores = torch.randn(2, 4, 4, dtype=torch.float32)

# ltor_mask: a boolean mask indicating which positions to mask
# True values indicate positions to mask (left-to-right causal mask)
# For causal attention, upper triangle should be True
ltor_mask = torch.triu(torch.ones(4, 4, dtype=torch.bool), diagonal=1)
# Broadcast to batch dimension
ltor_mask = ltor_mask.unsqueeze(0).expand(2, -1, -1)

ARGS = {
    "attention_scores": attention_scores,
    "ltor_mask": ltor_mask,
}
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, 4, 4) — shape (2, 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
nest_params Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/MaxText/convert_gemma_chkpt.py
code served (permissive licence) · get_code("f6a22c8bbef18283")
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 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

torch.manual_seed(0)

# The function nest_params takes a flat dictionary with string keys containing '/' separators
# and converts it into a nested dictionary structure.
# The parameter is:
# - params: Params (dict[str, Any]) - a flat dictionary where keys are paths with '/' separators

ARGS = {
    "params": {
        "model/layers/0/weight": torch.tensor([1.0, 2.0, 3.0, 4.0]),
        "model/layers/0/bias": torch.tensor([0.1, 0.2]),
        "model/layers/1/weight": torch.tensor([5.0, 6.0]),
        "optimizer/lr": 0.001,
        "optimizer/momentum": 0.9,
        "training/epochs": 100,
        "data/batch_size": 32,
    }
}
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 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
normalize_gcs_bucket_name Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_job.py
code served (permissive licence) · get_code("2530c27eb1db0abd")
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 Args. 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.

class Args:
    def __init__(self, bucket_name):
        self.BUCKET_NAME = bucket_name

# Test case 1: bucket name with gs:// prefix
args = Args("gs://my-bucket")

ARGS = {
    "args": args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Args — a Args output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Args 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
prefill_benchmark_loop Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/MaxText/inference_microbenchmark.py
code served (permissive licence) · get_code("5ce28e5d7146e8ad")
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 float, ndim 0, dtype family float, shape () 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 jax
import jax.numpy as jnp

class MockEngine:
    """Mock engine that mimics the interface expected by prefill_benchmark_loop."""
    def prefill(self, params, padded_tokens, true_length):
        # Return a tuple of (prefill_result, something_else)
        # prefill_result needs to be a JAX array so jax.block_until_ready works
        batch_size = padded_tokens.shape[0]
        prefill_result = jnp.ones((batch_size, 4))
        return prefill_result, None

# Create mock params (can be any pytree structure)
mock_params = {"layer_1": jnp.array([[1.0, 2.0, 3.0, 4.0]])}

# Create small token tensor: batch_size=2, sequence_length=3
padded_tokens = jnp.array([[1, 2, 3], [4, 5, 6]], dtype=jnp.int32)

# True lengths for each sequence in batch
true_length = jnp.array([3, 2], dtype=jnp.int32)

# Create engine instance
engine = MockEngine()

# Number of iterations for the benchmark loop
iters = 2

ARGS = {
    "engine": engine,
    "params": mock_params,
    "tokens": padded_tokens,
    "true_length": true_length,
    "iters": iters,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () 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
run_create_resources Ran
ran; our contract draft was wrong, not the code
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_job.py
code served (permissive licence) · get_code("9ff16fbb932de037")
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 CompletedProcess. 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 subprocess
from argparse import Namespace

# Create a minimal args object with all required attributes
args = Namespace(
    RUN_NAME="test-run",
    TPU_TYPE="v4-8",
    VERSION="tpu-vm-base",
    PROJECT="test-project",
    ZONE="us-central1-a",
    NUM_SLICES=1,
    CQR_EXTRA_ARGS="",
    ENABLE_AUTOCHECKPOINT=False
)

# Create a temporary startup script file path
startup_script_file = "/tmp/startup_script.sh"

ARGS = {
    "startup_script_file": startup_script_file,
    "args": args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type CompletedProcess — a CompletedProcess output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a CompletedProcess 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
execute_main_command Not yet run
unverified (harvested, no recorded run)
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_runner.py
code served (permissive licence) · get_code("4ec6a8b213a8a8ab")
How it ran

no invocation recorded.

get_system_characteristics Not yet run
unverified (harvested, no recorded run)
Haiyang-W/TokenFormer/tokenformer-tpu/MaxText/accelerator_to_spec_map.py
code served (permissive licence) · get_code("87c57735e68651cc")
How it ran

no invocation recorded.

move_script_dir_to_gcs Not yet run
unverified (harvested, no recorded run)
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_job.py
code served (permissive licence) · get_code("6a8c33a4bc4cad79")
How it ran

no invocation recorded.

scps Not yet run
unverified (harvested, no recorded run)
Haiyang-W/TokenFormer/tokenformer-tpu/multihost_runner.py
code served (permissive licence) · get_code("669c3270deb52aa2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 9 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
get_system_characteristics 2 other papers
2 dated earlier
2309.16588 (2023-09)
Vision Transformers Need Registers
2405.08553 (2024-05)
Improving Transformers with Dynamically Composable Multi-Head Attention
fmt_size 1 other paper
1 dated earlier
1910.01500 (2019-10)
MLPerf Training Benchmark

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-23.

Repositories linked to this paper

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

Abstract

Transformers have become the predominant architecture in foundation models due to their excellent performance across various domains. However, the substantial cost of scaling these models remains a significant concern. This problem arises primarily from their dependence on a fixed number of parameters within linear projections. When architectural modifications (e.g., channel dimensions) are introduced, the entire model typically requires retraining from scratch. As model sizes continue growing, this strategy results in increasingly high computational costs and becomes unsustainable. To overcome this problem, we introduce Tokenformer, a natively scalable architecture that leverages the attention mechanism not only for computations among input tokens but also for interactions between tokens and model parameters, thereby enhancing architectural flexibility. By treating model parameters as tokens, we replace all the linear projections in Transformers with our token-parameter attention layer, where input tokens act as queries and model parameters as keys and values. This reformulation allows for progressive and efficient scaling without necessitating retraining from scratch. Our model scales from 124M to 1.4B parameters by incrementally adding new key-value parameter pairs, achieving performance comparable to Transformers trained from scratch while greatly reducing training costs. Code and models are available at https://github.com/Haiyang-W/TokenFormer.git.

For agents

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

get_harvested_code_for_paper("2410.23168")
get_code_for_paper("2410.23168")
have("2410.23168")

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

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

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

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

Connect an agent — have() is free.