# Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet

Tokens-to-token ViT trains vision transformers from scratch on ImageNet

Yuan, Li, Chen, Yunpeng, Wang, Tao, Yu, Weihao, Shi, Yujun, Jiang, Zihang and 3 more · arXiv · 2021-1-28

- **Problem** Vision transformers trail CNNs when trained from scratch on ImageNet. Plain fixed-size patch tokens miss local structure such as edges and lines, and the backbone wastes capacity.
- **Method** T2T-ViT merges neighboring patch tokens over several passes, then uses a deep-narrow backbone.
- **Results** T2T-ViT-14 reached 81.5% top-1 accuracy on ImageNet with 21.5M parameters and 4.8G MACs. ViT-S/16 reached 78.1% with 48.6M parameters and 10.1G MACs.

## Why plain patch tokens limit ViT from scratch

ViT applies transformer layers to fixed-length patches of an image, treating each patch as a token and modeling the relations among all tokens globally.

The authors trace the gap to two properties of ViT. A hard split of the image gives tokens that cannot represent local structure such as edges and lines, so the model needs far more training samples. The attention backbone also carries redundant channels, which limits feature richness and makes training harder. To check this, the authors compared learned features of ViT-L/16 with those of ResNet50.

ResNet features build edges, lines and textures from the bottom layers upward, whereas ViT features model structure poorly, and many of its channels take a zero value.

## Progressive tokenization with the T2T module

The T2T module replaces the single hard split with a loop of two steps, re-structurization and soft split, run several times so that each pass merges neighboring tokens into longer-range units. Each pass shortens the token sequence, so the final token count is fixed before the backbone sees it.

Re-structurization sends the current tokens T through a transformer layer, where the MSA and the MLP both include layer normalization, giving \\( T^{\\prime} = \\mathrm{MLP}(\\mathrm{MSA}(T)) \\). The transformed tokens are then reorganized into a spatial grid, \\( I = \\mathrm{Reshape}(T^{\\prime}) \\), where \\( T^{\\prime} \\in R^{l \\times c} \\), \\( I \\in R^{h \\times w \\times c} \\) and \\( l = h \\times w \\).

The soft split cuts the grid into k by k patches that overlap with overlap s and carry padding p, so each patch shares elements with its neighbors. The k minus s term acts like a convolution stride. The number of output tokens is \\\[ l\_o = \\left\\lfloor \\frac{h + 2p - k}{k - s + 1} \\right\\rfloor \\times \\left\\lfloor \\frac{w + 2p - k}{k - s + 1} \\right\\rfloor \\\], and each patch is flattened into a token of length \\( c k^2 \\).

Because these tokens are longer than the 16×16 patches of ViT, the T2T layers use a small channel dimension of 32 or 64 to limit MACs, and a Performer layer can replace the standard transformer layer when GPU memory is tight.

## A deep-narrow backbone borrowed from CNN design

The authors adapted five CNN-derived designs to ViT: dense connections, deep-narrow versus shallow-wide layouts, channel attention, more heads in multi-head attention, and Ghost operations. Among these, a deep-narrow layout, with fewer channels per layer and more layers, reduced both model size and MACs while improving performance, and the SE channel attention helped less.

The T2T-ViT backbone takes the fixed-length tokens Tf from the T2T module, prepends a class token, adds a sinusoidal position embedding E, and runs b blocks of \\( Tf\_i = \\mathrm{MLP}(\\mathrm{MSA}(Tf\_{i-1})) \\). The prediction is \\( y = fc(LN(Tf\_b)) \\), where LN is layer normalization and fc is a single fully connected layer over the class token, and the embedding \\( E \\in R^{(l+1) \\times d} \\) matches the token count and hidden dimension d.

## How the model variants are sized

The T2T module uses two re-structurization steps and three soft splits with patch sizes 7, 3 and 3 and overlaps 3, 1 and 1, which reduces a 224×224 input to 14×14 tokens. The backbone uses hidden dimensions of 256 to 512 and MLP sizes of 512 to 1536, which is narrower than the ViT backbone.

## ImageNet results against ViT and ResNets

Models were trained on the roughly 1.3 million training images of ImageNet and evaluated on its 50k validation images, using batch sizes of 512 or 1024 on 8 NVIDIA GPUs. Most runs use 224×224 inputs and 310 epochs with AdamW and cosine learning rate decay, with mixup and cutmix as augmentations for both CNNs and the transformer models.

The authors state that the T2T-ViT models cut parameters and MACs of vanilla ViT by about half while improving accuracy.

Across these pairs the authors report a gain of 1.4%-2.7% over ResNets of similar model size and MACs.

The authors conclude that visual transformers can outperform CNNs at several complexities on ImageNet when trained without JFT-300M pretraining. The scope of this claim is the ImageNet comparisons with the models and baselines given above.

## Lite models against MobileNets

The lite variants use no efficient convolution or other special operations, and they are reduced only by lowering depth, hidden dimension and MLP ratio.

## Transfer to CIFAR10 and CIFAR100

The pretrained T2T-ViT-14 and T2T-ViT-19 were fine-tuned for 60 epochs with SGD and cosine learning rate decay on CIFAR10 and CIFAR100.

The text describes fine-tuning only for these two T2T-ViT models, so the transfer result covers them and no other variant.

## Which CNN designs transfer to ViT

The authors note that ResNeXt-style multi-head splitting had few effects on ViT and T2T-ViT, and that large head counts add GPU memory without benefit.

Ghost operations lowered accuracy by 2.9% on ResNet50, by 2.0% on T2T-ViT and by 4.4% on ViT, so on the T2T-ViT backbone the reduction in parameters and MACs came with a smaller accuracy cost than on ViT. The authors also report that T2T-ViT outperformed ViT in each of the five CNN-derived structures.

