Skip to content

mtmd : add MiniCPM-OCR 1.0 - #98

Open
notforu777 wants to merge 1 commit into
devfrom
feat/minicpm-ocr
Open

notforu777 wants to merge 1 commit into
devfrom
feat/minicpm-ocr

Conversation

@notforu777

Copy link
Copy Markdown

Adds OpenBMB's MiniCPM-OCR 1.0 (1.3B, Apache-2.0: text, tables as HTML, formulas as LaTeX) so Atomic Chat can
run it. Upstream support is ggml-org#30979 (merge a08ab75, 2026-10-22).

What is in it

MiniCPM-OCR 1.0 is the MiniCPM-V 4.6 stack: text model qwen35, mmproj with the 4.6 merger in 4x mode, new
projector type minicpm_ocr_1_0. Upstream registers the type on top of preprocessing the fork's 4.6 code does not
have yet. The new type gets that preprocessing; MiniCPM-V 4.6 itself does not change:

  • Resize: Pillow bicubic for the overview and the slices, no padding (the fork's 4.6 default is bilinear
    overview + PyTorch bicubic slices with ceil padding). New RESIZE_ALGO_BICUBIC_PILLOW_EXACT = the fork's Pillow
    resampler with Pillow's fixed-point weight rounding (+/-0.5, truncate), as upstream's. Existing
    BICUBIC_PILLOW users are untouched.
  • <image_id>N</image_id> before <image> (use_image_id).
  • Slice snapping with Python's round() (ties to even, double), via a new virtual
    align_round_div() on the llava-uhd preprocessor; the default keeps the old float std::round.
  • M-RoPE grid: clip_n_output_tokens_x/y give the 2D grid (n / (patch * n_merge)). The 4.6 path returns
    (all tokens, 1), one row.
  • Position buckets in vectors instead of int[1024] on the stack.
  • gguf-py: VisionProjectorType.MINICPM_OCR_1_0. The converter is not ported: the app only loads GGUFs.

Tested (A10, CUDA, BF16 GGUF + mmproj F16 from AtomicChat/MiniCPM-OCR-1.0-GGUF)

40 OmniDocBench pages (4 per source, seed 0), llama-mtmd-cli --jinja --temp 0, prompt Text Recognition:. This
branch against upstream a7af149:

  • 37/40 pages identical on CUDA. The 3 others diverge at a near-tied token (a table vs text opening, one
    character in a formula) and then drift. Two of them are dense newspaper pages.
  • Both newspaper pages give identical text on the CPU (-ngl 0 --no-mmproj-offload): the same 21 chunks, the
    same tokens. So the inputs match, and the CUDA difference comes from the fork's kernels, not from the port.
  • Accuracy against the OmniDocBench annotation is the same (rough CER 49.2% vs upstream 49.4%; that number is only
    for comparing two builds).
  • llama-server with an image request works.

Thinking (affects the app)

The model writes its transcription after the thinking block. With --jinja and default reasoning, llama-server
sets enable_thinking, the original template opens <think>, and the whole answer arrives in
reasoning_content with empty content
. This happens on upstream too. Checked on this branch:

GGUF flags content reasoning_content
vendor openbmb/MiniCPM-OCR-1.0-gguf (template with thinking hard-off) default 409 chars 0
original template default 0 409 chars
original template --reasoning off 409 chars 0
original template --chat-template-kwargs '{"enable_thinking": false}' 409 chars 0

For the app: either ship GGUFs whose template has thinking off, or start this model with --reasoning off.

Not in this PR

  • MiniCPM-V 4.7 (minicpmv4_7) is still not in the fork.
  • Unrelated, seen while testing: on the CPU the fork encodes vision slices about 2.5x slower than upstream (1.85 s vs
    0.74 s per 448px slice).

To ship in the app

Review, merge, cut a fork release, bump the app. Then handle thinking-off for this model (template or flag).

Assisted-by: Claude

Port of upstream ggml-org#30979 (a08ab75) to the fork. MiniCPM-OCR 1.0 is the MiniCPM-V 4.6 stack
with projector type minicpm_ocr_1_0; the fork's 4.6 code lacks parts of upstream's preprocessing that this
model's output depends on, so the new type gets them without changing 4.6:

- Pillow bicubic for the overview and the slices (RESIZE_ALGO_BICUBIC_PILLOW_EXACT: the fork's Pillow
  resampler with Pillow's fixed-point weight rounding), no padding;
- <image_id>N</image_id> before <image>;
- slice sizes snapped with Python's round() (ties to even);
- a 2D image grid (nx, ny) for M-RoPE positions instead of one row;
- position buckets in vectors instead of a 1024-entry stack array.

Pages read with the BF16 GGUF match upstream a7af149 token for token on CPU; on CUDA 37 of 40 OmniDocBench
pages are identical (the rest diverge at near-tied tokens, from the fork's CUDA kernels).

Assisted-by: Claude
@github-actions github-actions Bot added documentation Improvements or additions to documentation conversion mtmd labels Oct 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conversion documentation Improvements or additions to documentation mtmd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant