MiniCPM-V 4.7 (1B) - MNN
This is an unofficial MNN conversion of openbmb/MiniCPM-V-4.7-1B, a 1B vision-language model, for CPU and edge inference with the MNN runtime.
MNN's exporter (llmexport) did not support the minicpmv4_7 architecture, so the conversion used a patched copy of it. The vision encoder was re-implemented as an export-friendly graph that accepts a different image resolution per request.
This repository is not affiliated with OpenBMB or the MNN team.
Quantization
| Part | Setting |
|---|---|
| Language model | 4-bit, block size 128 |
lm_head |
8-bit |
| Embeddings | 8-bit |
| Vision encoder | 8-bit, block size 128 |
Files
The repository holds the files llmexport writes for an MNN model: the language model (llm.mnn and its weight file), the vision encoder (visual.mnn and its weight file), the tokenizer, and the runtime configs (config.json, llm_config.json).
Usage
Install the MNN Python package, download the repository, and point llm.create at config.json:
pip install -U MNN huggingface_hub
from huggingface_hub import snapshot_download
import MNN.llm as llm
path = snapshot_download("bakhil-aissa/MiniCPM-V-4.7-1B-MNN")
model = llm.create(f"{path}/config.json")
model.load()
# text only
print(model.response("What is the capital of France?"))
# image: <hw>height,width</hw> sets this image's size (see below)
print(model.response("<img><hw>448,448</hw>/path/to/image.png</img>Describe this image."))
Choosing the image size
Each image is resized to the height and width given in <hw>H,W</hw> (height first). Both values must be multiples of 56, and the number of visual tokens is (H / 56) * (W / 56). For example, 448 x 448 gives 64 tokens and 672 x 448 gives 96.
Always include <hw> for every image. The runtime may reuse the previous size when it is missing.
The vision layers before the early token compression attend over every 14-pixel patch, so cost grows quickly with image size. A budget of about 144 tokens is a reasonable CPU default. This helper picks a size that keeps the aspect ratio:
import math
def pick_size(img_w, img_h, max_tokens=144, unit=56, min_units=4):
s = min(1.0, math.sqrt(max_tokens * unit * unit / (img_w * img_h)))
H = max(min_units, round(img_h * s / unit)) * unit
W = max(min_units, round(img_w * s / unit)) * unit
while (H // unit) * (W // unit) > max_tokens:
if H >= W: H -= unit
else: W -= unit
return H, W
H, W = pick_size(1080, 2400)
prompt = f"<img><hw>{H},{W}</hw>/path/to/screenshot.png</img>Describe this image."
What was changed for the conversion
llmexportwas patched to loadMiniCPMV4_7ForConditionalGenerationand to reuse its Qwen3.5 text mapping for the language model.- The vision tower and merger were wrapped in a graph whose sizes are read from the input tensor, so height and width are dynamic. The vision input is named
image, so MNN's runtime uses its generic single-image path. - The conversion notebook is included as
minicpm_v47_to_mnn_dynamic.ipynb.
Validation and limitations
- Checked: the vision graph's math was compared with the Hugging Face implementation on random input (cosine similarity 1.000001 for the fixed 448 x 448 version of the graph).
- Not yet benchmarked: accuracy after quantization, output quality at sizes other than 448 x 448, and speed on specific devices. Treat this as an experimental conversion.
- Image normalization uses mean and std of 0.5, which is the usual SigLIP default. It has not been compared with the official MiniCPM-V processor.
- Only the 16x visual-token compression mode is exported.
- The original model also slices large images; this conversion encodes one image at one size, with no slicing.
- The runtime gives image tokens ordinary sequential positions, not the multimodal position layout the original implementation uses. This may reduce how well the model locates things in an image.
License and credits
The base model, openbmb/MiniCPM-V-4.7-1B, is released under Apache-2.0, and this conversion keeps that license. Please check the base model page for the current terms. Credit for the model goes to OpenBMB, and for the runtime to the MNN team at Alibaba.
- Downloads last month
- 46
Model tree for bakhil-aissa/MiniCPM-V-4.7-1B-mnn
Base model
openbmb/MiniCPM-V-4.7-1B