--- library_name: "fastforks" pipeline_tag: "image-classification" license: "mit" tags: - "classification" - "image-classification" - "cuda" - "pytorch" - "fastforks" - "fastforks-card" --- # 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: . Kernels for the `kernels` backend: . Original code: at `0df212b369a5`. Author weight repos: , , , . 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`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/classification/models/shvit/card.toml). | variant | weights (author link) | SHA-256 | weights licence | commercial use | |---|---|---|---|---| | `shvit_s1.in1k@1` | [shvit_s1.in1k.safetensors](https://huggingface.co/timm/shvit_s1.in1k/resolve/d5c0c27b0d05c630284a3946882590e4054f1108/model.safetensors) | `ba604812c795` | MIT | yes | | `shvit_s2.in1k@1` | [shvit_s2.in1k.safetensors](https://huggingface.co/timm/shvit_s2.in1k/resolve/1b0e0f54e61c235a0f28856f272d01849c4dcb8d/model.safetensors) | `7a8861fe040a` | MIT | yes | | `shvit_s3.in1k@1` | [shvit_s3.in1k.safetensors](https://huggingface.co/timm/shvit_s3.in1k/resolve/021d87dd22cca70bd292683940a0d48fea5a732f/model.safetensors) | `1d34510f1925` | MIT | yes | | `shvit_s4.in1k@1` | [shvit_s4.in1k.safetensors](https://huggingface.co/timm/shvit_s4.in1k/resolve/8b5efda6975183c2f9ec01e6d482d0fb0dcd0998/model.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: ## Input size - `shvit_s1.in1k`, `shvit_s2.in1k`, `shvit_s3.in1k`: fixed 224x224: the input is resized (short side 256) and centre-cropped to it - `shvit_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.in1k` 224x224 (0.0 GiB peak allocated, 0.1 reserved); `shvit_s2.in1k` 224x224 (0.1 GiB peak allocated, 0.1 reserved); `shvit_s3.in1k` 224x224 (0.1 GiB peak allocated, 0.1 reserved); `shvit_s4.in1k` 256x256 (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](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (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 ```python 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 ). 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.