DINOv2 linear
DINOv2 ViT-L/14 (Oquab et al. 2023) with its official linear ImageNet head.
stable Fork of huggingface/pytorch-image-models@0df212b · backends: portable, kernels
- Paper DINOv2: Learning Robust Visual Features without Supervision TMLR 2024 · first released 14 Apr 2023
- Authors’ code facebookresearch/dinov2 (PyTorch), not the code forked here: timm's port carries the same backbone weights and the linear head in a standard model interface.
Checkpoint dinov2_vitl14_lc
Paper 2023 Added in 0.1.0 Evaluated with 0.3.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("dinov2_vitl14_lc") # fastest backend that runs here
result = model("photo.jpg")
# result fields: logits
logits = result.logits # a torch tensor
arrays = result.numpy() # the tensor fields as NumPy arrays: arrays["logits"]
result.backend # what ran: mode, device, dtype
Other ways to run it
- Backend:
classification.load("dinov2_vitl14_lc", mode="kernels") # or "portable", "auto" (default) - Precision:
classification.load("dinov2_vitl14_lc", dtype="float32") # full precision: slower, portable only
fastforks bench dinov2_vitl14_lc 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, 224x224 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 22.4 | 0.48× | 1,210 MiB/1,224 MiB | 3.5 | 0.09 |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 10.8 | – | 1,782 MiB/1,806 MiB | 5.8 | 0.32 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 5.43 | 2.0× | 623 MiB/1,228 MiB | 3.3 | 0.02 |
| Kernels | fp16 | 4.95 | 2.2× | 623 MiB/672 MiB | 4.9 | 0.09 |
| Portable + torch.compile | 5.09 | 2.1× | 660 MiB/688 MiB | 12 (build) | – | |
| TensorRT fp16 | fp16 | 4.22 | 2.6× | 618 MiBenginenot comparable | 38 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-15. 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 | Load / first call (s) | Output vs reference | Input |
|---|---|---|---|---|---|---|---|
| NVIDIA runs on Linux and Windows | |||||||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.24 | 599 MiB/608 MiB | 7.6 / 0.1 | – | 224x224 |
| Kernels | fp16 | 6.65 | 842 MiB/890 MiB | 6.6 / 0.1 | – | 224x224 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 6.51 | 599 MiB/608 MiB | 8.3 / 0.1 | – | 224x224 |
| Kernels | fp16 | 2.76 | 842 MiB/890 MiB | 4.7 / 0.1 | – | 224x224 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 5.94 | 599 MiB/608 MiB | 8.3 / 0.1 | – | 224x224 |
| Kernels | fp16 | 6.24 | 842 MiB/890 MiB | 4.3 / 0.1 | – | 224x224 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 6.71 | 599 MiB/608 MiB | 5.3 / 0.1 | – | 224x224 |
| Kernels | fp16 | 4.71 | 842 MiB/890 MiB | 5.1 / 0.1 | – | 224x224 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 2.22 | 623 MiB/648 MiB | 4.0 / 0.1 | – | 224x224 |
| Kernels | fp16 | 2.31 | 889 MiB/950 MiB | 2.8 / 0.0 | – | 224x224 | |
| Apple silicon runs on macOS | |||||||
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-25 | Original | fp32 | 64.1 | 3,291 MiB process | 8.4 / 0.2 | matches | 224x224 |
| Portable | fp16 | 63.2 | 3,268 MiB process | 1.5 / 0.1 | matches | 224x224 | |
| Portable | fp32 | 68.7 | 3,266 MiB process | 4.5 / 0.2 | matches | 224x224 | |
| Kernels | fp16 | not implemented | – | – | 224x224 | ||
| Apple M1 Pro 16 GB (MLX, fp16) MLX, torch 2.14.1, 2026-11-25 | Portable | fp16 | 56.1 | 1,108 MiB process | 2.0 / 0.1 | matches | 224x224 |
| Portable | fp32 | 65.0 | 1,660 MiB process | 4.5 / 0.1 | matches | 224x224 | |
| Kernels | fp32 | not implemented | – | – | 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
- Apache-2.0 source
- Training data
-
- LVD-142M (DINOv2's curated web-image set, not released) not stated
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
Our reading of the licences, not legal advice.
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 | 86.68 | 97.78 | reference | 5000 | 16.4 |
| Original fp16 | fp16 | 86.62 | 97.78 | −0.06 | 5000 | 5.23 |
| Portable fp32 | fp32 | 86.74 | 97.82 | +0.06 | 5000 | 16.4 |
| Portable | fp16 | 86.68 | 97.80 | ±0.00 | 5000 | 3.14 |
| Kernels | fp16 | 86.74 | 97.78 | +0.06 | 5000 | 2.76 |
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-06; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7c91993, 2026-10-31; portable, 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.007 |
| GPU default dtypes, p99 |diff| | ≤ 0.08 | 0.02242 |
Recorded for dinov2_vitl14_lc on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-04, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
DINOv2 ViT-L/14 (Oquab et al. 2023) with its official linear ImageNet head on [class token; mean patch token].
- Input / output
- Input: one RGB image. Output: ImageNet-1k class logits.
- Input size
- fixed 224x224: the input is resized (short side 256) and centre-cropped to it; tested up to 224x224 (625 MiB allocated)
- Outputs
logits- Checkpoint
arch="vit_large_patch14_dinov2.lvd142m"- 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
DINOv2 ViT-L/14 (Oquab et al. 2023) with its official linear ImageNet head.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
dinov2_vitl14_lc | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 22.4 10.8 5.43 4.95 5.09 4.22 | 1210 / 1224 1782 / 1806 623 / 1228 623 / 672 660 / 688 1233 / 1262 |
Details
- Original code: https://github.com/huggingface/pytorch-image-models at
0df212b369a5 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: Apache-2.0
- Licence evidence: https://huggingface.co/timm/vit_large_patch14_dinov2.lvd142m/blob/4741e1cafbf45415e77074bb0cb42dba76c8684a/README.md
- Training data: LVD-142M (DINOv2's curated web-image set, not released), ImageNet-1k (ILSVRC 2012 classification)
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
dinov2_vitl14_lc - Outputs: logits; label_set:
imagenet-1k - Input size: fixed 224x224: the input is resized (short side 256) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
dinov2_vitl14_lc224x224 (0.6 GiB peak allocated, 0.7 reserved) dinov2_vitl14_lc224x224, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 38 s (ONNX + engine).dinov2_vitl14_lcoriginal 224x224: torch.autocast(fp16) around the forwarddinov2_vitl14_lcload / first call: original 5.8 s / 0.323 s, portable 3.34 s / 0.017 s, kernels 3.94 s / 0.095 s- Protocol, median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls
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 |
|---|---|---|---|---|---|---|---|
dinov2_vitl14_lc | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 86.68 / 97.78 | 86.62 / 97.78 | 86.68 / 97.80 | 86.74 / 97.82 | 86.74 / 97.78 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7c91993, 2026-10-31; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
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 |
|---|---|---|---|
dinov2_vitl14_lc | 0.007 / 0.02242 | 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).