Run this model with HF Jobs
Run openbmb/MiniCPM4-8B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/openbmb/MiniCPM4-8B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/openbmb/MiniCPM4-8B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/openbmb/MiniCPM4-8B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/openbmb/MiniCPM4-8B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use openbmb/MiniCPM4-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM4-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM4-8B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM4-8B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM4-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM4-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM4-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM4-8B
- SGLang
How to use openbmb/MiniCPM4-8B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openbmb/MiniCPM4-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM4-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openbmb/MiniCPM4-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM4-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM4-8B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM4-8B
Add model description and link to paper (#5)
Browse files- Add model description and link to paper (f9c341a8fbe4c21c893d7e20421ba25e884ba8c9)
Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>
123456789101168 unmodified lines80818283848586878889909192106 unmodified lines199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310---license: apache-2.0language:- zh- enpipeline_tag: text-generationlibrary_name: transformers---<div align="center"><img src="https://github.com/OpenBMB/MiniCPM/blob/main/assets/minicpm_logo.png?raw=true" width="500em" ></img></div>68 unmodified lines}```After modification, you can run the following command to reproduce the long-context acceleration effect (the script will automatically download the model weights from HuggingFace)```bashpython3 tests/test_generate.py```For more details about CPM.cu, please refer to [the repo CPM.cu](https://github.com/OpenBMB/cpm.cu).### Inference with Transformers```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer106 unmodified lines```pythonimport openaiclient = openai.Client(base_url=f"http://localhost:30000/v1", api_key="None")response = client.chat.completions.create(model="openbmb/MiniCPM4-8B",messages=[{"role": "user", "content": "Write an article about Artificial Intelligence."},],temperature=0.7,max_tokens=1024,)print(response.choices[0].message.content)```### Inference with [vLLM](https://github.com/vllm-project/vllm)For now, you need to install the latest version of vLLM.```pip install -U vllm \--pre \--extra-index-url https://wheels.vllm.ai/nightly```Then you can inference MiniCPM4-8B with vLLM:```pythonfrom transformers import AutoTokenizerfrom vllm import LLM, SamplingParamsmodel_name = "openbmb/MiniCPM4-8B"prompt = [{"role": "user", "content": "Please recommend 5 tourist attractions in Beijing. "}]tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)llm = LLM(model=model_name,trust_remote_code=True,max_num_batched_tokens=32768,dtype="bfloat16",gpu_memory_utilization=0.8,)sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)print(outputs[0].outputs[0].text)```Also, you can start the inference server by running the following command:> **Note**: In vLLM's chat API, `add_special_tokens` is `False` by default. This means important special tokens—such as the beginning-of-sequence (BOS) token—will not be added automatically. To ensure the input prompt is correctly formatted for the model, you should explicitly set `extra_body={"add_special_tokens": True}`.```bashvllm serve openbmb/MiniCPM4-8B```Then you can use the chat interface by running the following code:```pythonimport openaiclient = openai.Client(base_url="http://localhost:8000/v1", api_key="EMPTY")response = client.chat.completions.create(model="openbmb/MiniCPM4-8B",messages=[{"role": "user", "content": "Write an article about Artificial Intelligence."},],temperature=0.7,max_tokens=1024,extra_body=dict(add_special_tokens=True), # Ensures special tokens are added for chat template)print(response.choices[0].message.content)```## Evaluation ResultsOn two typical end-side chips, Jetson AGX Orin and RTX 4090, MiniCPM4 demonstrates significantly faster processing speed compared to similar-size models in long text processing tasks. As text length increases, MiniCPM4's efficiency advantage becomes more pronounced. On the Jetson AGX Orin platform, compared to Qwen3-8B, MiniCPM4 achieves approximately 7x decoding speed improvement.#### Comprehensive EvaluationMiniCPM4 launches end-side versions with 8B and 0.5B parameter scales, both achieving best-in-class performance in their respective categories.#### Long Text EvaluationMiniCPM4 is pre-trained on 32K long texts and achieves length extension through YaRN technology. In the 128K long text needle-in-a-haystack task, MiniCPM4 demonstrates outstanding performance.## Statement- As a language model, MiniCPM generates content by learning from a vast amount of text.- However, it does not possess the ability to comprehend or express personal opinions or value judgments.- Any content generated by MiniCPM does not represent the viewpoints or positions of the model developers.- Therefore, when using content generated by MiniCPM, users should take full responsibility for evaluating and verifying it on their own.## LICENSE- This repository and MiniCPM models are released under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM/blob/main/LICENSE) License.## Citation- Please cite our [paper](https://github.com/OpenBMB/MiniCPM/tree/main/report/MiniCPM_4_Technical_Report.pdf) if you find our work valuable.```bibtex@article{minicpm4,title={{MiniCPM4}: Ultra-Efficient LLMs on End Devices},author={MiniCPM Team},year={2025}}```123456789101112131468 unmodified lines838485868788106 unmodified lines195196197198---language:- zh- enlibrary_name: transformerslicense: apache-2.0pipeline_tag: text-generation---MiniCPM4-8B is a highly efficient large language model (LLM) designed explicitly for end-side devices. It achieves this efficiency through systematic innovation in model architecture, training data, training algorithms, and inference systems. The details can be found in [MiniCPM4: Ultra-Efficient LLMs on End Devices](https://huggingface.co/papers/2506.07900).<div align="center"><img src="https://github.com/OpenBMB/MiniCPM/blob/main/assets/minicpm_logo.png?raw=true" width="500em" ></img></div>68 unmodified lines}```### Inference with Transformers```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer106 unmodified lines```pythonimport openaiclient =
README.md+6-118