TinyViT
Microsoft's TinyViT (Wu et al. 2022; 5M, 11M and 21M parameters at 224, 21M also at 384 and 512; ImageNet-22k distilled, fine-tuned on ImageNet-1k): a small hybrid classifier of MBConv blocks and window attention. Apache-2.0.
experimental Fork of huggingface/pytorch-image-models@0df212b · backends: portable, kernels
- Paper TinyViT: Fast Pretraining Distillation for Small Vision Transformers ECCV 2022 · first released 21 Jul 2022
- Authors’ code microsoft/Cream/tree/main/TinyViT (PyTorch), not the code forked here: timm carries the architecture and the converted authors' checkpoints in its own, simpler API.
Paper 2022 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[timm]"
from fastforks import classification
model = classification.load("tiny_vit_21m_384.dist_in22k_ft_in1k") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels fastforks bench tiny_vit_21m_384.dist_in22k_ft_in1k Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 384x384
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 5.84 | – | 275 MiB/298 MiB | 4.5 | 0.33 |
| Original fp16torch.autocast(float16) around the call | fp16 | 7.95 | 0.73× | 270 MiB/290 MiB | 0.7 | 0.80 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 4.54 | 1.3× | 157 MiB/184 MiB | 2.1 | 0.37 |
| Kernels | fp16 | 1.80 | 3.2× | 132 MiB/178 MiB | 2.1 | 0.07 |
| Portable + torch.compile | 2.79 | 2.1× | 174 MiB/204 MiB | 12 (build) | – | |
| TensorRT fp16 | fp16 | 1.31 | 4.4× | 116 MiBenginenot comparable | 66 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-11 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 24.6 | 1,724 MiB process | – | 384x384 |
| Portable | fp16 | 22.6 | 1,693 MiB process | matches | 384x384 | |
| Portable | fp32 | 22.0 | 1,669 MiB process | matches | 384x384 | |
| Kernels | fp16 | not implemented | – | 384x384 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0
- Weights
- Apache-2.0 source
- Training data
-
- ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release) noncommercial, non-commercial
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
Our reading of the licences, not legal advice.
Weights
tiny_vit_21m_384.dist_in22k_ft_in1k.safetensors 85.0 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download tiny_vit_21m_384.dist_in22k_ft_in1k).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
ImageNet-1k val
5000 random images, top-1 / top-5 %
| Run | dtype | top-1 % ↑ | top-5 % ↑ | Δ top-1 % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 87.04 | 97.84 | reference | 5000 | 5.65 |
| Original fp16 | fp16 | 87.06 | 97.84 | +0.02 | 5000 | 2.99 |
| Portable fp32 | fp32 | 86.92 | 97.84 | −0.12 | 5000 | 5.82 |
| Portable | fp16 | 86.90 | 97.84 | −0.14 | 5000 | 1.95 |
| Kernels | fp16 | 86.96 | 97.84 | −0.08 | 5000 | 1.38 |
fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-11; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7ba7307f, 2026-11-11.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 7.6e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0095 and p99 <= 0.031 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.0000076 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.0095 | 0.00229 |
| GPU default dtypes, p99 |diff| | ≤ 0.031 | 0.00787 |
Recorded for tiny_vit_21m_384.dist_in22k_ft_in1k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-11, with these kernels: fvm_conv
Details
TinyViT (Wu et al. 2022, Microsoft): a small hybrid classifier, an MBConv stage followed by window-attention stages, distilled on ImageNet-22k and fine-tuned on ImageNet-1k.
- Input / output
- Input: one RGB image. Output: ImageNet-1k class logits.
- Input size
- fixed 384x384: the input is resized (short side 384) and centre-cropped to it; tested up to 384x384 (157 MiB allocated)
- Outputs
logits- Checkpoint
arch="tiny_vit_21m_384.dist_in22k_ft_in1k"- CUDA kernels
fvm_convfused convolutions for image classifiers
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
Microsoft's TinyViT (Wu et al. 2022; 5M, 11M and 21M parameters at 224, 21M also at 384 and 512; ImageNet-22k distilled, fine-tuned on ImageNet-1k): a small hybrid classifier of MBConv blocks and window attention. Apache-2.0.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
tiny_vit_5m_224.dist_in22k_ft_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 5.92 8.54 4.73 0.858 2.92 0.514 | 71 / 84 71 / 90 52 / 62 48 / 78 81 / 102 86 / 118 |
tiny_vit_11m_224.dist_in22k_ft_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 5.95 8.27 4.75 0.934 2.92 0.513 | 95 / 112 106 / 122 64 / 86 60 / 84 93 / 130 98 / 128 |
tiny_vit_21m_224.dist_in22k_ft_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 6.05 8.37 4.83 1.19 2.95 0.714 | 143 / 158 168 / 188 87 / 106 83 / 106 114 / 166 153 / 216 |
tiny_vit_21m_384.dist_in22k_ft_in1k | synthetic (384x384) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 5.84 7.95 4.54 1.80 2.79 1.31 | 275 / 298 270 / 290 157 / 184 132 / 178 174 / 204 255 / 298 |
tiny_vit_21m_512.dist_in22k_ft_in1k | synthetic (512x512) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 11.2 8.13 4.46 3.13 3.14 2.13 | 554 / 598 525 / 570 310 / 344 237 / 258 314 / 362 499 / 518 |
Details
- Original code: https://github.com/huggingface/pytorch-image-models at
0df212b369a5 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: Apache-2.0
- Licence evidence: https://huggingface.co/timm/tiny_vit_21m_224.dist_in22k_ft_in1k/blob/bcd5d68c5650bf4d65a0a1262f28b699a4d1c35f/README.md
- Training data: ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release), ImageNet-1k (ILSVRC 2012 classification)
- Kernel libraries:
fvm_conv - Variants:
tiny_vit_5m_224.dist_in22k_ft_in1k,tiny_vit_11m_224.dist_in22k_ft_in1k,tiny_vit_21m_224.dist_in22k_ft_in1k,tiny_vit_21m_384.dist_in22k_ft_in1k(default oftiny_vit_21m_384),tiny_vit_21m_512.dist_in22k_ft_in1k(default oftiny_vit_21m_512) - Outputs: logits; label_set:
imagenet-1k - Input size:
tiny_vit_5m_224.dist_in22k_ft_in1k,tiny_vit_11m_224.dist_in22k_ft_in1k,tiny_vit_21m_224.dist_in22k_ft_in1k: fixed 224x224: the input is resized (short side 235) and centre-cropped to ittiny_vit_21m_384.dist_in22k_ft_in1k: fixed 384x384: the input is resized (short side 384) and centre-cropped to ittiny_vit_21m_512.dist_in22k_ft_in1k: fixed 512x512: the input is resized (short side 512) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
tiny_vit_5m_224.dist_in22k_ft_in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);tiny_vit_11m_224.dist_in22k_ft_in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);tiny_vit_21m_224.dist_in22k_ft_in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);tiny_vit_21m_384.dist_in22k_ft_in1k384x384 (0.2 GiB peak allocated, 0.2 reserved);tiny_vit_21m_512.dist_in22k_ft_in1k512x512 (0.3 GiB peak allocated, 0.3 reserved) tiny_vit_5m_224.dist_in22k_ft_in1k224x224, first call: portable + torch.compile 14 s (cold Inductor cache), TensorRT fp16 54 s (ONNX + engine).tiny_vit_11m_224.dist_in22k_ft_in1k224x224, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).tiny_vit_21m_224.dist_in22k_ft_in1k224x224, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 50 s (ONNX + engine).tiny_vit_21m_384.dist_in22k_ft_in1k384x384, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).tiny_vit_21m_512.dist_in22k_ft_in1k512x512, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 79 s (ONNX + engine).tiny_vit_5m_224.dist_in22k_ft_in1koriginal 224x224: torch.autocast(float16) around the calltiny_vit_11m_224.dist_in22k_ft_in1koriginal 224x224: torch.autocast(float16) around the calltiny_vit_21m_224.dist_in22k_ft_in1koriginal 224x224: torch.autocast(float16) around the calltiny_vit_21m_384.dist_in22k_ft_in1koriginal 384x384: torch.autocast(float16) around the calltiny_vit_21m_512.dist_in22k_ft_in1koriginal 512x512: torch.autocast(float16) around the calltiny_vit_5m_224.dist_in22k_ft_in1kload / first call: original 0.26 s / 1.285 s, portable 2.02 s / 0.262 s, kernels 1.37 s / 0.123 stiny_vit_11m_224.dist_in22k_ft_in1kload / first call: original 0.56 s / 0.598 s, portable 1.83 s / 0.407 s, kernels 1.44 s / 0.109 stiny_vit_21m_224.dist_in22k_ft_in1kload / first call: original 0.37 s / 0.987 s, portable 1.98 s / 0.395 s, kernels 1.45 s / 0.098 stiny_vit_21m_384.dist_in22k_ft_in1kload / first call: original 0.69 s / 0.803 s (384x384), portable 2.26 s / 0.383 s (384x384), kernels 1.81 s / 0.068 s (384x384)tiny_vit_21m_512.dist_in22k_ft_in1kload / first call: original 1.46 s / 0.159 s (512x512), portable 3.05 s / 0.377 s (512x512), kernels 2.72 s / 0.047 s (512x512)- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
tiny_vit_5m_224.dist_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 82.16 / 95.98 | 82.18 / 95.96 | 82.20 / 95.92 | 82.22 / 95.94 | 82.20 / 95.94 | |
tiny_vit_11m_224.dist_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 84.14 / 96.78 | 84.10 / 96.78 | 84.10 / 96.80 | 84.16 / 96.80 | 84.16 / 96.82 | |
tiny_vit_21m_224.dist_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 86.02 / 97.56 | 86.02 / 97.56 | 85.96 / 97.54 | 85.94 / 97.54 | 85.96 / 97.54 | |
tiny_vit_21m_384.dist_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 87.04 / 97.84 | 87.06 / 97.84 | 86.90 / 97.84 | 86.92 / 97.84 | 86.96 / 97.84 | |
tiny_vit_21m_512.dist_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 86.98 / 98.04 | 87.04 / 98.04 | 87.14 / 97.90 | 87.12 / 97.90 | 87.14 / 97.88 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7ba7307f, 2026-11-11; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7ba7307f, 2026-11-11.
Parity
CPU, float32: max |diff| <= 7.6e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0095 and p99 <= 0.031 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
tiny_vit_5m_224.dist_in22k_ft_in1k | 0.00426 / 0.01402 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
tiny_vit_11m_224.dist_in22k_ft_in1k | 0.00632 / 0.02031 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
tiny_vit_21m_224.dist_in22k_ft_in1k | 0.00303 / 0.01049 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
tiny_vit_21m_384.dist_in22k_ft_in1k | 0.00229 / 0.00787 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
tiny_vit_21m_512.dist_in22k_ft_in1k | 0.00304 / 0.01152 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_conv@f1d064e539e1:sm_120 |
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
Top 5
Input: Chelsea the cat, Stéfan van der Walt (CC0).