SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2404.00672 · CVPR · 2024

A General and Efficient Training for Transformer via Token Expansion

Xing Sun, Baochang Zhang, Ke Li, Yunhang Shen, Wenxuan Huang, Shaohui Lin, Gaoqi He, Jiao Xie

arXiv · PDF · Open in the Atlas

Code that ran

7 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 6 failures of our instrument; 1 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, measured 2026-11-22; 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/2404.00672.json · badge: /api/ran/2404.00672.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
osilly/tokenexpansion canonical (classifier label)
classifier basis: census
6 ran · 0 no recorded run
Osilly/TokenExpansion community
Papers with Code archive
1 ran · 1 no recorded run
FunctionStatusWhere it lives
window_partition Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
osilly/tokenexpansion/ToE/EfficientTrain/models/swin.py
code served (permissive licence) · get_code("144d10b49baeb8a6")
How it ran

Ran in Syntology's jail 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 (8, 4, 4, 4) as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-04T22:38:58Z). 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)

# Create a tensor with shape (B, H, W, C)
# B=2 (batch), H=8 (height), W=8 (width), C=4 (channels)
# Using distinct sizes: 2, 8, 8, 4
x = torch.randn(2, 8, 8, 4)

# window_size must divide both H and W evenly
# H=8, W=8, so window_size=4 works (8 // 4 = 2)
window_size = 4

