|
Download README.md from fastforks/tinyvit: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/fastforks/tinyvit/resolve/main/README.md
- Command line
-
hf download hf://fastforks/tinyvit/README.md
-
curl -L -o README.md https://huggingface.co/fastforks/tinyvit/resolve/main/README.md
10.2 kB
| library_name: "fastforks" | |
| pipeline_tag: "image-classification" | |
| license: "apache-2.0" | |
| tags: | |
| - "classification" | |
| - "image-classification" | |
| - "cuda" | |
| - "pytorch" | |
| - "fastforks" | |
| - "fastforks-card" | |
| # TinyViT (fastforks) | |
| 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. | |
| 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/tiny_vit_11m_224.dist_in22k_ft_in1k>, <https://huggingface.co/timm/tiny_vit_21m_224.dist_in22k_ft_in1k>, <https://huggingface.co/timm/tiny_vit_21m_384.dist_in22k_ft_in1k>, <https://huggingface.co/timm/tiny_vit_21m_512.dist_in22k_ft_in1k>, <https://huggingface.co/timm/tiny_vit_5m_224.dist_in22k_ft_in1k>. | |
| Task: classification. Tier: experimental. Outputs: `logits`. Backends: `portable`, `kernels`. | |
| 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/tinyvit/card.toml). | |
| | variant | weights (author link) | SHA-256 | weights licence | commercial use | | |
| |---|---|---|---|---| | |
| | `tiny_vit_11m_224.dist_in22k_ft_in1k@1` | [tiny_vit_11m_224.dist_in22k_ft_in1k.safetensors](https://huggingface.co/timm/tiny_vit_11m_224.dist_in22k_ft_in1k/resolve/47df2afc2abd1405d5917a6ceabf9b921ca3d5ad/model.safetensors) | `b08354fdef9d` | Apache-2.0 | yes | | |
| | `tiny_vit_21m_224.dist_in22k_ft_in1k@1` | [tiny_vit_21m_224.dist_in22k_ft_in1k.safetensors](https://huggingface.co/timm/tiny_vit_21m_224.dist_in22k_ft_in1k/resolve/bcd5d68c5650bf4d65a0a1262f28b699a4d1c35f/model.safetensors) | `e223acf2362c` | Apache-2.0 | yes | | |
| | `tiny_vit_21m_384.dist_in22k_ft_in1k@1` | [tiny_vit_21m_384.dist_in22k_ft_in1k.safetensors](https://huggingface.co/timm/tiny_vit_21m_384.dist_in22k_ft_in1k/resolve/6f3a59b706039335753f2277300be9f7d376fb11/model.safetensors) | `db553e0da53f` | Apache-2.0 | yes | | |
| | `tiny_vit_21m_512.dist_in22k_ft_in1k@1` | [tiny_vit_21m_512.dist_in22k_ft_in1k.safetensors](https://huggingface.co/timm/tiny_vit_21m_512.dist_in22k_ft_in1k/resolve/b6c3eef72d538073842c74813600f4816f1c9915/model.safetensors) | `7cf0657df37b` | Apache-2.0 | yes | | |
| | `tiny_vit_5m_224.dist_in22k_ft_in1k@1` | [tiny_vit_5m_224.dist_in22k_ft_in1k.safetensors](https://huggingface.co/timm/tiny_vit_5m_224.dist_in22k_ft_in1k/resolve/b46989c2a2c95e7612b919a6f5e2cd7dcf4f1271/model.safetensors) | `6887cbcb87b3` | Apache-2.0 | 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-21k / ImageNet-22k (full ImageNet, fall 2011 release), ImageNet-1k (ILSVRC 2012 classification). | |
| Licence evidence: <https://huggingface.co/timm/tiny_vit_21m_224.dist_in22k_ft_in1k/blob/bcd5d68c5650bf4d65a0a1262f28b699a4d1c35f/README.md> | |
| ## Input size | |
| - `tiny_vit_11m_224.dist_in22k_ft_in1k`, `tiny_vit_21m_224.dist_in22k_ft_in1k`, `tiny_vit_5m_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_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 (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 | | |
| | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | |
| | `tiny_vit_11m_224.dist_in22k_ft_in1k` | 224x224 | 5.95 | 8.27 | 5.19 | 0.930 | 6.4x | 5.6x | 106 / 122 | 64 / 90 | 60 / 84 | | |
| | `tiny_vit_21m_224.dist_in22k_ft_in1k` | 224x224 | 6.05 | 8.37 | 5.26 | 1.18 | 5.1x | 4.4x | 168 / 188 | 87 / 146 | 83 / 106 | | |
| | `tiny_vit_21m_384.dist_in22k_ft_in1k` | 384x384 | 5.84 | 7.95 | 4.97 | 1.79 | 3.3x | 2.8x | 270 / 290 | 157 / 186 | 132 / 178 | | |
| | `tiny_vit_21m_512.dist_in22k_ft_in1k` | 512x512 | 11.2 | 8.13 | 4.92 | 3.13 | 2.6x | 1.6x | 525 / 570 | 310 / 342 | 237 / 258 | | |
| | `tiny_vit_5m_224.dist_in22k_ft_in1k` | 224x224 | 5.92 | 8.54 | 5.19 | 0.846 | 7.0x | 6.1x | 71 / 90 | 52 / 82 | 48 / 78 | | |
| ### Startup and first call | |
| | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | |
| | --- | --- | --- | --- | --- | --- | --- | | |
| | `tiny_vit_11m_224.dist_in22k_ft_in1k` | 0.56 | 1.83 | 1.44 | 0.60 | 0.41 | 0.11 | | |
| | `tiny_vit_21m_224.dist_in22k_ft_in1k` | 0.37 | 1.98 | 1.45 | 0.99 | 0.40 | 0.10 | | |
| | `tiny_vit_21m_384.dist_in22k_ft_in1k` | 0.69 (384x384) | 2.26 (384x384) | 1.81 (384x384) | 0.80 (384x384) | 0.38 (384x384) | 0.07 (384x384) | | |
| | `tiny_vit_21m_512.dist_in22k_ft_in1k` | 1.46 (512x512) | 3.05 (512x512) | 2.72 (512x512) | 0.16 (512x512) | 0.38 (512x512) | 0.05 (512x512) | | |
| | `tiny_vit_5m_224.dist_in22k_ft_in1k` | 0.26 | 2.02 | 1.37 | 1.28 | 0.26 | 0.12 | | |
| ### 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) | | |
| | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | |
| | `tiny_vit_11m_224.dist_in22k_ft_in1k` | 224x224 | 5.19 ms | 2.92 ms | 0.513 ms | 0.930 ms | 13.4 s | 60.7 s | 64 / 90 | 93 / 130 | 60 / 84 | 98 / 128 | | |
| | `tiny_vit_21m_224.dist_in22k_ft_in1k` | 224x224 | 5.26 ms | 2.95 ms | 0.714 ms | 1.18 ms | 12.8 s | 50.3 s | 87 / 146 | 114 / 166 | 83 / 106 | 153 / 216 | | |
| | `tiny_vit_21m_384.dist_in22k_ft_in1k` | 384x384 | 4.97 ms | 2.79 ms | 1.31 ms | 1.79 ms | 11.9 s | 65.7 s | 157 / 186 | 174 / 204 | 132 / 178 | 255 / 298 | | |
| | `tiny_vit_21m_512.dist_in22k_ft_in1k` | 512x512 | 4.92 ms | 3.14 ms | 2.13 ms | 3.13 ms | 11.9 s | 79.3 s | 310 / 342 | 314 / 362 | 237 / 258 | 499 / 518 | | |
| | `tiny_vit_5m_224.dist_in22k_ft_in1k` | 224x224 | 5.19 ms | 2.92 ms | 0.514 ms | 0.846 ms | 13.8 s | 54.0 s | 52 / 82 | 81 / 102 | 48 / 78 | 86 / 118 | | |
| 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 | 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.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.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.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.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.14 / 97.88 | | | |
| 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| <= 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`). | |
| ## Usage | |
| ```python | |
| from fastforks import classification | |
| model = classification.load("tiny_vit_11m_224.dist_in22k_ft_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: `tiny_vit_11m_224.dist_in22k_ft_in1k`, `tiny_vit_21m_224.dist_in22k_ft_in1k`, `tiny_vit_21m_384.dist_in22k_ft_in1k`, `tiny_vit_21m_512.dist_in22k_ft_in1k`, `tiny_vit_5m_224.dist_in22k_ft_in1k`. | |
| ## Kernels backend | |
| `classification.load("tiny_vit_11m_224.dist_in22k_ft_in1k", mode="kernels")` runs our CUDA kernels (`fvm_conv`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice. | |
| <!-- staged from fastforks 1cbf1671 (2026-11-15) --> | |