Skip to content

Add OpenBMB MiniCPM-V 4.6 support - #464

Merged
justinchuby merged 6 commits into
mainfrom
justinchuby-add-minicpm-v-4-6
Aug 14, 2026
Merged

justinchuby merged 6 commits into
mainfrom
justinchuby-add-minicpm-v-4-6

Conversation

@justinchuby

@justinchuby justinchuby commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add native minicpmv4_6 support for openbmb/MiniCPM-V-4.6 / Transformers 5.7+
  • implement packed variable-resolution SigLIP2 vision, ragged overview/slice batching, inserted window-attention merger, final MLP merger, and 16x/4x modes
  • reuse the Qwen3.5 hybrid decoder and standard three-model VLM helpers; support image and video placeholder routing
  • add config/registry/CLI/runtime integration, weight mapping, synthetic and real-weight parity, and genuine image-conditioned L4/L5 goldens

Updated from main

Rebased the linear six-commit PR series onto current origin/main at c3b7cf1, 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: clean
  • config extractor: 1 passed, 24 deselected
  • MiniCPM unit/L1: 6 passed, 1392 deselected
  • CUDA real-weight nonzero-image parity: 1 passed, 126 deselected
  • prior CPU real parity and CUDA L4/L5 image generation remain unchanged by the registration-only main conflicts
  • FP16 CUDA stages: vision cosine 0.999961913, embedding cosine 0.999961913, last-token logits cosine 0.999991179, identical argmax 760, no NaNs

Fused and optimized graphs

Weighted FP16 CUDA-targeted graph audit after the latest rebase:

Graph Nodes Identity Unused inputs Fused/layout evidence
decoder 1,107 0 0 6 GQA, 18 LinearAttention, 18 CausalConvWithState, 48 SkipSimplifiedLayerNormalization, 42 Swish, 36 transpose
vision_encoder 619 0 0 28 Attention, 54 SkipLayerNormalization, 5 transpose, 2 cast
embedding 15 0 0 0 transpose, 1 cast, 2 reshape

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, and build_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

  • ort-extensions has no native MiniCPM adaptive slicing + horizontal NaViT packing transform; callers supply Hugging Face processor tensors, including native INT32 target_sizes.
  • onnxruntime-genai-cuda 0.15.2 crashes loading this hybrid package on Windows, while raw ORT CUDA executes all three graphs and exact L5 generation successfully.
  • FP16 is the validated end-to-end reduced-precision CUDA path; BF16 decoder awaits an ORT CausalConvWithState kernel.
  • Foundry Local and Olive are not installed in this environment.

@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 8, 2026 00:48
@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing c3b7cf1 → c74aae3

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing c3b7cf1 → c74aae3

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MiniCPMVLTask and register the new minicpmv4_6 model_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.

@justinchuby

Copy link
Copy Markdown
Member Author

Looks like we need compress and argmax in ORT cuda

@justinchuby justinchuby left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness review: one batched multimodal finding.

Comment thread src/mobius/models/minicpmv4_6.py Resolved
@justinchuby
justinchuby force-pushed the justinchuby-add-minicpm-v-4-6 branch 2 times, most recently from bb3e88c to 7552308 Compare August 13, 2026 22:39
justinchuby and others added 6 commits August 13, 2026 16:58
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]>
@justinchuby
justinchuby force-pushed the justinchuby-add-minicpm-v-4-6 branch from 7552308 to c74aae3 Compare August 14, 2026 00:01
@justinchuby
justinchuby requested a lite review from Copilot August 14, 2026 00:09
@justinchuby
justinchuby merged commit c2a3a93 into main Aug 14, 2026
20 of 23 checks passed
@justinchuby
justinchuby deleted the justinchuby-add-minicpm-v-4-6 branch August 14, 2026 00:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_bias expands the key padding bias to [batch, 1, seq, seq], but op.Attention only 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_values uses a symbolic packed_batch dimension here, but the MiniCPM vision implementation reshapes patches to [1, -1, hidden] (see src/mobius/models/minicpmv4_6.py:255-258), effectively assuming batch==1. Leaving this dimension symbolic makes it easy to pass packed_batch>1 and get silently incorrect results; it should be fixed to 1 like 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")

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.

3 participants