ARGS = {
    "x": x,
    "window_size": window_size,
}
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 (8, 4, 4, 4) — shape (8, 4, 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
TokenSelect Ran
ran on a synthesized input · constructed an object; no result was computed
Osilly/TokenExpansion/ToE/EfficientTrain/models/deit_expansion.py
code served (permissive licence) · get_code("ed66abf8ce1543ae")
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 an instance of its own class, TokenSelect: the run constructed the object and did not call it, so no result was computed. 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
from torch import nn as nn

torch.manual_seed(0)

ARGS = {
    'expansion_step': [0, 100, 200],
    'keep_rate': [0.5, 0.75, 1.0],
    'initialization_keep_rate': 0.25,
    'expansion_multiple_stage': 2,
    'distance': 'cosine'
}
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 TokenSelect — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a TokenSelect 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
build_dataset Ran
ran; our contract draft was wrong, not the code
osilly/tokenexpansion/ToE/EfficientTrain/datasets.py
code served (permissive licence) · get_code("cd3815bc733c3af8")
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 tuple. 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
from argparse import Namespace
import tempfile
import os
from PIL import Image
import shutil

# Create a temporary directory structure for datasets
temp_dir = tempfile.mkdtemp()

# Create minimal CIFAR100-like directory structure
cifar_path = os.path.join(temp_dir, 'cifar100')
os.makedirs(cifar_path, exist_ok=True)

# Create minimal ImageNet-like directory structure
imnet_path = os.path.join(temp_dir, 'imagenet')
train_path = os.path.join(imnet_path, 'train')
val_path = os.path.join(imnet_path, 'val')
os.makedirs(train_path, exist_ok=True)
os.makedirs(val_path, exist_ok=True)

# Create sample class directories and images for ImageNet
for class_idx in range(2):
    class_dir_train = os.path.join(train_path, f'class_{class_idx}')
    class_dir_val = os.path.join(val_path, f'class_{class_idx}')
    os.makedirs(class_dir_train, exist_ok=True)
    os.makedirs(class_dir_val, exist_ok=True)
    
    # Create a minimal dummy image
    img = Image.new('RGB', (256, 256), color='red')
    img.save(os.path.join(class_dir_train, 'img_0.jpg'))
    img.save(os.path.join(class_dir_val, 'img_0.jpg'))

# Create image_folder dataset structure
image_folder_path = os.path.join(temp_dir, 'image_folder')
eval_image_folder_path = os.path.join(temp_dir, 'eval_image_folder')
os.makedirs(image_folder_path, exist_ok=True)
os.makedirs(eval_image_folder_path, exist_ok=True)

for class_idx in range(3):
    class_dir_train = os.path.join(image_folder_path, f'class_{class_idx}')
    class_dir_eval = os.path.join(eval_image_folder_path, f'class_{class_idx}')
    os.makedirs(class_dir_train, exist_ok=True)
    os.makedirs(class_dir_eval, exist_ok=True)
    
    img = Image.new('RGB', (256, 256), color='blue')
    img.save(os.path.join(class_dir_train, 'img_0.jpg'))
    img.save(os.path.join(class_dir_eval, 'img_0.jpg'))

ARGS = {
    'is_train': True,
    'args': Namespace(
        base_input_size=224,
        imagenet_default_mean_and_std=True,
        color_jitter=0.4,
        aa='rand-m9-mstd0.5-inc1',
        train_interpolation='bicubic',
        reprob=0.25,
        remode='pixel',
        recount=1,
        crop_pct=None,
        data_set='IMNET',
        data_path=imnet_path,
        eval_data_path=eval_image_folder_path,
        nb_classes=3,
    )
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, timm, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
build_transform Ran
ran; our contract draft was wrong, not the code
osilly/tokenexpansion/ToE/EfficientTrain/datasets.py
code served (permissive licence) · get_code("60fc00ee96a43cdf")
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 Compose. 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
from torchvision import transforms

torch.manual_seed(0)

class Args:
    def __init__(self):
        self.base_input_size = 224
        self.imagenet_default_mean_and_std = True
        self.color_jitter = 0.4
        self.aa = "rand-m9-mstd0.5"
        self.train_interpolation = "bicubic"
        self.reprob = 0.25
        self.remode = "pixel"
        self.recount = 1
        self.crop_pct = None

ARGS = {
    "is_train": True,
    "args": Args()
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, timm, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Compose — a Compose output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Compose 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
img2windows Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
osilly/tokenexpansion/ToE/EfficientTrain/models/cswin.py
code served (permissive licence) · get_code("39b18f062e0cc6d9")
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 3, dtype family float, shape (16, 6, 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)

# Create a small image tensor: B=2, C=4, H=8, W=6
img = torch.randn(2, 4, 8, 6)

# Window dimensions that divide evenly into H and W
H_sp = 2  # H // H_sp = 8 // 2 = 4
W_sp = 3  # W // W_sp = 6 // 3 = 2

ARGS = {
    "img": img,
    "H_sp": H_sp,
    "W_sp": W_sp,
}
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 3, dtype family float, shape (16, 6, 4) — shape (16, 6, 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
window_reverse Ran
ran; our contract draft was wrong, not the code
osilly/tokenexpansion/ToE/EfficientTrain/models/swin.py
code served (permissive licence) · get_code("61bf152e6a42a184")
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, 8, 12, 3) 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)

# Parameters for window_reverse
# windows: (num_windows*B, window_size, window_size, C)
# The function expects windows to be partitioned from an image of size (B, H, W, C)
# where the image is divided into non-overlapping windows of size window_size x window_size

B = 2  # batch size
H = 8  # image height
W = 12  # image width
window_size = 4  # window size
C = 3  # number of channels

# Calculate number of windows
num_windows_h = H // window_size  # 2
num_windows_w = W // window_size  # 3
num_windows = num_windows_h * num_windows_w  # 6

# windows shape: (num_windows*B, window_size, window_size, C)
# = (6*2, 4, 4, 3) = (12, 4, 4, 3)
windows = torch.randn(num_windows * B, window_size, window_size, C)

ARGS = {
    "windows": windows,
    "window_size": window_size,
    "H": H,
    "W": W,
}
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, 8, 12, 3) — shape (2, 8, 12, 3) 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
windows2img Ran
ran; our contract draft was wrong, not the code
osilly/tokenexpansion/ToE/EfficientTrain/models/cswin.py
code served (permissive licence) · get_code("ab01fbfe58c75b08")
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, 8, 6, 12) 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 as nn

torch.manual_seed(0)

# Understand the function:
# - img_splits_hw: shape (B', H, W, C) where B' = B * (H/H_sp) * (W/W_sp)
# - H_sp, W_sp: spatial dimensions of each window/split
# - H, W: original image height and width
# - C: number of channels (inferred from last dim)

# Let's construct valid arguments:
# Choose concrete values:
B = 2  # batch size
H_sp = 4  # height of each split
W_sp = 3  # width of each split
H = 8  # original image height
W = 6  # original image width
C = 3  # channels

