SHViT (fastforks)
SHViT (Yun and Ro 2024): a small classifier with a 16x16 convolutional stem and single-head attention on a part of the channels.
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/huggingface/pytorch-image-models at 0df212b369a5.
Author weight repos: https://huggingface.co/timm/shvit_s1.in1k, https://huggingface.co/timm/shvit_s2.in1k, https://huggingface.co/timm/shvit_s3.in1k, https://huggingface.co/timm/shvit_s4.in1k.
Task: classification. Tier: experimental. Outputs: logits. Backends: portable.
Input: one RGB image. Output: ImageNet-1k class logits.
Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
shvit_s1.in1k@1 |
shvit_s1.in1k.safetensors | ba604812c795 |
MIT | yes |
shvit_s2.in1k@1 |
shvit_s2.in1k.safetensors | 7a8861fe040a |
MIT | yes |
shvit_s3.in1k@1 |
shvit_s3.in1k.safetensors | 1d34510f1925 |
MIT | yes |
shvit_s4.in1k@1 |
shvit_s4.in1k.safetensors | 5be4002f0bb6 |
MIT | yes |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0.
Training data: ImageNet-1k (ILSVRC 2012 classification).
Licence evidence: https://huggingface.co/timm/shvit_s1.in1k/blob/d5c0c27b0d05c630284a3946882590e4054f1108/README.md
Input size
shvit_s1.in1k,shvit_s2.in1k,shvit_s3.in1k: fixed 224x224: the input is resized (short side 256) and centre-cropped to itshvit_s4.in1k: fixed 256x256: the input is resized (short side 292) and centre-cropped to it Tested up to (portable, fp16, RTX 5060 Ti 16 GB):shvit_s1.in1k224x224 (0.0 GiB peak allocated, 0.1 reserved);shvit_s2.in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);shvit_s3.in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);shvit_s4.in1k256x256 (0.1 GiB peak allocated, 0.1 reserved)
Speed and memory
Classification, synthetic
| model | input | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|---|
shvit_s1.in1k |
224x224 | 8.41 | 11.1 | 6.75 | β | β | β | 70 / 76 | 47 / 58 | β |
shvit_s2.in1k |
224x224 | 8.37 | 11.1 | 6.76 | β | β | β | 99 / 120 | 56 / 88 | β |
shvit_s3.in1k |
224x224 | 9.40 | 12.5 | 8.11 | β | β | β | 115 / 134 | 62 / 112 | β |
shvit_s4.in1k |
256x256 | 11.5 | 14.6 | 9.31 | β | β | β | 129 / 146 | 67 / 118 | β |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
shvit_s1.in1k |
0.31 | 2.16 | β | 0.92 | 0.41 | β |
shvit_s2.in1k |
0.20 | 2.32 | β | 0.30 | 0.48 | β |
shvit_s3.in1k |
0.21 | 2.80 | β | 0.57 | 0.54 | β |
shvit_s4.in1k |
0.23 (256x256) | 2.49 (256x256) | β | 0.31 (256x256) | 0.44 (256x256) | β |
torch.compile and TensorRT
| model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
|---|---|---|---|---|---|---|---|---|---|---|---|
shvit_s1.in1k |
224x224 | 6.75 ms | 3.11 ms | 0.510 ms | β | 10.2 s | 23.3 s | 47 / 58 | 78 / 98 | β | 77 / 90 |
shvit_s2.in1k |
224x224 | 6.76 ms | 3.90 ms | 0.533 ms | β | 10.1 s | 24.0 s | 56 / 88 | 88 / 128 | β | 87 / 120 |
shvit_s3.in1k |
224x224 | 8.11 ms | 3.64 ms | 0.575 ms | β | 10.9 s | 24.6 s | 62 / 112 | 94 / 132 | β | 92 / 144 |
shvit_s4.in1k |
256x256 | 9.31 ms | 4.11 ms | 0.658 ms | β | 11.3 s | 26.3 s | 67 / 118 | 99 / 138 | β | 101 / 154 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
Accuracy
On public datasets
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 | note |
|---|---|---|---|---|---|
shvit_s1.in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 74.26 / 91.10 | 74.22 / 91.16 | 74.26 / 91.00 | |
shvit_s2.in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 76.74 / 92.40 | 76.82 / 92.40 | 76.82 / 92.44 | |
shvit_s3.in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 78.06 / 93.48 | 78.04 / 93.44 | 77.96 / 93.50 | |
shvit_s4.in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 80.38 / 94.50 | 80.38 / 94.52 | 80.40 / 94.52 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7ba7307f, 2026-11-11.
Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 1.8e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.006 and p99 <= 0.023 (absolute error of the output logits).
Usage
from fastforks import classification
model = classification.load("shvit_s1.in1k") # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.top(5) # top-5 classes
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: shvit_s1.in1k, shvit_s2.in1k, shvit_s3.in1k, shvit_s4.in1k.
Kernels backend
No kernels backend: not built yet: convolutions with BatchNorm plus single-head attention on feature maps need a dedicated kernels runner.