--- library_name: transformers tags: - vision - image-feature-extraction - dinov3 - vit license: other --- # EUPE ViT-B/16 This repository contains the EUPE ViT-B/16 backbone converted to the Hugging Face `transformers` DINOv3 ViT format. - Hugging Face repo: `kittn/eupe_vitb16` - Original EUPE checkpoint: [`facebook/EUPE-ViT-B`](https://huggingface.co/facebook/EUPE-ViT-B) - Architecture: ViT-B/16 - Hidden size: `768` - Layers: `12` - Attention heads: `12` - Register tokens: `4` - Patch size: `16` This conversion is meant for direct use with `AutoModel` / `DINOv3ViTModel`. It uses the stock Hugging Face DINOv3 implementation, so small numerical differences versus the original EUPE implementation are expected. ## RoPE note The original EUPE checkpoints use persisted RoPE values derived from bf16-rounded periods, while the stock Hugging Face DINOv3 implementation reconstructs RoPE analytically from `rope_theta`. Because of that, outputs are very close but not exactly identical to the original EUPE implementation. ## Minimal-loss inference If you want to minimize the discrepancy versus the original EUPE inference path, prefer running the Hugging Face model on CUDA under `torch.autocast("cuda", dtype=torch.bfloat16)` rather than hard-casting the full model to `bfloat16`. ## Usage ```python import torch from PIL import Image from transformers import AutoImageProcessor, AutoModel repo_id = "kittn/eupe_vitb16" image = Image.open("image.jpg").convert("RGB") processor = AutoImageProcessor.from_pretrained(repo_id) model = AutoModel.from_pretrained(repo_id).eval() inputs = processor(images=image, return_tensors="pt") with torch.inference_mode(): outputs = model(**inputs) last_hidden_state = outputs.last_hidden_state pooler_output = outputs.pooler_output print("last_hidden_state:", last_hidden_state.shape) print("pooler_output:", pooler_output.shape) ``` On CUDA, a low-loss inference pattern is: ```python with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): outputs = model(**inputs) ``` `last_hidden_state` contains: - token `0`: CLS token - tokens `1:5`: 4 register tokens - remaining tokens: patch tokens ## Optional masking For masked inference, pass `bool_masked_pos` with shape `batch_size x num_patches`. For a `224 x 224` image with patch size `16`, `num_patches = 14 x 14 = 196`. ```python import torch from PIL import Image from transformers import AutoImageProcessor, AutoModel repo_id = "kittn/eupe_vitb16" image = Image.open("image.jpg").convert("RGB") processor = AutoImageProcessor.from_pretrained(repo_id) model = AutoModel.from_pretrained(repo_id).eval() inputs = processor(images=image, return_tensors="pt") num_patches = (inputs["pixel_values"].shape[-2] // 16) * (inputs["pixel_values"].shape[-1] // 16) bool_masked_pos = torch.zeros(1, num_patches, dtype=torch.bool) bool_masked_pos[:, 0] = True with torch.inference_mode(): outputs = model(pixel_values=inputs["pixel_values"], bool_masked_pos=bool_masked_pos) print(outputs.last_hidden_state.shape) ```