# B' = B * (H/H_sp) * (W/W_sp) = 2 * (8/4) * (6/3) = 2 * 2 * 2 = 8
B_prime = B * (H // H_sp) * (W // W_sp)

# img_splits_hw should have shape (B', H, W, C) = (8, 8, 6, 3)
img_splits_hw = torch.randn(B_prime, H, W, C)

ARGS = {
    "img_splits_hw": img_splits_hw,
    "H_sp": H_sp,
    "W_sp": W_sp,
    "H": H,
    "W": W,
}
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, 8, 6, 12) — shape (2, 8, 6, 12) 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
VisionTransformerExpansion Not yet run
unverified (harvested, no recorded run)
Osilly/TokenExpansion/ToE/EfficientTrain/models/deit_expansion.py
code served (permissive licence) · get_code("4f40d9a1fc241aab")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 5 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 2 the same month, 5 later) and 3 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
window_reverse 227 other papers
164 dated earlier, 8 the same month, 46 later, 9 same year, order not determinable · 34 only as an assembly brick
1608.03983 (2016-08)
SGDR: Stochastic Gradient Descent with Warm Restarts
1711.10925 (2017-11)
Deep Image Prior
2003.13678 (2020-03)
Designing Network Design Spaces
and 224 more not named here
window_partition 223 other papers
160 dated earlier, 8 the same month, 46 later, 9 same year, order not determinable · 32 only as an assembly brick
1706.03762 (2017-06)
Attention Is All You Need
1711.10925 (2017-11)
Deep Image Prior
2003.13678 (2020-03)
Designing Network Design Spaces
and 220 more not named here
img2windows 14 other papers
9 dated earlier, 4 later, 1 same year, order not determinable · 1 only as an assembly brick
2107.00652 (2021-07)
CSWin Transformer: A General Vision Transformer Backbone with Cross-Shaped Windows
2208.08630 (2022-08)
Unifying Visual Perception by Dispersible Points Learning
2211.13654 (2022-11)
Cross Aggregation Transformer for Image Restoration
and 11 more not named here
windows2img 14 other papers
9 dated earlier, 4 later, 1 same year, order not determinable · 1 only as an assembly brick
2107.00652 (2021-07)
CSWin Transformer: A General Vision Transformer Backbone with Cross-Shaped Windows
2208.08630 (2022-08)
Unifying Visual Perception by Dispersible Points Learning
2211.13654 (2022-11)
Cross Aggregation Transformer for Image Restoration
and 11 more not named here
build_dataset 4 other papers
3 dated earlier, 1 later
2302.06052 (2023-02)
CEDNet: A Cascade Encoder-Decoder Network for Dense Prediction
2304.02330 (2023-04)
SMPConv: Self-moving Point Representations for Continuous Convolution
2309.15812 (2023-09)
Convolutional Networks with Oriented 1D Kernels
and 1 more not named here

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

Repositories linked to this paper

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

Abstract

The remarkable performance of Vision Transformers (ViTs) typically requires an extremely large training cost. Existing methods have attempted to accelerate the training of ViTs, yet typically disregard method universality with accuracy dropping. Meanwhile, they break the training consistency of the original transformers, including the consistency of hyper-parameters, architecture, and strategy, which prevents them from being widely applied to different Transformer networks. In this paper, we propose a novel token growth scheme Token Expansion (termed ToE) to achieve consistent training acceleration for ViTs. We introduce an "initialization-expansion-merging" pipeline to maintain the integrity of the intermediate feature distribution of original transformers, preventing the loss of crucial learnable information in the training process. ToE can not only be seamlessly integrated into the training and finetuning process of transformers (e.g., DeiT and LV-ViT), but also effective for efficient training frameworks (e.g., Effi-cientTrain), without twisting the original training hyperparameters, architecture, and introducing additional training strategies. Extensive experiments demonstrate that ToE achieves about 1.3× faster for the training of ViTs in a lossless manner, or even with performance gains over the full-token training baselines. Code is available at https: //github.com/Osilly/TokenExpansion.

For agents

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

get_harvested_code_for_paper("2404.00672")
get_code_for_paper("2404.00672")
have("2404.00672")

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

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

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

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

Connect an agent — have() is free.