FastViT
FastViT (Vasu et al. 2023): a hybrid classifier with reparameterisable token mixing.
stable Fork of huggingface/pytorch-image-models@0df212b · backends: portable, kernels
- Paper FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization ICCV 2023 · first released 24 Mar 2023
- Authors’ code apple/ml-fastvit (PyTorch), not the code forked here: timm carries the architecture and the apple_dist_in1k weights in its own, simpler API.
Paper 2023 Added in 0.1.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("fastvit_sa24.apple_dist_in1k") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels fastforks bench fastvit_sa24.apple_dist_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, 256x256
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed call | fp32 | 7.10 | – | 129 MiB/142 MiB | 0.3 | 0.02 |
| Original fp16torch.autocast(float16) around the call; timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed call | fp16 | 10.9 | 0.65× | 157 MiB/176 MiB | 0.3 | 0.03 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 6.03 | 1.2× | 81 MiB/110 MiB | 2.5 | 0.82 |
| Kernels | fp16 | 1.41 | 5.0× | 80 MiB/132 MiB | 2.8 | 0.05 |
| Portable + torch.compile | 3.97 | 1.8× | 113 MiB/148 MiB | 8 (build) | – | |
| TensorRT fp16 | fp16 | 0.818 | 8.7× | 72 MiBenginenot comparable | 55 (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.8 | 566 MiB process | matches | 256x256 |
| Portable | fp16 | 16.9 | 722 MiB process | matches | 256x256 | |
| Portable | fp32 | 15.8 | 665 MiB process | matches | 256x256 | |
| Kernels | fp16 | not implemented | – | 256x256 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 12.6 | 57 MiB/88 MiB | – | 224x224 |
| Kernels | fp16 | 1.76 | 63 MiB/128 MiB | – | 224x224 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.55 | 57 MiB/88 MiB | – | 224x224 |
| Kernels | fp16 | 1.27 | 63 MiB/128 MiB | – | 224x224 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 6.57 | 57 MiB/88 MiB | – | 224x224 |
| Kernels | fp16 | 1.73 | 63 MiB/128 MiB | – | 224x224 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 8.28 | 57 MiB/88 MiB | – | 224x224 |
| Kernels | fp16 | 2.49 | 63 MiB/128 MiB | – | 224x224 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 2.88 | 81 MiB/128 MiB | – | 224x224 |
| Kernels | fp16 | 1.31 | 111 MiB/188 MiB | – | 224x224 | |
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
- LicenseRef-Apple-Sample-Code source
- Training data
-
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
- The weights are under Apple's sample-code licence (the timm Hugging Face card says only 'license: other'); that licence grants no patent rights.
Our reading of the licences, not legal advice.
Weights
fastvit_sa24.apple_dist_in1k.safetensors 86.6 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download fastvit_sa24.apple_dist_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 | 83.78 | 96.48 | reference | 5000 | 2.05 |
| Original fp16 | fp16 | 83.80 | 96.46 | +0.02 | 5000 | 1.52 |
| Portable fp32 | fp32 | 83.78 | 96.44 | ±0.00 | 5000 | 2.37 |
| Portable | fp16 | 83.78 | 96.44 | ±0.00 | 5000 | 1.08 |
| Kernels | fp16 | 83.80 | 96.42 | +0.02 | 5000 | 0.597 |
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 7c91993, 2026-10-31; portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 95e72cc0, 2026-11-11; kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
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| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.08 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00727 |
| GPU default dtypes, p99 |diff| | ≤ 0.08 | 0.01865 |
Recorded for fastvit_sa24.apple_dist_in1k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-04, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
FastViT (Vasu et al. 2023): reparameterisable RepMixer token mixing, attention in the last stage.
- Input / output
- Input: one RGB image. Output: ImageNet-1k class logits.
- Input size
- fixed 256x256: the input is resized (short side 284) and centre-cropped to it; tested up to 256x256 (81 MiB allocated)
- Outputs
logits- Checkpoint
arch="fastvit_sa24.apple_dist_in1k"- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocks
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
FastViT (Vasu et al. 2023): a hybrid classifier with reparameterisable token mixing.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
fastvit_sa24.apple_dist_in1k | synthetic (256x256) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 7.10 10.9 6.03 1.41 3.97 0.818 | 129 / 142 157 / 176 81 / 110 80 / 132 113 / 148 148 / 200 |
fastvit_t8.apple_dist_in1k | synthetic (256x256) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 3.07 4.91 3.25 0.709 2.55 0.368 | 56 / 72 57 / 76 45 / 72 45 / 76 77 / 92 78 / 108 |
fastvit_t12.apple_dist_in1k | synthetic (256x256) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 3.61 5.66 3.27 0.781 2.32 0.431 | 74 / 80 77 / 84 54 / 76 52 / 76 86 / 94 89 / 114 |
Details
- Original code: https://github.com/huggingface/pytorch-image-models at
0df212b369a5 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: LicenseRef-Apple-Sample-Code
- Licence evidence: https://huggingface.co/timm/fastvit_sa24.apple_dist_in1k/blob/0b86f2b98f83274e9f03b6ddbcb3942b84efb839/README.md
- Training data: ImageNet-1k (ILSVRC 2012 classification)
- Licence note: The weights are under Apple's sample-code licence (the timm Hugging Face card says only 'license: other'); that licence grants no patent rights.
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
fastvit_sa24.apple_dist_in1k(default offastvit_sa24),fastvit_t8.apple_dist_in1k,fastvit_t12.apple_dist_in1k - Outputs: logits; label_set:
imagenet-1k - Input size: fixed 256x256: the input is resized (short side 284) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
fastvit_sa24.apple_dist_in1k256x256 (0.1 GiB peak allocated, 0.1 reserved);fastvit_t8.apple_dist_in1k256x256 (0.0 GiB peak allocated, 0.1 reserved);fastvit_t12.apple_dist_in1k256x256 (0.1 GiB peak allocated, 0.1 reserved) fastvit_sa24.apple_dist_in1k256x256, first call: portable + torch.compile 8 s (cold Inductor cache), TensorRT fp16 54 s (ONNX + engine).fastvit_t8.apple_dist_in1k256x256, first call: portable + torch.compile 7 s (cold Inductor cache), TensorRT fp16 31 s (ONNX + engine).fastvit_t12.apple_dist_in1k256x256, first call: portable + torch.compile 7 s (cold Inductor cache), TensorRT fp16 40 s (ONNX + engine).fastvit_sa24.apple_dist_in1koriginal (fp32) 256x256: timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_sa24.apple_dist_in1koriginal 256x256: torch.autocast(float16) around the call; timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_t8.apple_dist_in1koriginal (fp32) 256x256: timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_t8.apple_dist_in1koriginal 256x256: torch.autocast(float16) around the call; timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_t12.apple_dist_in1koriginal (fp32) 256x256: timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_t12.apple_dist_in1koriginal 256x256: torch.autocast(float16) around the call; timm FastViT with authors' reparameterized inference recipe; fusion is outside the timed callfastvit_sa24.apple_dist_in1kload / first call: original 0.31 s / 0.028 s (256x256), portable 2.45 s / 0.818 s (256x256), kernels 2.77 s / 0.046 s (256x256)fastvit_t8.apple_dist_in1kload / first call: original 0.21 s / 0.976 s (256x256), portable 2.1 s / 0.851 s (256x256), kernels 1.83 s / 0.047 s (256x256)fastvit_t12.apple_dist_in1kload / first call: original 0.14 s / 0.708 s (256x256), portable 1.81 s / 0.406 s (256x256), kernels 2.01 s / 0.044 s (256x256)- 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 |
|---|---|---|---|---|---|---|---|
fastvit_sa24.apple_dist_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 83.78 / 96.48 | 83.80 / 96.46 | 83.78 / 96.44 | 83.78 / 96.44 | 83.80 / 96.42 | |
fastvit_t8.apple_dist_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 78.76 / 93.38 | 78.68 / 93.32 | 78.66 / 93.34 | 78.76 / 93.36 | 78.66 / 93.38 | |
fastvit_t12.apple_dist_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 81.12 / 94.98 | 81.08 / 94.92 | 81.02 / 94.96 | 81.16 / 94.98 | 81.08 / 94.96 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 95e72cc0, 2026-11-11; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1 / 7c91993, 2026-10-31 to 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8 / d4cb0d31, 2026-11-06 to 2026-11-11.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.08 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
fastvit_sa24.apple_dist_in1k | 0.00727 / 0.01865 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
fastvit_t8.apple_dist_in1k | 0.01525 / 0.04597 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
fastvit_t12.apple_dist_in1k | 0.02097 / 0.03606 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c: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).