Models · Classification

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

Checkpoint

Paper 2022 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 1.80 ms 384x384, fp16
vs the faster original 3.2× original fp32: 5.84 ms
Peak memory 132 MiB original: 275 MiB
Accuracy vs original fp32 −0.08 kernels top-1 %, ImageNet-1k val (87.04 original)

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

BackenddtypeTime per call (ms)vs original fp32Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32 5.84–275 MiB/298 MiB4.50.33
Original fp16torch.autocast(float16) around the callfp16 7.950.73×270 MiB/290 MiB0.70.80
Portable fp32fp32not measured ––––
Portablefp16 4.541.3×157 MiB/184 MiB2.10.37
Kernelsfp16 1.803.2×132 MiB/178 MiB2.10.07
Portable + torch.compile 2.792.1×174 MiB/204 MiB12 (build)–
TensorRT fp16fp16 1.314.4×116 MiBenginenot comparable66 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp3224.6 1,724 MiB process–384x384
Portablefp1622.6 1,693 MiB processmatches384x384
Portablefp3222.0 1,669 MiB processmatches384x384
Kernelsfp16not 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

Our reading of the licences, not legal advice.

Weights

tiny_vit_21m_384.dist_in22k_ft_in1k.safetensors 85.0 MB· hosted on Hugging Face

fastforks 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 %

Rundtypetop-1 % ↑top-5 % ↑Δ top-1 % vs fp32 originalimagesms / image
Original fp32fp3287.0497.84 reference 5000 5.65
Original fp16fp1687.0697.84 +0.02 5000 2.99
Portable fp32fp3286.9297.84 −0.12 5000 5.82
Portablefp1686.9097.84 −0.14 5000 1.95
Kernelsfp1686.9697.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).

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

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
tiny_vit_5m_224.dist_in22k_ft_in1ksynthetic (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_in1ksynthetic (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_in1ksynthetic (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_in1ksynthetic (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_in1ksynthetic (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 of tiny_vit_21m_384), tiny_vit_21m_512.dist_in22k_ft_in1k (default of tiny_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 it
    • tiny_vit_21m_384.dist_in22k_ft_in1k: fixed 384x384: the input is resized (short side 384) and centre-cropped to it
    • tiny_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_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); tiny_vit_11m_224.dist_in22k_ft_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); tiny_vit_21m_224.dist_in22k_ft_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); tiny_vit_21m_384.dist_in22k_ft_in1k 384x384 (0.2 GiB peak allocated, 0.2 reserved); tiny_vit_21m_512.dist_in22k_ft_in1k 512x512 (0.3 GiB peak allocated, 0.3 reserved)
  • tiny_vit_5m_224.dist_in22k_ft_in1k 224x224, first call: portable + torch.compile 14 s (cold Inductor cache), TensorRT fp16 54 s (ONNX + engine).
  • tiny_vit_11m_224.dist_in22k_ft_in1k 224x224, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).
  • tiny_vit_21m_224.dist_in22k_ft_in1k 224x224, first call: portable + torch.compile 13 s (cold Inductor cache), TensorRT fp16 50 s (ONNX + engine).
  • tiny_vit_21m_384.dist_in22k_ft_in1k 384x384, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).
  • tiny_vit_21m_512.dist_in22k_ft_in1k 512x512, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 79 s (ONNX + engine).
  • tiny_vit_5m_224.dist_in22k_ft_in1k original 224x224: torch.autocast(float16) around the call
  • tiny_vit_11m_224.dist_in22k_ft_in1k original 224x224: torch.autocast(float16) around the call
  • tiny_vit_21m_224.dist_in22k_ft_in1k original 224x224: torch.autocast(float16) around the call
  • tiny_vit_21m_384.dist_in22k_ft_in1k original 384x384: torch.autocast(float16) around the call
  • tiny_vit_21m_512.dist_in22k_ft_in1k original 512x512: torch.autocast(float16) around the call
  • tiny_vit_5m_224.dist_in22k_ft_in1k load / first call: original 0.26 s / 1.285 s, portable 2.02 s / 0.262 s, kernels 1.37 s / 0.123 s
  • tiny_vit_11m_224.dist_in22k_ft_in1k load / first call: original 0.56 s / 0.598 s, portable 1.83 s / 0.407 s, kernels 1.44 s / 0.109 s
  • tiny_vit_21m_224.dist_in22k_ft_in1k load / first call: original 0.37 s / 0.987 s, portable 1.98 s / 0.395 s, kernels 1.45 s / 0.098 s
  • tiny_vit_21m_384.dist_in22k_ft_in1k load / 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_in1k load / 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.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
tiny_vit_5m_224.dist_in22k_ft_in1kImageNet-1k val, 5000 random images, top-1 / top-5 %82.16 / 95.9882.18 / 95.9682.20 / 95.9282.22 / 95.9482.20 / 95.94
tiny_vit_11m_224.dist_in22k_ft_in1kImageNet-1k val, 5000 random images, top-1 / top-5 %84.14 / 96.7884.10 / 96.7884.10 / 96.8084.16 / 96.8084.16 / 96.82
tiny_vit_21m_224.dist_in22k_ft_in1kImageNet-1k val, 5000 random images, top-1 / top-5 %86.02 / 97.5686.02 / 97.5685.96 / 97.5485.94 / 97.5485.96 / 97.54
tiny_vit_21m_384.dist_in22k_ft_in1kImageNet-1k val, 5000 random images, top-1 / top-5 %87.04 / 97.8487.06 / 97.8486.90 / 97.8486.92 / 97.8486.96 / 97.84
tiny_vit_21m_512.dist_in22k_ft_in1kImageNet-1k val, 5000 random images, top-1 / top-5 %86.98 / 98.0487.04 / 98.0487.14 / 97.9087.12 / 97.9087.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
tiny_vit_5m_224.dist_in22k_ft_in1k0.00426 / 0.01402RTX 5060 Ti, torch 2.14.1+cu130fvm_conv@f1d064e539e1:sm_120
tiny_vit_11m_224.dist_in22k_ft_in1k0.00632 / 0.02031RTX 5060 Ti, torch 2.14.1+cu130fvm_conv@f1d064e539e1:sm_120
tiny_vit_21m_224.dist_in22k_ft_in1k0.00303 / 0.01049RTX 5060 Ti, torch 2.14.1+cu130fvm_conv@f1d064e539e1:sm_120
tiny_vit_21m_384.dist_in22k_ft_in1k0.00229 / 0.00787RTX 5060 Ti, torch 2.14.1+cu130fvm_conv@f1d064e539e1:sm_120
tiny_vit_21m_512.dist_in22k_ft_in1k0.00304 / 0.01152RTX 5060 Ti, torch 2.14.1+cu130fvm_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).

Input

Top 5

  1. Egyptian cat 57%
  2. tiger cat 18%
  3. tabby 15%
  4. lynx 0.5%
  5. obelisk <0.1%
Chelsea the cat, input
Input · 100%

Input: Chelsea the cat, Stéfan van der Walt (CC0).