Document model provenance, conversion and validation
Browse files- README.md +103 -17
- conversion.json +74 -0
README.md
CHANGED
|
@@ -4,41 +4,127 @@ pipeline_tag: image-text-to-text
|
|
| 4 |
base_model: openbmb/MiniCPM-V-4.7-1B
|
| 5 |
tags:
|
| 6 |
- MNN
|
| 7 |
-
- minicpm-v
|
| 8 |
- quantized
|
| 9 |
- vision-language
|
| 10 |
---
|
| 11 |
|
| 12 |
# MiniCPM-V-4.7-1B-MNN
|
| 13 |
|
| 14 |
-
MNN conversion of [
|
| 15 |
-
The source model and its weights are provided by OpenBMB under Apache-2.0.
|
| 16 |
|
| 17 |
-
|
| 18 |
-
Vision encoder: HQQ 8-bit, block size 128 (per-channel where the channel count is not divisible by 128).
|
| 19 |
-
The exported model uses default 16x visual compression and supports text, single-image and multi-image prompts, including image slicing. Video input has not been validated.
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
~~~
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
~~~bash
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
~~~
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
## Validation
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
| 4 |
base_model: openbmb/MiniCPM-V-4.7-1B
|
| 5 |
tags:
|
| 6 |
- MNN
|
|
|
|
| 7 |
- quantized
|
| 8 |
- vision-language
|
| 9 |
---
|
| 10 |
|
| 11 |
# MiniCPM-V-4.7-1B-MNN
|
| 12 |
|
| 13 |
+
MNN-format conversion of [openbmb/MiniCPM-V-4.7-1B](https://huggingface.co/openbmb/MiniCPM-V-4.7-1B). Model developer: OpenBMB.
|
|
|
|
| 14 |
|
| 15 |
+
## Model overview
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
MiniCPM-V 4.7 is OpenBMB's multimodal model family for efficient local inference. The original models combine single-image, multi-image and video understanding with early visual-token compression inside the vision encoder. This reduces computation in later encoder layers; the upstream architecture supports 4x and 16x compression to trade visual detail against inference cost. This is the compact 1B-class dense variant.
|
| 18 |
|
| 19 |
+
This overview summarizes the [original model card](https://huggingface.co/openbmb/MiniCPM-V-4.7-1B). Refer to it for training details, upstream evaluations and intended uses.
|
| 20 |
|
| 21 |
+
| Property | Value |
|
| 22 |
+
| --- | --- |
|
| 23 |
+
| Language backbone | Qwen3.5 dense |
|
| 24 |
+
| Vision | Patch-14 ViT, early window merger, final MLP merger |
|
| 25 |
+
| This export | 16x visual compression, up to 9 image slices |
|
| 26 |
+
| Inputs / outputs | Text and images / text |
|
| 27 |
|
| 28 |
+
## MNN conversion
|
| 29 |
+
|
| 30 |
+
Language linear weights: HQQ4, block 64, FP16 scales. Input embeddings: BF16. Vision weights: HQQ8, block 128, with per-channel quantization where the input channels are not divisible by 128.
|
| 31 |
+
|
| 32 |
+
- Public converter/runtime baseline: **MNN 3.6.1**, commit [d662ce36175956038cfd6ed13f84cb3343a287d2](https://github.com/alibaba/MNN/commit/d662ce36175956038cfd6ed13f84cb3343a287d2).
|
| 33 |
+
- Source checkpoint: `379f120c2ff3588e6e06559ec6b9ec15cc05114e`, the Hugging Face Git revision used for the source weights.
|
| 34 |
+
- Export environment: Transformers 5.18.0, PyTorch 2.13.0, ONNX 1.16.0, HQQ 0.2.8.post1.
|
| 35 |
+
- Export options are saved in [export_args.json](export_args.json); source provenance and runtime-file SHA256 checksums are in [conversion.json](conversion.json).
|
| 36 |
+
- MiniCPM-V 4.7 adapter source snapshot: `584f2fe333bc1ad221becb75f25ad6fddfe52918`. The public baseline alone predates this adapter. Use an exporter/runtime containing this adaptation; follow [MNN issue #5015](https://github.com/alibaba/MNN/issues/5015) for upstream availability.
|
| 37 |
+
|
| 38 |
+
### Files
|
| 39 |
+
|
| 40 |
+
| File | Size (MiB) | Purpose |
|
| 41 |
+
| --- | ---: | --- |
|
| 42 |
+
| `llm.mnn` | 2.48 | Language graph |
|
| 43 |
+
| `llm.mnn.weight` | 403.63 | Language weights, including tied embeddings when configured |
|
| 44 |
+
| `embeddings_bf16.bin` | 484.56 | BF16 input embeddings |
|
| 45 |
+
| `visual.mnn` | 0.47 | Vision graph |
|
| 46 |
+
| `visual.mnn.weight` | 563.71 | Vision weights |
|
| 47 |
+
| `tokenizer.mtok` | 7.00 | MNN tokenizer |
|
| 48 |
+
|
| 49 |
+
Sizes describe storage, not peak RAM or GPU allocation. Keep graphs, weights, tokenizer and both config files together.
|
| 50 |
+
|
| 51 |
+
## Download
|
| 52 |
+
|
| 53 |
+
~~~bash
|
| 54 |
+
hf download taobao-mnn/MiniCPM-V-4.7-1B-MNN --local-dir ./MiniCPM-V-4.7-1B-MNN
|
| 55 |
~~~
|
| 56 |
|
| 57 |
+
If your environment uses the mirror, set `HF_ENDPOINT=https://hf-mirror.com` first.
|
| 58 |
+
|
| 59 |
+
## Build and convert
|
| 60 |
+
|
| 61 |
+
Use an MNN source tree with IndexedLinear support and the MiniCPM-V 4.7 adapter noted above. From its root:
|
| 62 |
+
|
| 63 |
+
~~~bash
|
| 64 |
+
cmake -S . -B build -DMNN_BUILD_LLM=ON -DMNN_LOW_MEMORY=ON \
|
| 65 |
+
-DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_LLM_OMNI=ON -DMNN_BUILD_OPENCV=ON -DMNN_IMGCODECS=ON
|
| 66 |
+
cmake --build build --target llm_demo llm_bench MNNConvert -j4
|
| 67 |
+
~~~
|
| 68 |
+
|
| 69 |
+
For Metal add `-DMNN_METAL=ON`; for Android OpenCL use the Android NDK toolchain and `-DMNN_OPENCL=ON`. Use matching backend-enabled binaries.
|
| 70 |
+
|
| 71 |
+
Download the original checkpoint at the recorded revision, install the exporter's dependencies, then run from `transformers/llm/export`:
|
| 72 |
|
| 73 |
~~~bash
|
| 74 |
+
python llmexport.py \
|
| 75 |
+
--path /path/to/original/MiniCPM-V-4.7-1B \
|
| 76 |
+
--export mnn --hqq --quant_bit 4 --quant_block 64 --scale_bit 16 \
|
| 77 |
+
--mnnconvert /path/to/MNN/build/MNNConvert \
|
| 78 |
+
--dst_path ./MiniCPM-V-4.7-1B-MNN
|
| 79 |
~~~
|
| 80 |
|
| 81 |
+
## Inference and tests
|
| 82 |
+
|
| 83 |
+
Create a greedy test config inside the downloaded model directory:
|
| 84 |
+
|
| 85 |
+
~~~python
|
| 86 |
+
import json
|
| 87 |
+
from pathlib import Path
|
| 88 |
+
model = Path('./MiniCPM-V-4.7-1B-MNN')
|
| 89 |
+
config = json.loads((model / 'config.json').read_text())
|
| 90 |
+
config.update(backend_type='cpu', precision='low', thread_num=4,
|
| 91 |
+
sampler_type='greedy', temperature=0.0, top_k=1)
|
| 92 |
+
config['mllm'] = dict(backend_type='cpu', precision='low', thread_num=4, memory='low')
|
| 93 |
+
(model / 'config-test.json').write_text(json.dumps(config, indent=2))
|
| 94 |
+
~~~
|
| 95 |
+
|
| 96 |
+
For a GPU build change backend_type to metal or opencl in both the top-level config and mllm, keeping separate language and vision runtime managers. Put each prompt on a separate line in prompts.txt:
|
| 97 |
+
|
| 98 |
+
~~~text
|
| 99 |
+
请用一句话介绍北京。
|
| 100 |
+
<img>/absolute/path/cat.jpg</img>请用一句话描述图中的动物。
|
| 101 |
+
~~~
|
| 102 |
+
|
| 103 |
+
~~~bash
|
| 104 |
+
./build/llm_demo ./MiniCPM-V-4.7-1B-MNN/config-test.json ./prompts.txt 128
|
| 105 |
+
./build/llm_bench -m ./MiniCPM-V-4.7-1B-MNN/config-test.json \
|
| 106 |
+
-a cpu -c 2 -t 4 -p 0 -n 0 -pg 512,128 -rep 3 -load false
|
| 107 |
+
~~~
|
| 108 |
+
|
| 109 |
+
Use `-a metal` or `-a opencl` for the corresponding GPU build. `-pg 512,128` measures prefill followed by decode using the same KV cache, reporting the speeds separately. `-p 512 -n 128` instead measures independent prefill-only and decode-only workloads. Text benchmarks exclude image encoding.
|
| 110 |
|
| 111 |
## Validation
|
| 112 |
|
| 113 |
+
Linux CPU text/image generation and Python prefill/first-decode parity passed. Single-image, sliced-image and multi-image token IDs and Canvas positions were checked against the original processor. Android PJZ110 passed 11 ARM CPU/OpenCL checks, including vision and language at Low precision; standard llm_demo text/image generation passed on both. Metal text/image correctness and GPU execution were verified on an M4 Mac mini.
|
| 114 |
+
|
| 115 |
+
The MNN adapter is validated for images, including slicing and multiple images. Video has not been validated. Upstream capabilities describe the original model; these functional checks are not a quality benchmark for the quantized MNN files.
|
| 116 |
+
|
| 117 |
+
### Measured text performance
|
| 118 |
+
|
| 119 |
+
Low precision, HQQ4 language weights, four threads, one warmup excluded, three measured repetitions and no mmap. These are different devices, not a controlled backend comparison.
|
| 120 |
+
|
| 121 |
+
| Device / backend | pp512 (token/s) | tg128 (token/s) | pp512+tg128: prefill / decode (token/s) |
|
| 122 |
+
| --- | ---: | ---: | ---: |
|
| 123 |
+
| M4 Mac mini, 16 GB / Metal | 2581.3 ± 1.2 | 188.6 ± 0.2 | 2576.4 / 185.2 |
|
| 124 |
+
| Snapdragon 8 Elite, Adreno 830 / OpenCL | 1104.4 ± 9.6 | 76.6 ± 0.1 | 1099.0 / 76.1 |
|
| 125 |
+
|
| 126 |
+
For 2048-token prefill followed by 128 decode tokens, Metal measured 2650.3 / 178.1 token/s and OpenCL measured 1033.2 / 75.5 token/s. Results are specific to the recorded snapshot and devices.
|
| 127 |
+
|
| 128 |
+
## License and attribution
|
| 129 |
|
| 130 |
+
Original model and weights: OpenBMB, Apache-2.0. See the complete [LICENSE](LICENSE) and original model card.
|
conversion.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model": "MiniCPM-V-4.7-1B",
|
| 3 |
+
"mnn_version": "3.6.1",
|
| 4 |
+
"mnn_converter_runtime_public_commit": "d662ce36175956038cfd6ed13f84cb3343a287d2",
|
| 5 |
+
"source_repo": "openbmb/MiniCPM-V-4.7-1B",
|
| 6 |
+
"source_revision": "379f120c2ff3588e6e06559ec6b9ec15cc05114e",
|
| 7 |
+
"source_url": "https://huggingface.co/openbmb/MiniCPM-V-4.7-1B",
|
| 8 |
+
"quantization": {
|
| 9 |
+
"method": "HQQ",
|
| 10 |
+
"weight_bits": 4,
|
| 11 |
+
"block_size": 64,
|
| 12 |
+
"scale_bits": 16,
|
| 13 |
+
"embedding": {
|
| 14 |
+
"storage": "BF16 external"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"export_packages": {
|
| 18 |
+
"torch": "2.13.0",
|
| 19 |
+
"transformers": "5.18.0",
|
| 20 |
+
"onnx": "1.16.0",
|
| 21 |
+
"hqq": "0.2.8.post1",
|
| 22 |
+
"safetensors": "0.8.0"
|
| 23 |
+
},
|
| 24 |
+
"files": {
|
| 25 |
+
"llm.mnn.weight": {
|
| 26 |
+
"size": 423234586,
|
| 27 |
+
"sha256": "f4c2519d1e96f5a23515c97a7c6cad0db0d8d8c813c44038292803dad59ba2df"
|
| 28 |
+
},
|
| 29 |
+
"visual.mnn.weight": {
|
| 30 |
+
"size": 591096650,
|
| 31 |
+
"sha256": "d411969d6de971ce38acd9f3692cbcf952b2d0d2cf96bbd609618a0b3edd71d8"
|
| 32 |
+
},
|
| 33 |
+
"export_args.json": {
|
| 34 |
+
"size": 1117,
|
| 35 |
+
"sha256": "c07d12c6ce7638dbccbbe2d3a67f4ec479c30e79ad1c9f05916c20e9def527d8"
|
| 36 |
+
},
|
| 37 |
+
"LICENSE": {
|
| 38 |
+
"size": 11346,
|
| 39 |
+
"sha256": "a830d59c4f98d110e0540d0581efada06192ba6e798434307d1794b07a290302"
|
| 40 |
+
},
|
| 41 |
+
"llm_config.json": {
|
| 42 |
+
"size": 8510,
|
| 43 |
+
"sha256": "90a9ebea9dc5bf8a531ccdea28477cb362379e2049b70e7ff44f3ff27335af15"
|
| 44 |
+
},
|
| 45 |
+
"tokenizer.mtok": {
|
| 46 |
+
"size": 7334903,
|
| 47 |
+
"sha256": "6d5d90b7fc88cba043a2eb7d7cb909cec5c5911f4d02a9838d12d7787221ddd9"
|
| 48 |
+
},
|
| 49 |
+
"config.json": {
|
| 50 |
+
"size": 634,
|
| 51 |
+
"sha256": "b81ac7008ba5f894301b7b9265bba882889df52c6e25c86390514c1bd4afe0c4"
|
| 52 |
+
},
|
| 53 |
+
"visual.mnn": {
|
| 54 |
+
"size": 495696,
|
| 55 |
+
"sha256": "fe88829e2c4fa0c4ff1686ae0b0a2c4e7c5683f94d1621c1fb5924dc5946b959"
|
| 56 |
+
},
|
| 57 |
+
"llm.mnn": {
|
| 58 |
+
"size": 2603920,
|
| 59 |
+
"sha256": "c6cdbc5a1f7bfe20510d3770d6784d1ef387f1a921cf66ae861f0c0d53edd5a4"
|
| 60 |
+
},
|
| 61 |
+
"embeddings_bf16.bin": {
|
| 62 |
+
"size": 508096512,
|
| 63 |
+
"sha256": "6e6d9326e7a960b96d3c9fcf07686d26ab3147556a280dceb494806594f1e334"
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"minicpm_adapter_source_commit": "584f2fe333bc1ad221becb75f25ad6fddfe52918",
|
| 67 |
+
"source_weight_files": [
|
| 68 |
+
{
|
| 69 |
+
"name": "model.safetensors",
|
| 70 |
+
"size": 3109054480,
|
| 71 |
+
"sha256": "8c4921ac83182c85190ad10c3aeb118d51e385d2d98ec13b88b514bbf6cac002"
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
}
|