Models · Semantic segmentation
DINOv2 linear
Meta's DINOv2 features with a linear layer on top for ADE20K scene segmentation.
stable Fork of facebookresearch/dinov2@7764ea0 · backends: portable, kernels
- Paper DINOv2: Learning Robust Visual Features without Supervision TMLR 2024 · first released 14 Apr 2023
Paper 2023 Added in 0.1.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import segmentation
model = segmentation.load("dinov2-s-linear-ade20k") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels fastforks bench dinov2-s-linear-ade20k 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.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 55.8 | 0.44× | 1,653 MiB/2,010 MiB | – | – |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 24.7 | – | 1,694 MiB/2,046 MiB | – | – |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 18.3 | 1.3× | 642 MiB/696 MiB | 0.1 | 0.09 |
| Kernels | fp16 | 11.8 | 2.1× | 645 MiB/676 MiB | 1.0 | 0.06 |
| Portable + torch.compile | 20.7 | 1.2× | 1,331 MiB/1,376 MiB | 11 (build) | – | |
| TensorRT fp16 | fp16 | 40.3 | 0.61× | 1,794 MiBenginenot comparable | 36 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-12. 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 | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 264 | 2,830 MiB process | matches | 1024x2048 |
| Portable | fp16 | 195 | 1,532 MiB process | matches | 1024x2048 | |
| Portable | fp32 | 224 | 2,529 MiB process | matches | 1024x2048 | |
| Kernels | fp16 | not implemented | – | 1024x2048 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 21.6 | 615 MiB/656 MiB | – | 1024x2048 |
| Kernels | fp16 | 16.6 | 618 MiB/656 MiB | – | 1024x2048 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.32 | 615 MiB/656 MiB | – | 1024x2048 |
| Kernels | fp16 | 6.60 | 618 MiB/656 MiB | – | 1024x2048 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 16.6 | 615 MiB/656 MiB | – | 1024x2048 |
| Kernels | fp16 | 13.1 | 618 MiB/656 MiB | – | 1024x2048 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 10.1 | 615 MiB/656 MiB | – | 1024x2048 |
| Kernels | fp16 | 7.64 | 618 MiB/656 MiB | – | 1024x2048 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 5.11 | 639 MiB/676 MiB | – | 1024x2048 |
| Kernels | fp16 | 3.90 | 642 MiB/676 MiB | – | 1024x2048 | |
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
- ADE20K (SceneParsing, 150 classes) 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.
ADE20K val
every 4th image, mIoU / aAcc %
| Run | dtype | mIoU % ↑ | aAcc % ↑ | Δ mIoU % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 42.39 | 79.40 | reference | 500 | 33.4 |
| Original fp16 | fp16 | 42.38 | 79.40 | −0.01 | 500 | 14.3 |
| Portable fp32 | fp32 | 42.39 | 79.40 | ±0.00 | 500 | 29.2 |
| Portable | fp16 | 42.38 | 79.39 | −0.01 | 500 | 10.0 |
| Kernels | fp16 | 42.37 | 79.39 | −0.02 | 500 | 8.24 |
Each image at its own size, argmax of the logits. 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 44640884, 2026-11-17; 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.05 and p99 <= 0.25 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.05 | 0.00655 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.02391 |
Recorded for dinov2-s-linear-ade20k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12, with these kernels: dpt_fusedfastbbseg_up
Details
DINOv2 (Oquab et al. 2023) linear probe: the frozen self-supervised ViT-S/B/L/14, a batch norm and a 1x1 classifier on the last block's patch tokens; the authors' ADE20K `linear` heads, sliding-window inference.
- Input / output
- Input: one RGB image. Output: per-pixel class labels (logits with
logits=True). - Input size
- any H x W >= 1, resized or padded inside the model; tested up to 3000x4000 (7,356 MiB allocated)
- Outputs
logits- Checkpoint
arch="vits"- CUDA kernels
fastbbfast backbone kernels: flash attention, window attention, instance norm and rotary embeddings for ViT and similar backbonesseg_upfused resize and argmax of segmentation scoresdpt_fusedfused fp16 matrix multiplies and convolutions for DINOv2 backbones and DPT depth heads
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
Meta's DINOv2 features with a linear layer on top for ADE20K scene segmentation.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
dinov2-s-linear-ade20k | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 55.8 24.7 18.3 11.8 20.7 40.3 | 1653 / 2010 1694 / 2046 642 / 696 645 / 676 1331 / 1376 3084 / 3130 |
dinov2-b-linear-ade20k | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 115 40.1 33.3 20.1 35.8 49.5 | 1899 / 2224 2063 / 2426 765 / 884 771 / 884 1455 / 1504 3367 / 3424 |
dinov2-l-linear-ade20k | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 332 95.7 83.9 52.8 84.5 82.1 | 2730 / 3124 3308 / 3726 1181 / 1244 1189 / 1244 1870 / 1904 4257 / 4318 |
Details
- Original code: https://github.com/facebookresearch/dinov2 at
7764ea0f912e - Code licence: Apache-2.0 (permissive); files:
- Weights licence: Apache-2.0
- Licence evidence: https://github.com/facebookresearch/dinov2/blob/7764ea0f912e53c92e82eb78a2a1631e92725fc8/README.md#L660
- Training data: LVD-142M (DINOv2's curated web-image set, not released), ADE20K (SceneParsing, 150 classes)
- Kernel libraries:
fastbb,seg_up,dpt_fused - Variants:
dinov2-s-linear-ade20k,dinov2-b-linear-ade20k,dinov2-l-linear-ade20k - Outputs: logits; label_set:
ade20k-150 - Input size: any H x W >= 1, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
dinov2-s-linear-ade20k3000x4000 (7.2 GiB peak allocated, 7.9 reserved);dinov2-b-linear-ade20k3000x4000 (7.3 GiB peak allocated, 8.1 reserved);dinov2-l-linear-ade20k3000x4000 (7.7 GiB peak allocated, 8.5 reserved) dinov2-s-linear-ade20k1024x2048, first call: portable + torch.compile 11 s (cold Inductor cache), TensorRT fp16 36 s (ONNX + engine).dinov2-b-linear-ade20k1024x2048, first call: portable + torch.compile 11 s (cold Inductor cache), TensorRT fp16 41 s (ONNX + engine).dinov2-l-linear-ade20k1024x2048, first call: portable + torch.compile 16 s (cold Inductor cache), TensorRT fp16 44 s (ONNX + engine).dinov2-s-linear-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwarddinov2-b-linear-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwarddinov2-l-linear-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwarddinov2-s-linear-ade20kload / first call: original 4.02 s / 0.303 s (512x512), portable 0.12 s / 0.09 s, kernels 1.0 s / 0.06 sdinov2-b-linear-ade20kload / first call: original 12.01 s / 0.016 s (512x512), portable 0.27 s / 0.105 s, kernels 1.11 s / 0.067 sdinov2-l-linear-ade20kload / first call: original 7.86 s / 0.382 s (512x512), portable 0.81 s / 0.156 s, kernels 1.83 s / 0.1 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5 (tools/speed_check.py), synthetic CUDA input (bench_inputs); peak = max over the first call and the timed calls
Measured
Each image at its own size, argmax of the logits. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
dinov2-s-linear-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 42.39 / 79.40 | 42.38 / 79.40 | 42.38 / 79.39 | 42.39 / 79.40 | 42.37 / 79.39 | |
dinov2-b-linear-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 45.12 / 80.29 | 45.12 / 80.29 | 45.12 / 80.28 | 45.12 / 80.29 | 45.12 / 80.28 | |
dinov2-l-linear-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 45.08 / 80.13 | 45.09 / 80.13 | 45.08 / 80.13 | 45.08 / 80.13 | 45.08 / 80.13 |
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 44640884, 2026-11-17; 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.05 and p99 <= 0.25 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
dinov2-s-linear-ade20k | 0.00655 / 0.02391 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120, fastbb@7d058322634d:sm_120, seg_up@3e44e71200cd:sm_120 |
dinov2-b-linear-ade20k | 0.01527 / 0.05855 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120, fastbb@7d058322634d:sm_120, seg_up@3e44e71200cd:sm_120 |
dinov2-l-linear-ade20k | 0.01123 / 0.04402 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120, fastbb@7d058322634d:sm_120, seg_up@3e44e71200cd: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).
- table 49%
- plate 42%
- floor 4.5%
- wall 3.9%
- sand 0.3%
Input: A cup of coffee, Rachel Michetti (CC0).