Repository navigation
Add OpenBMB MiniCPM-V 4.6 support - #464
Conversation
Performance Comparison
|
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
Pull request overview
Adds first-class support for OpenBMB MiniCPM‑V‑4.6 to mobius’ multimodal pipeline by introducing a native model implementation, a dedicated 3-model Vision-Language task layout (decoder/vision_encoder/embedding), registry/config wiring, ORT GenAI export integration, and new integration + golden coverage.
Changes:
- Introduce
MiniCPMV46ForConditionalGeneration(packed NaViT/SigLIP2 vision + Qwen3.5 hybrid decoder) plus unit tests and weight-routing. - Add
MiniCPMVLTaskand register the newminicpmv4_6model_type across configs, registry, and ORT GenAI export behavior. - Add new L4/L5 test case + golden artifacts, plus ORT GenAI package-load and real-weight vision parity integration tests.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ort_genai_test.py | Adds ORT GenAI integration test to verify MiniCPM-V-4.6 package loads. |
| tests/integration_test.py | Adds real-weight SigLIP2/merger vision parity test for MiniCPM‑V‑4.6. |
| tests/_test_configs.py | Adds tiny MiniCPM‑V‑4.6 VL config for graph-build coverage. |
| testdata/golden/vision-language/minicpm-v-4_6.json | Adds L4 golden logits/tokens snapshot for MiniCPM‑V‑4.6. |
| testdata/golden/vision-language/minicpm-v-4_6_generation.json | Adds L5 deterministic generation golden for MiniCPM‑V‑4.6. |
| testdata/cases/vision-language/minicpm-v-4_6.yaml | Adds L4/L5 golden case definition for MiniCPM‑V‑4.6. |
| src/mobius/tasks/_vision_language_3model.py | Adds MiniCPMVLTask and packed target_sizes vision I/O contract. |
| src/mobius/tasks/init.py | Exposes MiniCPMVLTask and registers it in task registry. |
| src/mobius/models/minicpmv4_6.py | Implements MiniCPM‑V‑4.6 model (vision tower + mergers + hybrid decoder + embedding fusion). |
| src/mobius/models/minicpmv4_6_test.py | Adds synthetic vision parity + embedding placeholder-mixing tests. |
| src/mobius/models/init.py | Exports MiniCPMV46ForConditionalGeneration. |
| src/mobius/integrations/ort_genai/auto_export.py | Adds MiniCPM-specific ORT GenAI handling (no image_processor.json; preserve HF preprocessor config; adjust vision input mapping). |
| src/mobius/_registry.py | Registers minicpmv4_6 model_type and default model id. |
| src/mobius/_configs/per_model/_minicpmv4_6_vision.py | Adds per-model vision-config extraction hook for the composite MiniCPM config. |
| src/mobius/_configs/per_model/init.py | Imports the new MiniCPM vision extractor to register hooks. |
| src/mobius/_configs/_sub_configs.py | Extends VisionConfig with MiniCPM merger parameters. |
| src/mobius/_configs/_base.py | Adds video_token_id and downsample_mode to the shared architecture config. |
| README.md | Updates supported Multimodal model list to include MiniCPM‑V 4.6. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Looks like we need compress and argmax in ORT cuda |
justinchuby
left a comment
There was a problem hiding this comment.
Correctness review: one batched multimodal finding.
bb3e88c to
7552308
Compare
Implement the packed variable-resolution SigLIP2 vision tower, ragged crop batching, 16x/4x mergers, Qwen3.5 hybrid decoder integration, image/video token mixing, config extraction, standardized three-model export, and ORT GenAI metadata. Add synthetic and real-weight parity tests plus committed image prefill and deterministic generation goldens. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Keep packed patch coordinate mapping on CUDA by replacing ArgMax with a segment-count reduction. Cast through float for ReduceMean and Compress so BF16 vision graphs load and run while restoring the model dtype at each boundary. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Emit float compatibility casts around ReduceMean and Compress only for BF16, where ORT requires them. Keep native FP16 kernels on the fast path and remove four unnecessary casts without changing outputs. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Fall back to the architecture's 2x2 merger kernels when Hugging Face explicitly supplies null values, and add a regression test for both window and final merger fields. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Flatten the media placeholder mask before cumulative indexing so packed image and video features are consumed globally in HF masked_scatter order across batch rows. Add two-row parity and empty decode execution coverage. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
Apply the repository formatter to the batch-global image and video feature routing coverage. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
7552308 to
c74aae3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/mobius/models/minicpmv4_6.py:183
_vision_attention_biasexpands the key padding bias to[batch, 1, seq, seq], butop.Attentiononly requires an additive bias broadcastable to[batch, num_heads, q_seq, kv_seq]. Keeping the mask as[batch, 1, 1, seq]avoids materializing an O(seq^2) tensor and can significantly reduce memory use for larger packed grids.
key_bias = op.Where(
op.Unsqueeze(valid, [1, 2]),
op.CastLike(0.0, hidden_states),
op.CastLike(-10_000.0, hidden_states),
)
sequence_length = op.Mul(max_height, max_width)
return op.Expand(
key_bias,
op.Concat(
op.Shape(target_sizes, start=0, end=1),
op.Constant(value_ints=[1]),
sequence_length,
sequence_length,
axis=0,
),
)
src/mobius/tasks/_vision_language_3model.py:361
pixel_valuesuses a symbolicpacked_batchdimension here, but the MiniCPM vision implementation reshapes patches to[1, -1, hidden](seesrc/mobius/models/minicpmv4_6.py:255-258), effectively assuming batch==1. Leaving this dimension symbolic makes it easy to passpacked_batch>1and get silently incorrect results; it should be fixed to1like other single-image vision encoders in this file.
packed_batch = ir.SymbolicDim("packed_batch")
packed_width = ir.SymbolicDim("packed_width")
num_visual_units = ir.SymbolicDim("num_visual_units")
Summary
minicpmv4_6support foropenbmb/MiniCPM-V-4.6/ Transformers 5.7+Updated from main
Rebased the linear six-commit PR series onto current
origin/mainatc3b7cf1, incorporating Mage-VL image/video support and Parakeet CTC in addition to Moonshine, Nemotron Parse 2.0, LFM2.5, fused Swish, Gemma 3n, and Muse Glimmer. Conflict resolution preserves all upstream registrations, configs, tasks, docs, and tests alongside MiniCPM.Validation after latest rebase
lintrunner -a: clean1 passed, 24 deselected6 passed, 1392 deselected1 passed, 126 deselected0.999961913, embedding cosine0.999961913, last-token logits cosine0.999991179, identical argmax760, no NaNsFused and optimized graphs
Weighted FP16 CUDA-targeted graph audit after the latest rebase:
Initializer folding reduces unweighted vision transposes from 175 to five required raster/window permutations. FP16 avoids BF16-only compatibility casts.
Actual CUDA profiling confirms the fused kernels execute on CUDA: vision 542 CUDA nodes / 0 CPU compute, embedding 15 CUDA / 0 CPU, decoder 991 CUDA nodes with all GQA/LinearAttention/CausalConv/skip-RMSNorm kernels on CUDA. Outputs are finite and image-conditioned argmax remains
760.DRYness
Reuses
Qwen35TextModel, shared hybrid-cache task machinery,VisionEncoderLayer,VisionAttention,LayerNorm,Linear, activation helpers,VisionLanguageTask,build_decoder_from_embeds, andbuild_embedding_from_features. Only MiniCPM-specific NaViT/ragged-grid/merger logic remains local. The specialized dual image/video embedding graph is 15 nodes.Runtime limitations
target_sizes.onnxruntime-genai-cuda 0.15.2crashes loading this hybrid package on Windows, while raw ORT CUDA executes all three graphs and exact L5 generation successfully.CausalConvWithStatekernel.