Instructions to use 662goats/dinov3-mixed-precision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use 662goats/dinov3-mixed-precision with timm:
import timm model = timm.create_model("hf-hub:662goats/dinov3-mixed-precision", pretrained=True) - Notebooks
- Google Colab
- Kaggle
DINOv3 mixed-precision evaluation
Code for measuring how DINOv3 backbones behave under reduced precision (fp32 vs bf16 vs fp16), using a linear probe and k-NN classifier on Imagenette (a 10-class subset of ImageNet).
This repo contains code only. The model weights are hosted in separate Hugging Face repos and are downloaded automatically the first time the script runs:
| Key | Model | Weights repo | Input |
|---|---|---|---|
vit |
DINOv3 ViT-B/16 (85.6M params) | darrenli003/vit_base_patch16_dinov3.lvd1689m | 256ร256 |
convnext |
DINOv3 ConvNeXt-B (87.6M params) | darrenli003/convnext_base.dinov3_lvd1689m | 224ร224 |
Both are timm versions of Meta's DINOv3 weights, distilled from DINOv3 ViT-7B on LVD-1689M, and are
covered by the DINOv3 license.
Setup
git clone https://huggingface.co/darrenli003/dinov3-mixed-precision
cd dinov3-mixed-precision
python -m venv .venv
Activate the environment:
.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux / macOS
Install dependencies. requirements.txt installs the CPU build of PyTorch:
pip install -r requirements.txt
On an NVIDIA GPU machine, install the CUDA build of PyTorch first (see pytorch.org), for example:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
pip install timm scikit-learn numpy pillow safetensors
Running
python eval_imagenette.py --limit 200 # quick test on 200 images per split
python eval_imagenette.py # full run: both models, all precisions
python eval_imagenette.py --models vit # one model only
python eval_imagenette.py --precisions fp32 bf16 # choose precisions
python eval_imagenette.py --train-per-precision # also train a classifier on low-precision features
python eval_imagenette.py --help # all options
By default it tests fp32 and bf16 on CPU, and fp32, bf16 and fp16 on a CUDA GPU.
On first run the script downloads:
- Model weights (
350 MB per model) to the Hugging Face cache (`/.cache/huggingface`). Later runs reuse the cached copy and work offline. - Imagenette (320px version, ~340 MB) to
data/.
If the weight repos are already cloned into this folder (for example
./vit_base_patch16_dinov3.lvd1689m/model.safetensors), the script uses them and skips the
download. Clones need git lfs so the actual weight files are present. Other options:
--local DIR: look for the clones inDIRinstead, and stop with an error rather than download if they are missing.--hub: always load from the Hub, even if clones are present.
What it measures
For each model, the frozen backbone turns every image into one feature vector (768 numbers for the ViT, 1024 for ConvNeXt). Then:
- Linear probe: logistic regression trained on fp32 features from the training split.
- k-NN: each validation image is labelled by majority vote of its 20 most similar training images.
- Validation features are extracted at each precision using
torch.autocastand scored with the fp32-trained classifiers. This tests whether a lower precision can be dropped into an existing fp32 pipeline. - Feature drift: cosine similarity between each image's fp32 and low-precision features, and how often the classifier's prediction stays the same.
Outputs
results/imagenette_<size>_<limit>_<device>.jsonand.csv: the summary table.features/: cached feature vectors, so re-running only computes what is missing. Not committed.
Notes
- Speed numbers are only meaningful on hardware with native low-precision support (most NVIDIA GPUs from the RTX 30-series / A100 onwards for bf16; T4 and newer for fp16). On CPUs without bf16 instructions, bf16 is emulated and runs several times slower than fp32, although the accuracy and drift results are still valid.
- The
timmViT computes RoPE periods in fp32, whereas Meta's original stores them in bf16, so outputs differ very slightly from Meta's reference implementation.
- Downloads last month
- -