[OpenVINO] Support MiniCPM-V-4.6#1810
Open
openvino-agent wants to merge 1 commit into
Open
Conversation
Add OpenVINO export and inference support for MiniCPM-V-4.6 VLM with hybrid linear+full attention (Qwen3_5TextModel) and NaViT-packed vision. Key components: - Export: 4 submodels (vision_embeddings, merger, text_embeddings, language) - Vision: per-image NaViT splitting for single-image-traced OV model - Language: RecurrentAttentionCell for GatedDeltaNet linear attention with correct state extraction from cache lists (not stale layer attributes) - Preprocessor: explicit image_processor save when processor omits it Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 tasks
|
@rkazants @popovaan WWB gives 0.92 accuracy hf vs optimum. from transformers import AutoProcessor, AutoModelForImageTextToText
from optimum.intel.openvino import OVModelForVisualCausalLM
from pathlib import Path
prompt = "List all the states marked in the purple color in the map."
image_url = "https://textvision-data-quality.s3.us-west-1.amazonaws.com/infographics_images/33051.jpeg"
model_id = "openbmb/MiniCPM-V-4.6"
processor = AutoProcessor.from_pretrained(model_id, padding_side="left")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": image_url},
{"type": "text", "text": prompt},
],
},
]
inputs = processor.apply_chat_template(
messages,
tokenize=True,
return_dict=True,
return_tensors="pt",
add_generation_prompt=True,
)
def run_optimum(inputs):
model_path = Path("./MiniCPM-V-4.6")
ov_config = {"INFERENCE_PRECISION_HINT": "f32", "KV_CACHE_PRECISION": "f32", "DYNAMIC_QUANTIZATION_GROUP_SIZE": 0}
model = OVModelForVisualCausalLM.from_pretrained(model_path, ov_config=ov_config)
output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
return processor.decode(output[0, inputs.input_ids.shape[1] :], skip_special_tokens=True)
def run_transformers(inputs):
model = AutoModelForImageTextToText.from_pretrained(model_id)
output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
return processor.decode(output[0, inputs.input_ids.shape[1] :], skip_special_tokens=True)
result_transformers = run_transformers(inputs)
result_optimum = run_optimum(inputs)
print(f"Results transformers:\n{result_transformers}\n")
print(f"Results optimum:\n{result_optimum}\n")
assert result_optimum == result_transformers
# Results transformers:
# Based on the map titled "WE CAN DO BETTER," the states marked in purple are:
# - TX (Texas)
# - LA (Louisiana) — note: LA is shown in blue, but the box says "STATE SIZE DISTORTED" and LA is in purple? Wait, let’s check the map carefully.
# Actually, looking at the map, the states colored **purple** are:
# - Texas (TX)
# - Louisiana (LA) — but wait, the
# Results optimum:
# Looking at the map under the "WE CAN DO BETTER" section and the state color-coded in purple, the states marked in purple are:
# - TX (Texas)
# - LA (Louisiana) — wait, no, looking again, LA is blue (top states), but let’s check the purple ones.
# Actually, reviewing the map, the states marked in **purple** (which according to the legend likely represent bottom states or lower science adoption) include:
# - TX (
# Traceback (most recent call last):
# File "/home/asuvorov/projects/openvino.genai/reproducer.py", line 49, in <module>
# assert result_optimum == result_transformers
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# AssertionError |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Installation instructions
Cmd-line for export:
optimum-cli export openvino -m openbmb/MiniCPM-V-4.6 MiniCPM-V-4.6The script for inference:
Fixes # (issue)
Before submitting