## Ablations of the T2T module and the deep-narrow choice

That is a 2.7% decrease in top-1 accuracy relative to T2T-ViT-14, at similar model size and MACs, which the authors read as evidence that the deep-narrow layout matters for T2T-ViT.

## Limitations

The MACs of T2T-ViT remain larger than those of MobileNets, which the authors attribute to the dense operations in transformers. The token count at the start of the T2T module is larger than the 16×16 case of ViT, which raises MACs and memory use and is the reason for the small channel dimensions and the optional Performer layer.

The 384×384 result was obtained only for T2T-ViT-14. Transfer was run only on CIFAR10 and CIFAR100, and only for T2T-ViT-14 and T2T-ViT-19. The main ResNet comparison relies on the retrained ResNet rows, and the published ResNet numbers are lower.

## Paper info

- **Authors**: Yuan, Li, Chen, Yunpeng, Wang, Tao, Yu, Weihao, Shi, Yujun, Jiang, Zihang, Tay, Francis EH, Feng, Jiashi, Yan, Shuicheng
- **Venue**: arXiv · Preprint
- **First published**: 2021-1-28
- **Added**: 2026-11-12
- **Updated**: 2021-11-30
- **Version**: v3
- **arXiv**: 2101.11986
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2101.11986v3) · [PDF ↗](https://arxiv.org/pdf/2101.11986v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Yuan, Li, Chen, Yunpeng, Wang, Tao, Yu, Weihao, Shi, Yujun, Jiang, Zihang, Tay, Francis EH, Feng, Jiashi, Yan, Shuicheng (2021). Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet. arXiv:2101.11986v3. https://arxiv.org/abs/2101.11986v3

**BibTeX**

```
@misc{li2021tokens,
  title = {{Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet}},
  author = {Yuan, Li and Chen, Yunpeng and Wang, Tao and Yu, Weihao and Shi, Yujun and Jiang, Zihang and Tay, Francis EH and Feng, Jiashi and Yan, Shuicheng},
  year = {2021},
  eprint = {2101.11986},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2101.11986v3}
}
```

## Other paper commentary

- [Swin UNETR: Swin Transformers for Semantic Segmentation of Brain Tumors in MRI Images](https://refivu.com/en/papers/44c6c3a9-434b-4cb2-aed0-e8b3167653fc-swin-unetr-swin-transformers-for-semantic-segmentation-of.md)
- [Uformer: A General U-Shaped Transformer for Image Restoration](https://refivu.com/en/papers/f59714df-d19d-41d7-8c41-8c04e0636925-uformer-a-general-u-shaped-transformer-for-image.md)
- [Bridging the Gap Between Anchor-based and Anchor-free Detection via Adaptive Training Sample Selection](https://refivu.com/en/papers/a286d37a-f6cf-498c-9170-fa2a9627c54e-bridging-the-gap-between-anchor-based-and-anchor.md)
- [YOLACT: Real-time Instance Segmentation](https://refivu.com/en/papers/5c58130c-e869-497b-8b85-e21d46848fe1-yolact-real-time-instance-segmentation.md)
- [SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks](https://refivu.com/en/papers/bd27ac05-aab2-4448-8e23-79659dfe759b-siamrpn-evolution-of-siamese-visual-tracking-with-very.md)
- [A Review on Deep Learning Techniques Applied to Semantic Segmentation](https://refivu.com/en/papers/8ae0e955-3ed5-48a2-b638-f9e5d7aa334e-a-review-on-deep-learning-techniques-applied-to.md)
- [Recurrent Neural Networks for Multivariate Time Series with Missing Values](https://refivu.com/en/papers/04779a68-ae30-4f73-bc85-9bae7235eaaf-recurrent-neural-networks-for-multivariate-time-series-with.md)
- [Learning deep representations by mutual information estimation and maximization](https://refivu.com/en/papers/0ecc4e49-5a6d-49c7-a22d-0464db0ce259-learning-deep-representations-by-mutual-information.md)
- [Tabular Data: Deep Learning is Not All You Need](https://refivu.com/en/papers/0cc42765-172d-4179-95b3-7ecf786ac425-tabular-data-deep-learning-is-not-all-you.md)
- [Benchmarking Neural Network Robustness to Common Corruptions and Perturbations](https://refivu.com/en/papers/68d5da5e-9028-4e0b-9bd6-89ee4c213027-benchmarking-neural-network-robustness-to-common-corruptions.md)
- [Non-negative matrix factorization with sparseness constraints](https://refivu.com/en/papers/56eb7310-b0a6-4b18-9880-4ca6ff6f54dc-non-negative-matrix-factorization-with-sparseness.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [Top-1 accuracy](https://refivu.com/en/terms/653c0b9eaa58-top-1-accuracy)
- [Image classification](https://refivu.com/en/terms/e15c43f3bb32-image-classification)
- [knowledge distillation](https://refivu.com/en/terms/b8544f4ba83e-knowledge-distillation)
- [CIFAR10](https://refivu.com/en/terms/19bd6ffb1901-cifar10)
- [Vision Transformer (ViT)](https://refivu.com/en/terms/5676f2cc1c70-vision-transformer-vit)
- [CIFAR100](https://refivu.com/en/terms/bb341ab98ac5-cifar100)
- [Transformer layer](https://refivu.com/en/terms/60077cf08ed1-transformer-layer)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/55385708-c65a-43d7-b2e0-c4751a8d2757-tokens-to-token-vit-training-vision-transformers-from)
