Skip to content

feat(vlm): support MiniCPM-V 4.7 dense and MoE checkpoints - #3657

Merged
inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/minicpm47-canvas
Dec 2, 2026
Merged

inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/minicpm47-canvas

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Closes #2398.

Adds MiniCPM-V 4.7 dense and MoE loading. Image requests use canvas M-RoPE and retain their positions across preemption; text-only requests keep 1-D positions. The encoder selects the checkpoint’s downsample mode and 4.7 merger activation without changing the 4.6 default. The patch also updates a stale constructor in the logit-trace example so the verification harness builds.

Spark2 verification (NVIDIA GB10, CUDA)

The pre-change binary rejected minicpmv4_7. I tested the 1B-4bit checkpoint at 13caa569 and the 35B-A3B-mxfp4 checkpoint at 810419dd with greedy generation, using the repository soccer photo, an OCR card, and two ordered shape images. Examples of visible answers:

Checkpoint / path Soccer photo OCR Ordered images
1B CLI Describes the men directing play in a stadium LUNAR GATE 72 red, blue
1B server “during a soccer match, likely on the sidelines” LUNAR GATE 72 “First image: A red triangle. … Second image: A blue circle.”
35B CLI Describes the suited man leaning forward and pointing LUNAR GATE 72 Red, Blue
35B server Describes two football managers on the sidelines LUNAR GATE 72 “the colors in order are: red, blue”

Both CLI and server ran with a 64-token cap first. Thinking consumed the entire budget on some prompts, including the photo. The visible results above use a 384-token cap; server requests set chat_template_kwargs.enable_thinking=false.

Teacher-forced comparison

Against two identical mlx-vlm 0.8.2 reference runs on Metal, the Rust 1B CUDA trace had identical prompt IDs and 0/17 top-token disagreements (0/16 where the reference gap was ≥2). Absolute logit differences on the reference choice: median 0.125, maximum 0.875; this is top-token parity, not identical logits. On the same input, replacing canvas with 1-D positions in the reference changed 4/16 decided tokens; switching both merger activations to erf changed 0/16.

The focused regression tests cover upstream canvas fixtures, malformed crop spans, packed 4-bit embeddings with fractional pixels, and per-sequence state. Independent source review checked position handling and found a missing exhaustive-test entry and upstream attribution; both are included here.
test result: ok. 72 passed; 0 failed; 2 ignored; 0 measured; 14199 filtered out; finished in 1.20s

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box modeltype:vlm Vision-language model arch:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) labels Dec 1, 2026
Jaeyeong-CHOI and others added 2 commits December 2, 2026 09:27
…mul guard

Add a dedicated `MiniCPM-V 4.7` section header and upstream URL to `NOTICE` (resolved during rebase onto `main`), add the full upstream GitHub URL and `NOTICE` pointer to `src/vision/minicpmv4_7_rope.rs`, use `checked_mul` for grid-size validation, and update `Used by:` annotations in `src/vision/encoders/minicpmv4_6.rs`.

Validated with `cargo test --profile test-fast --lib -- minicpm` (72 passed), `cargo fmt --check`, and real Metal checks on `mlx-community/MiniCPM-V-4.7-1B-4bit` and `models/minicpm-v-4.6-mxfp4` (both accurately OCR'd `GOT OCR two point zero renders this page`).

Refs lablup#2398, lablup#3657
@inureyes
inureyes force-pushed the feat/minicpm47-canvas branch from ba6c0a3 to 740a027 Compare December 2, 2026 00:41
@inureyes

inureyes commented Dec 2, 2026

Copy link
Copy Markdown
Member

Implementation Hardening Summary

Audited PR #3657 against issue #2398 across MiniCPM-V 4.7 detection, canvas M-RoPE, vision encoder/merger configuration, and preemption state binding.

Findings & Fixes

  • Rebase onto main (HIGH): Rebased onto origin/main (dropping the redundant examples/logit_trace/gemma4.rs fix already merged in fix(examples): update logit_trace Gemma 4 adapter call after #3324 #3659 and resolving the NOTICE conflict cleanly after Support Mistral Multimodal Embed for text and image embeddings #3654).
  • Attribution (MEDIUM): Added a dedicated MiniCPM-V 4.7 section heading and upstream URL in NOTICE, and added the full GitHub URL and NOTICE pointer in src/vision/minicpmv4_7_rope.rs.
  • Hygiene & Safety (LOW): Updated Used by: doc comments on output_token_count_for_spatial_shape and forward in src/vision/encoders/minicpmv4_6.rs to include MiniCPM-V 4.7, and switched height * width to height.checked_mul(width) in src/vision/minicpmv4_7_rope.rs.
  • Security & Performance: Verified all span/bounds checks, MAX_PIXELS/max_slices caps, quantized 4-bit embedding preservation, and per-sequence preemption state cleanup.

Validation

  • cargo test --profile test-fast --lib -- minicpm: 72 passed, 0 failed (2 ignored).
  • cargo fmt --check: passed.
  • Real-model Metal checks (Apple M1 Ultra):
    • mlxcel arch: lists MiniCPM-V 4.7 (minicpmv4_7; SigLIP + canvas M-RoPE + Qwen3.5 dense or MoE text).
    • mlx-community/MiniCPM-V-4.7-1B-4bit (tests/fixtures/got_ocr_page.png): accurately read GOT OCR two point zero renders this page (160 tokens, 55.48 tok/s).
    • models/minicpm-v-4.6-mxfp4 regression check: accurately read GOT OCR two point zero renders this page (18 tokens, 29.81 tok/s).

@inureyes
inureyes merged commit 5526a0c into lablup:main Dec 2, 2026
36 checks passed
inureyes added a commit that referenced this pull request Dec 2, 2026
Parallel `cargo test --features cuda --lib -- --test-threads=4` aborted in most runs with "invalid memory registered when calling <op>::eval_gpu". The cause is a race in MLX's debug-only CUDA allocation tracker: `move_to_unified_memory` and `move_to_device_memory` freed the old pointer before calling `swap_allocation`, so another thread could be handed that address and track it, and the late swap then moved the live entry away and its next `verify_graph` aborted. A new overlay of `mlx/backend/cuda/allocator.cpp` (base 5a48f9cc) retargets the tracker before the free. Release and test-fast builds define NDEBUG and never ran this code, which is why the merge gates did not see it.

MLX-evaluating lib tests now take `mlx_test_guard()` as their first statement, and `tests/mlx_test_guard_coverage.rs` gains a source scan that fails when a test reaches an eval or host readback before taking the guard. Helpers that took their own guard or the device lock were adjusted so nothing deadlocks. CI clippy now also lints examples (about one second of extra time).

Main broke several times while this was open, and the branch carries the fixes the verification needed: the diffusing_interval settings classification, LLaVA-OneVision in FAMILY_ORDER, two clippy lints, the WebUI string fixture and bundle, and guards on tests added by #3654, #3657 and #3678.

Validation: five consecutive 4-thread CUDA lib runs on GB10 passed (14080 passed, 0 failed each) where the base aborted; the guard scan, family_order, fmt, clippy with examples, the scripts/ci contract checks, the WebUI suite and contract check pass. OpenXLA feature compile fails with the same RUSTFLAGS quoting error as on main.

Closes #3660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) area:models Model architectures, weights, loading, metadata modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box modeltype:vlm Vision-language model priority:medium Medium priority status:review Under review type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(vlm): add MiniCPM-V 4.7 (minicpmv4_7) support

2 participants