Skip to content

[EXPERIMENT][WIP][OpenVINO] Add support for DINOv3 ConvNeXt - #1865

Draft
mlukasze wants to merge 1 commit into
huggingface:mainfrom
mlukasze:enable/facebook-dinov3-convnext-small-pretrain-lvd1689m
Draft

[EXPERIMENT][WIP][OpenVINO] Add support for DINOv3 ConvNeXt#1865
mlukasze wants to merge 1 commit into
huggingface:mainfrom
mlukasze:enable/facebook-dinov3-convnext-small-pretrain-lvd1689m

Conversation

@mlukasze

Copy link
Copy Markdown
Contributor

⚠️ AUTOMATICALLY GENERATED BY OMEGA AGENT — REQUIRES HUMAN REVIEW ⚠️
This PR was created by an AI agent as part of automated model enablement.
A human maintainer must review and approve it before it can be considered for merge.
Do NOT merge without human review and sign-off.

What does this PR do?

Adds OpenVINO export and inference support for DINOv3 ConvNeXt (dinov3_convnext, e.g. facebook/dinov3-convnext-small-pretrain-lvd1689m).

DINOv3ConvNextModel (native transformers support since ~4.56) is architecturally a standard ConvNeXt CNN backbone (depthwise conv -> channels-last LayerNorm -> pointwise GELU MLP -> layer-scale -> droppath, 4 stages, global-average-pool + final LayerNorm) with a pixel_values -> last_hidden_state/pooler_output signature -- fully compatible with the existing ViTOpenVINOConfig contract already used by plain convnext. This PR follows the exact same one-line pass-through pattern as ConvNextOpenVINOConfig, registered under the feature-extraction task only (this model has no image-classification/masked-im head/variant, unlike plain convnext).

Validation (real full-size gated model, real COCO image, not synthetic data): PyTorch FP32 vs. OpenVINO IR (OVModelForCustomTasks) cosine similarity = 0.99999994 (last_hidden_state, 50x768) / 1.0 (pooled token); max abs diff 3.53e-05 / 7.27e-06. No missing/unsupported OpenVINO operators (Convolution, GroupConvolution, MVN, MatMul, Add, Multiply, Transpose, Gelu, ReduceMean, Concat, Reshape -- all standard/long-supported).

Test coverage: extended OVModelForCustomTasksIntegrationTest with test_compare_output_vision_feature_extraction, parametrized on dinov3_convnext. OVModelForFeatureExtraction is hard-coded for text inputs (input_ids/attention_mask/token_type_ids) so this test uses the generic OVModelForCustomTasks wrapper instead, with the required explicit task="feature-extraction" kwarg (this class has no default export_feature, unlike task-specific OVModelForXXX classes -- omitting it crashes task inference with TypeError: unsupported operand type(s) for +: 'NoneType' and 'str', a real bug caught and fixed while validating this new test).

Known limitation -- tiny CI fixture not yet uploaded: tests/openvino/utils_tests.py registers optimum-intel-internal-testing/tiny-random-dinov3_convnext per convention, but this repo does not exist on the Hub yet, and the automation account used to prepare this PR only has read-scoped Hub access (confirmed via a 403 on repo creation, including under its own personal namespace) -- it cannot self-publish this fixture. A helper script is included at the bottom of this description for a maintainer with optimum-intel-internal-testing write access to run once (create_tiny_dinov3_convnext.py --push-to-hub); until then, CI will fail on this one parametrized case with a clear "not a valid model identifier" error (not a code defect). The test logic itself has been independently verified to genuinely pass end-to-end (1 passed in a real local pytest run) by temporarily pointing the fixture entry at the real gated model with an authorized token, then reverting -- see the attached test_run.log.

Tiny fixture creation script (for a maintainer with org write access)
python create_tiny_dinov3_convnext.py --push-to-hub
# pushes to optimum-intel-internal-testing/tiny-random-dinov3_convnext
# (script builds a depths=[1,1,1,1], hidden_sizes=[8,16,32,64] tiny random DINOv3ConvNextModel)

Installation instructions

pip install git+https://github.com/mlukasze/optimum-intel.git@enable/facebook-dinov3-convnext-small-pretrain-lvd1689m
pip install --pre -U openvino openvino-tokenizers nncf --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly

Exporting cmd-line

export HF_TOKEN=<your_token_with_accepted_license>
optimum-cli export openvino --model facebook/dinov3-convnext-small-pretrain-lvd1689m --task feature-extraction --trust-remote-code ov_model/

Inference script

import numpy as np
from transformers import AutoImageProcessor
from optimum.intel import OVModelForCustomTasks
from PIL import Image
import requests

processor = AutoImageProcessor.from_pretrained("facebook/dinov3-convnext-small-pretrain-lvd1689m")
ov_model = OVModelForCustomTasks.from_pretrained("ov_model/", device="CPU")

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
inputs = processor(images=image, return_tensors="pt")
outputs = ov_model(**inputs)

last_hidden_state = outputs.last_hidden_state  # (1, num_patches+1, hidden_size)
pooled_output = last_hidden_state[:, 0, :]      # pooled/CLS-equivalent embedding

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

- Register dinov3_convnext model_type in optimum/exporters/openvino/model_configs.py
  as a one-line pass-through of ViTOpenVINOConfig (same pattern as existing convnext).
- Add tiny model test entry to tests/openvino/utils_tests.py.
- Extend OVModelForCustomTasksIntegrationTest in tests/openvino/test_modeling.py with
  a vision feature-extraction comparison test (pixel_values -> last_hidden_state),
  since OVModelForFeatureExtraction is hard-coded for text inputs.
- Document DINOv3 (ConvNeXt variant) in docs/source/openvino/models.mdx.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants