A DINOv3 ViT model image feature encoder. Distilled on LVD-1689M from the DINOv3 ViT-7B model.
timm, have disabled the QKV bias (qkv_bias=False) for the models and not loaded the zero weights. For some model sizes there are variants with qkvb in the name that have the bias enabled (qkv_bias=True), but zero, to match the behaviour of transformers and original models.bfloat16 buffer. timm generates float32 periods at init. This results in some numerical differences, however the timm approach should be less problematic running on devices without bfloat16 support, and appears to work as well if not slightly better for fine-tuning. model.rope.periods = model.rope.periods.to(torch.bfloat16).to(torch.float32) will truncate the periods to bfloat16 and result in matching outputs.from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model('vit_small_patch16_dinov3.lvd1689m', pretrained=True)
model = model.eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'vit_small_patch16_dinov3.lvd1689m',
pretrained=True,
features_only=True,
)
model = model.eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
for o in output:
# print shape of each feature map in output
# e.g.:
# torch.Size([1, 384, 16, 16])
# torch.Size([1, 384, 16, 16])
# torch.Size([1, 384, 16, 16])
print(o.shape)from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'vit_small_patch16_dinov3.lvd1689m',
pretrained=True,
num_classes=0, # remove classifier nn.Linear
)
model = model.eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
# or equivalently (without needing to set num_classes=0)
output = model.forward_features(transforms(img).unsqueeze(0))
# output is unpooled, a (1, 261, 384) shaped tensor
output = model.forward_head(output, pre_logits=True)
# output is a (1, num_features) shaped tensorSee the associated paper for details on the evaluation protocols
| Model | IN-ReaL | IN-R | Obj.Net | Ox.-H | ADE20k | NYU↓ | DAVIS | NAVI | SPair |
|---|---|---|---|---|---|---|---|---|---|
| Global Tasks | Dense Tasks | ||||||||
| DINOv3 ViT-S/16 | 87.0 | 60.4 | 50.9 | 49.5 | 47.0 | 0.403 | 72.7 | 56.3 | 50.4 |
| DINOv3 ViT-S+/16 | 88.0 | 68.8 | 54.6 | 50.0 | 48.8 | 0.399 | 75.5 | 57.1 | 55.2 |
| DINOv3 ViT-B/16 | 89.3 | 76.7 | 64.1 | 58.5 | 51.8 | 0.373 | 77.2 | 58.8 | 57.2 |
| DINOv3 ViT-L/16 | 90.2 | 88.1 | 74.8 | 63.1 | 54.9 | 0.352 | 79.9 | 62.3 | 61.3 |
| DINOv3 ViT-H+/16 | 90.3 | 90.0 | 78.6 | 64.5 | 54.8 | 0.352 | 79.3 | 63.3 | 56.3 |
| DINOv3 ViT-7B/16 | 90.4 | 91.1 | 91.1 | 72.8 | 55.9 | 0.309 | 79.7 | 64.4 | 58.7 |
| Model | IN-ReaL @256px | IN-ReaL @512px | IN-R @256px | IN-R @512px | Obj.Net @256px | Obj.Net @512px | ADE20k | NYU↓ |
|---|---|---|---|---|---|---|---|---|
| Global Tasks | Dense Tasks | |||||||
| DINOv3 ConvNeXt Tiny | 86.6 | 87.7 | 73.7 | 74.1 | 52.6 | 58.7 | 42.7 | 0.448 |
| DINOv3 ConvNeXt Small | 87.9 | 88.7 | 73.7 | 74.1 | 52.6 | 58.7 | 44.8 | 0.432 |
| DINOv3 ConvNeXt Base | 88.5 | 89.2 | 77.2 | 78.2 | 56.2 | 61.3 | 46.3 | 0.420 |
| DINOv3 ConvNeXt Large | 88.9 | 89.4 | 81.3 | 82.4 | 59.3 | 65.2 | 47.8 | 0.403 |
| Model | m-BEnet | m-brick-kiln | m-eurosat | m-forestnet | m-pv4ger | m-so2sat | mean |
|---|---|---|---|---|---|---|---|
| DINOv3 ViT-L/16 | 73.0 | 96.5 | 94.1 | 60.6 | 96.0 | 57.4 | 79.6 |
| DINOv3 ViT-7B/16 | 74.0 | 97.2 | 94.8 | 62.3 | 96.1 | 62.1 | 81.1 |
| Model | m-cashew | m-chesapeake | m-NeonTree | m-nz-cattle | m-pv4ger-seg | m-SA-crop | mean |
|---|---|---|---|---|---|---|---|
| DINOv3 ViT-L/16 | 94.2 | 75.6 | 61.8 | 83.7 | 95.2 | 36.8 | 74.5 |
| DINOv3 ViT-7B/16 | 94.1 | 76.6 | 62.6 | 83.4 | 95.5 | 37.6 | 75.0 |
@article{simeoni2025dinov3,
title={DINOv3},
author={Sim{'e}oni, Oriane and Vo, Huy V and Seitzer, Maximilian and Baldassarre, Federico and Oquab, Maxime and Jose, Cijo and Khalidov, Vasil and Szafraniec, Marc and Yi, Seungeun and Ramamonjisoa, Micha{"e}l and others},
journal={arXiv preprint arXiv:2508.10104},
year={2025}
}
}@article{dosovitskiy2020vit,
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
journal={ICLR},
year={2021}
}@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}This section documents the adaptation and validation of vit_small_patch16_dinov3.lvd1689m on Huawei Ascend Ascend910B4 NPU.
| Component | Version |
|---|---|
torch | 2.9.0+cpu |
torch-npu | 2.9.0 |
timm | 1.0.27 |
transformers | 4.57.6 |
CANN | 8.5.1 |
1 logical card (Ascend910B4)2026-05-09Since timm pulls weights from HuggingFace Hub by default, it is recommended to set HF_ENDPOINT to a mirror site in China:
export HF_ENDPOINT=https://hf-mirror.comExample code to load the model and move it to NPU:
import torch
import torch_npu
import timm
device = torch.device("npu:0")
torch.npu.set_device(device)
model = timm.create_model(
"vit_small_patch16_dinov3.lvd1689m",
pretrained=True
)
model = model.to(device).eval()
# Get model preprocessing config
data_config = timm.data.resolve_model_data_config(model)
input_size = data_config["input_size"] # (3, 256, 256)The model runs directly on NPU without any additional operator replacement or code modifications. timm's VisionTransformer implementation is fully compatible with torch_npu.
import torch
import torch_npu
import timm
device = torch.device("npu:0")
model = timm.create_model("vit_small_patch16_dinov3.lvd1689m", pretrained=True)
model = model.to(device).eval()
dummy_input = torch.randn(1, 3, 256, 256).to(device)
with torch.no_grad():
output = model(dummy_input)
print(f"Output shape: {output.shape}") # torch.Size([1, 384])
print(f"Output range: [{output.min():.4f}, {output.max():.4f}]")Validation results:
[1, 384] (as expected)[-1.1397, 2.0712]-0.0053Using the same weights and input, compare the output differences between NPU and CPU:
| Metric | Value |
|---|---|
| Max Absolute Diff | 0.002358 |
| Mean Absolute Diff | 0.000584 |
Conclusion: The floating-point difference between NPU inference results and the CPU baseline is within the 1e-2 order of magnitude, meeting the precision requirements for visual feature extraction tasks.
On a single Ascend910B4 card, inference throughput and latency were tested using fp32 precision (excluding preprocessing).
| Batch Size | Throughput (samples/s) | Latency (ms/batch) |
|---|---|---|
| 1 | 30.89 | 32.38 |
| 4 | 233.97 | 17.10 |
| 8 | 463.21 | 17.27 |
| 16 | 927.35 | 17.25 |
Test notes:
3 x 256 x 25610100torch.npu.synchronize() after each batchFrom the data, batch=16 achieves the best throughput (approximately 927 samples/s), with an average inference latency of about 1.1 ms per image.
The complete script used for this validation is provided with the repository:
python validate_npu.pyThe script covers:
export HF_ENDPOINT=https://hf-mirror.com. Otherwise, timm downloading weights from the official HuggingFace site will time out.torch_npu prompts can not create directory: /home/atomgit/ascend/log on the first run, it can be ignored and does not affect inference. To eliminate the message, manually create that directory.256 x 256, which differs from the standard ViT's 224 x 224. Please pay attention to input_size when using it.fp32. For further acceleration, you can try torch.npu.set_amp_dtype(torch.float16) for mixed-precision inference, but additional verification of precision loss is required.| File | Description |
|---|---|
validate_npu.py | NPU adaptation validation script |
README.md | Adaptation documentation (this file) |
validation_output.txt | Raw output log from the validation script |