1## MiniCPM-o 4
 2
 3### Prepare models and code
 4
 5Download [MiniCPM-o-4](https://huggingface.co/openbmb/MiniCPM-o-4) PyTorch model from huggingface to "MiniCPM-o-4" folder.
 6
 7
 8### Build llama.cpp
 9Readme modification time: 20250206
10
11If there are differences in usage, please refer to the official build [documentation](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md)
12
13Clone llama.cpp:
14```bash
15git clone https://github.com/ggml-org/llama.cpp
16cd llama.cpp
17```
18
19Build llama.cpp using `CMake`:
20```bash
21cmake -B build
22cmake --build build --config Release
23```
24
25
26### Usage of MiniCPM-o 4
27
28Convert PyTorch model to gguf files (You can also download the converted [gguf](https://huggingface.co/openbmb/MiniCPM-o-4-gguf) by us)
29
30```bash
31python ./tools/mtmd/legacy-models/minicpmv-surgery.py -m ../MiniCPM-o-4
32python ./tools/mtmd/legacy-models/minicpmv-convert-image-encoder-to-gguf.py -m ../MiniCPM-o-4 --minicpmv-projector ../MiniCPM-o-4/minicpmv.projector --output-dir ../MiniCPM-o-4/ --minicpmv_version 6
33python ./convert_hf_to_gguf.py ../MiniCPM-o-4/model
34
35# quantize int4 version
36./build/bin/llama-quantize ../MiniCPM-o-4/model/ggml-model-f16.gguf ../MiniCPM-o-4/model/ggml-model-Q4_K_M.gguf Q4_K_M
37```
38
39
40Inference on Linux or Mac
41```bash
42# run in single-turn mode
43./build/bin/llama-mtmd-cli -m ../MiniCPM-o-4/model/ggml-model-f16.gguf --mmproj ../MiniCPM-o-4/mmproj-model-f16.gguf -c 4096 --temp 0.7 --top-p 0.8 --top-k 100 --repeat-penalty 1.05 --image xx.jpg -p "What is in the image?"
44
45# run in conversation mode
46./build/bin/llama-mtmd-cli -m ../MiniCPM-o-4/model/ggml-model-Q4_K_M.gguf --mmproj ../MiniCPM-o-4/mmproj-model-f16.gguf
47```