# Deploy MiniCPM5-15B-A2.5B with 🤗 Transformers `AutoModelForCausalLM` loads MiniCPM5-15B-A2.5B using the `MiniCPM5MoeForCausalLM` implementation registered by Transformers. The checkpoint's `config.json` declares its architecture as `MiniCPM5MoEForCausalLM`; for backward compatibility, Transformers rewrites that old name to `MiniCPM5MoeForCausalLM`, so the capitalization difference does not affect loading. ## Install Transformers 5.25.0 and newer register `minicpm5_moe`. If your installed version does not recognize it, upgrade. [Transformers model support](https://github.com/huggingface/transformers/pull/51218) ```bash python -m pip install -U "transformers>=5.25.0" accelerate torch ``` Check that the installed Transformers registers the model type. The command should print `minicpm5_moe`: ```bash python -c 'from transformers import AutoConfig; print(AutoConfig.for_model("minicpm5_moe").model_type)' ``` ## GPU inference (bfloat16) The BF16 weights take about 30 GB. `device_map="auto"` places them on one GPU or spreads them across several. ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer model_path = "openbmb/MiniCPM5-15B-A2.5B" tokenizer = AutoTokenizer.from_pretrained(model_path) model = AutoModelForCausalLM.from_pretrained( model_path, dtype=torch.bfloat16, device_map="auto", ).eval() messages = [{"role": "user", "content": "Who are you? Please briefly introduce yourself."}] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, enable_thinking=True, # set to False to disable thinking mode return_tensors="pt", return_dict=True, ).to(model.device) with torch.no_grad(): outputs = model.generate( **inputs, max_new_tokens=1024, do_sample=True, temperature=1.0, top_p=0.95, ) prompt_len = inputs["input_ids"].shape[-1] print(tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True)) ``` ## CPU-only inference The model also runs on CPU, for example on a no-GPU host for a quick sanity check. Change the loading call above to the following: ```python model = AutoModelForCausalLM.from_pretrained( model_path, dtype=torch.bfloat16, # use torch.float32 on CPUs without BF16 support device_map="cpu", ).eval() ``` CPU generation is slow. For local inference on a laptop, use the GGUF files with [llama.cpp](llama_cpp.md) or the MLX checkpoint with [MLX-VLM](mlx.md) instead. ## Generation defaults | Mode | `enable_thinking` | Sampling | | --- | --- | --- | | Thinking (general tasks, default) | `True` | `temperature=1.0`, `top_p=0.95`, `min_p=0.0` (add `repetition_penalty=1.05` if outputs repeat) | | Creative writing | `True` | `temperature=0.7`, `top_p=0.95`, `min_p=0.0`, `repetition_penalty=1.05` | | Non-thinking | `False` | `temperature=0.7`, `top_p=0.80`, `top_k=20`, `min_p=0.0`, `repetition_penalty=1.0` | `generation_config.json` is tuned for thinking mode by default. ## Common issues - `KeyError: 'minicpm5_moe'` or "model type not recognized": install the model-support build above in the Python environment running inference. - Out of GPU memory: spread the model across more GPUs with `device_map="auto"`, or serve the INT4 checkpoint with [vLLM](vllm.md) or [SGLang](sglang.md). [Agent skill for Transformers deployment](../../../skills/minicpm5-15b-a2p5b-deploy-transformers/SKILL.md)