# Deploy MiniCPM5-15B-A2.5B with MLX-VLM Use [MLX-VLM](https://github.com/Neywa-Labs/mlx-vlm) on an Apple Silicon Mac for local text generation or OpenAI-compatible Chat Completions. The [MLX checkpoint](https://huggingface.co/openbmb/MiniCPM5-15B-A2.5B-MLX) contains a single affine 4-bit weight file (group size 128), the tokenizer and the chat template. Choose it when BF16 leaves too little unified memory for the model and KV cache, or to try faster decoding. Quantization can reduce accuracy. For original precision on a Mac, see [BF16 GGUF with Metal](llama_cpp.md#2-download-a-gguf-model). ## Install MLX-VLM Use a native arm64 Python environment (Python 3.11 or newer recommended). Install from upstream `main` for the MiniCPM5 MoE loader and DSpark support. MLX-VLM 0.8.2 was released before this integration. [Model support](https://github.com/Neywa-Labs/mlx-vlm/pull/2866) ```bash python3 -m venv .venv source .venv/bin/activate python -m pip install --upgrade "git+https://github.com/Neywa-Labs/mlx-vlm.git@main" ``` ## Generate a reply Pass the Hugging Face model ID, or set `MODEL` to the path of a complete local MLX snapshot. Use the same value when starting the server and sending requests. ```bash export MODEL=openbmb/MiniCPM5-15B-A2.5B-MLX python -m mlx_vlm.generate --model "$MODEL" --prompt "Explain unified memory in one sentence." ``` ## Start the server ```bash python -m mlx_vlm.server --model "$MODEL" ``` The default port is 8080. In a second terminal, list the models and send a chat request. If you started the server with a local path, replace the example request's `model` with the loaded ID shown by `/v1/models`. ```bash curl -fsS http://127.0.0.1:8080/v1/models curl -fsS http://127.0.0.1:8080/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "openbmb/MiniCPM5-15B-A2.5B-MLX", "messages": [{"role": "user", "content": "What is unified memory?"}], "temperature": 1.0, "top_p": 0.95 }' ``` To disable thinking for a chat request, add `"enable_thinking": false` at the top level of the JSON payload. For non-thinking mode the model card recommends `temperature=0.7` and `top_p=0.80`. For creative writing with thinking enabled, use `temperature=0.7` and `top_p=0.95`. [Model card](https://huggingface.co/openbmb/MiniCPM5-15B-A2.5B) ## Speculative decoding with DSpark (optional) Stop the target-only server and start it with the matching [DSpark checkpoint](https://huggingface.co/openbmb/MiniCPM5-15B-A2.5B-DSpark). Clients keep the same target model ID. ```bash python -m mlx_vlm.server --model "$MODEL" --draft-model openbmb/MiniCPM5-15B-A2.5B-DSpark ``` MLX-VLM reads the block size from the drafter. Its `--draft-block-size` counts one target token plus the draft positions, so a block size of 8 allows up to seven proposals. For a shorter cap, a block size of 4 allows up to three. Compare decoding latency on your prompts and leave unified memory for both models and the KV cache. The same draft options work with `mlx_vlm.generate`. [DSpark tuning](dspark.md) ## Tool calling The server selects `minicpm5` from the chat template. For the updated handling of tool arguments in streamed and non-streamed responses, apply the [tool parser update](https://github.com/Neywa-Labs/mlx-vlm/pull/2870) on top of upstream `main`. Stop the running server, then run these commands in the same Python environment. ```bash git clone https://github.com/Neywa-Labs/mlx-vlm.git git -C mlx-vlm fetch https://github.com/cyxu0401/mlx-vlm.git xcy/minicpm-tool-parser-update git -C mlx-vlm merge --no-edit FETCH_HEAD python -m pip install -e ./mlx-vlm python -m mlx_vlm.server --model "$MODEL" ``` ```bash curl -fsS http://127.0.0.1:8080/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "openbmb/MiniCPM5-15B-A2.5B-MLX", "messages": [{"role": "user", "content": "Use get_weather to look up the weather in Beijing."}], "tools": [{"type": "function", "function": { "name": "get_weather", "description": "Look up the weather in a city.", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]} }}] }' ``` Read the function name and JSON arguments from `choices[0].message.tool_calls`. To continue the conversation, append the assistant message, then the tool result with its matching `tool_call_id`. For streaming, join argument fragments by call index before parsing them as JSON. ## Stream in Python For a text-only application, load the checkpoint once and pass token IDs directly to generation. This applies the chat template exactly once and is useful when comparing input token IDs with Transformers. ```python import os import mlx.core as mx from mlx_vlm import load, stream_generate model, processor = load(os.environ["MODEL"]) tokenizer = getattr(processor, "tokenizer", processor) messages = [{"role": "user", "content": "Explain unified memory in one sentence."}] ids = tokenizer.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_dict=False ) for chunk in stream_generate(model, processor, prompt="", input_ids=mx.array([ids])): print(chunk.text, end="", flush=True) print() ``` ## Common issues - **Unknown model type**. Check the active environment with `python -c 'from mlx_vlm.models.minicpm5_moe import Model'`. Use the MLX checkpoint with its tokenizer and template. - **Tool markup appears in chat**. Query `/health` on the running server and check that `loaded_tool_parser` is `minicpm5`. Verify the server is using the updated parser checkout. - **Memory pressure with DSpark**. Retry the same request with only the target loaded. Draft weights and verification consume additional unified memory. [Agent skill for MLX-VLM deployment](../../../skills/minicpm5-15b-a2p5b-deploy-mlx/SKILL.md)