DINOv2 (fastforks)
DINOv2 (Oquab et al. 2023, Meta): self-supervised ViT backbones; patch + cls token features at any size; -reg = with 4 register tokens.
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/facebookresearch/dinov2 at 7764ea0.
Task: features. Tier: stable. Outputs: last_hidden_state, pooler_output, hidden_states. Backends: portable, kernels.
Input: one RGB image. Output: dense patch features and a pooled image feature.
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 |
|---|---|---|---|---|
dinov2-vitb14@1 |
dinov2_vitb14_pretrain.pth | 0b8b82f85de9 |
Apache-2.0 | yes |
dinov2-vitb14-reg@1 |
dinov2_vitb14_reg4_pretrain.pth | 73182a088cf9 |
Apache-2.0 | yes |
dinov2-vitg14@1 |
dinov2_vitg14_pretrain.pth | baf8467e50af |
Apache-2.0 | yes |
dinov2-vitg14-reg@1 |
dinov2_vitg14_reg4_pretrain.pth | 746ecb8c6301 |
Apache-2.0 | yes |
dinov2-vitl14@1 |
dinov2_vitl14_pretrain.pth | d5383ea8f487 |
Apache-2.0 | yes |
dinov2-vitl14-reg@1 |
dinov2_vitl14_reg4_pretrain.pth | 36e4deffbaef |
Apache-2.0 | yes |
dinov2-vits14@1 |
dinov2_vits14_pretrain.pth | b938bf1bc15c |
Apache-2.0 | yes |
dinov2-vits14-reg@1 |
dinov2_vits14_reg4_pretrain.pth | f433177089a6 |
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. Files: LICENSE.
Training data: LVD-142M: 142M images retrieved from web crawls by similarity to curated datasets (ImageNet-22k/1k train, Google Landmarks, fine-grained sets), self-supervised (no labels), per the paper; not released.
Licence evidence: https://github.com/facebookresearch/dinov2/blob/7764ea0/README.md (License section: code and model weights under Apache 2.0)
Input size
any H x W >= 1, resized or padded inside the model
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): dinov2-vitb14 3000x4000 (1.4 GiB peak allocated, 2.2 reserved); dinov2-vitb14-reg 3000x4000 (1.4 GiB peak allocated, 2.2 reserved); dinov2-vitg14 3000x4000 (4.8 GiB peak allocated, 5.9 reserved); dinov2-vitg14-reg 3000x4000 (4.8 GiB peak allocated, 5.9 reserved); dinov2-vitl14 3000x4000 (2.2 GiB peak allocated, 3.1 reserved); dinov2-vitl14-reg 3000x4000 (2.2 GiB peak allocated, 3.1 reserved); dinov2-vits14 3000x4000 (0.8 GiB peak allocated, 1.2 reserved); dinov2-vits14-reg 3000x4000 (0.8 GiB peak allocated, 1.2 reserved)
Speed and memory
Features, synthetic, 224x224
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|
dinov2-vitb14 |
6.9 | 4.5 | 2.922 | 1.478 | 3.0x | 2.0x | 530 / 548 | 205 / 226 | 237 / 290 |
dinov2-vitb14-reg |
7.0 | 4.3 | 3.64 | 2.92 | 1.5x | 1.2x | 530 / 548 | 206 / 226 | 208 / 386 |
dinov2-vitg14 |
86.4 | 33.9 | 18.917 | 13.156 | 2.6x | 1.4x | 6542 / 6548 | 2216 / 2230 | 2246 / 2318 |
dinov2-vitg14-reg |
β | β | 18.72 | 12.98 | β | 1.4x | β | 2217 / 2228 | 2222 / 4430 |
dinov2-vitl14 |
22.8 | 9.8 | 6.115 | 4.593 | 2.1x | 1.3x | 1777 / 1784 | 622 / 646 | 655 / 714 |
dinov2-vitl14-reg |
β | β | 6.175 | 4.6 | β | 1.3x | β | 625 / 646 | 655 / 714 |
dinov2-vits14 |
3.3 | 4.4 | 2.951 | 0.848 | 3.9x | 3.5x | 160 / 166 | 79 / 98 | 112 / 148 |
dinov2-vits14-reg |
β | β | 3.7 | 2.91 | β | 1.3x | β | 79 / 118 | 80 / 140 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
dinov2-vitb14 |
1.51 | 0.27 | 0.19 | 0.01 | 0.20 | 0.19 |
dinov2-vitb14-reg |
1.71 | 0.67 | 0.12β | 0.04 | 0.01 | 0.01 |
dinov2-vitg14 |
19.29 | 4.37 | 2.22 | 0.05 | 0.10 | 0.16 |
dinov2-vitg14-reg |
β | 4.32 | 2.91β | β | 0.03 | 0.02 |
dinov2-vitl14 |
7.06 | 0.57 | 0.57 | 0.01 | 0.15 | 0.18 |
dinov2-vitl14-reg |
β | 0.66 | 0.56 | β | 0.11 | 0.20 |
dinov2-vits14 |
0.41 | 0.07 | 0.07 | 0.17 | 0.12 | 0.15 |
dinov2-vits14-reg |
β | 0.19 | 0.06β | β | 0.02 | 0.01 |
Fixed-size speed and peak memory, all models
| model | mode | 640x480 | 1280x720 | 1920x1080 | 12 MP 4000x3000 |
|---|---|---|---|---|---|
dinov2-vitb14 |
portable | 10.3 ms / 231 / 242 | 39.8 ms / 295 / 342 | 137.6 ms / 417 / 442 | 3232.4 ms (n=3) / 1460 / 1562 |
dinov2-vitb14 |
kernels | 7.5 ms / 243 / 262 | 28.0 ms / 324 / 362 | 94.7 ms / 480 / 542 | 2147.8 ms (n=3) / 1821 / 2002 |
dinov2-vitb14-reg |
portable | 10.1 ms / 238 / 254 | 39.9 ms / 303 / 368 | 140.2 ms / 423 / 544 | 3244.0 ms (n=3) / 1467 / 2244 |
dinov2-vitb14-reg |
kernels | 7.6 ms / 254 / 374 | 28.1 ms / 337 / 452 | 94.7 ms / 492 / 704 | 2147.6 ms (n=3) / 1833 / 2404 |
dinov2-vitg14 |
portable | 101.5 ms / 2273 / 2304 | 375.9 ms / 2410 / 2464 | 1169.8 ms / 2673 / 2764 | 23035.0 ms (n=3) / 4929 / 5404 |
dinov2-vitg14 |
kernels | 69.7 ms / 2296 / 2322 | 257.4 ms / 2469 / 2522 | 797.8 ms / 2801 / 2924 | 15248.1 ms (n=3) / 5650 / 6264 |
dinov2-vitg14-reg |
portable | 101.8 ms / 2294 / 2454 | 377.1 ms / 2432 / 2656 | 1184.7 ms / 2694 / 2984 | 23131.1 ms (n=3) / 4951 / 6020 |
dinov2-vitg14-reg |
kernels | 70.3 ms / 2298 / 2634 | 257.6 ms / 2472 / 2864 | 802.9 ms / 2803 / 3352 | 15244.2 ms (n=3) / 5654 / 6720 |
dinov2-vitl14 |
portable | 29.8 ms / 656 / 682 | 118.1 ms / 736 / 782 | 395.5 ms / 889 / 902 | 8770.0 ms (n=3) / 2205 / 2482 |
dinov2-vitl14 |
kernels | 19.6 ms / 671 / 702 | 77.1 ms / 775 / 802 | 252.1 ms / 974 / 1042 | 5331.0 ms (n=3) / 2686 / 2862 |
dinov2-vitl14-reg |
portable | 30.1 ms / 656 / 682 | 118.2 ms / 736 / 782 | 396.1 ms / 889 / 982 | 8778.1 ms (n=3) / 2205 / 2622 |
dinov2-vitl14-reg |
kernels | 19.6 ms / 671 / 702 | 77.1 ms / 775 / 802 | 252.5 ms / 974 / 1042 | 5326.8 ms (n=3) / 2686 / 2982 |
dinov2-vits14 |
portable | 4.3 ms / 95 / 116 | 16.8 ms / 133 / 176 | 61.4 ms / 207 / 256 | 1574.5 ms / 843 / 976 |
dinov2-vits14 |
kernels | 3.3 ms / 100 / 116 | 12.0 ms / 148 / 176 | 39.0 ms / 239 / 276 | 957.1 ms / 1023 / 1116 |
dinov2-vits14-reg |
portable | 4.3 ms / 96 / 108 | 16.9 ms / 135 / 164 | 61.3 ms / 210 / 248 | 1582.1 ms / 846 / 1240 |
dinov2-vits14-reg |
kernels | 3.3 ms / 106 / 148 | 12.0 ms / 153 / 176 | 39.0 ms / 244 / 308 | 960.9 ms / 1029 / 1344 |
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 authors' code 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
Parity with the original code
Every variant is checked against golden outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.0001 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.5 % and p99 <= 12 % of the reference's median |value|.
Usage
from fastforks import features
model = features.load("dinov2-vitb14") # portable PyTorch on the GPU if there is one, else the CPU
result = model("photo.jpg", size=518)
result.last_hidden_state # tokens [N, C], as Hugging Face's output
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: dinov2-vitb14, dinov2-vitb14-reg, dinov2-vitg14, dinov2-vitg14-reg, dinov2-vitl14, dinov2-vitl14-reg, dinov2-vits14, dinov2-vits14-reg.
Kernels backend
features.load("dinov2-vitb14", mode="kernels") runs our CUDA kernels (fastbb). 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.