Instructions to use openbmb/MiniCPM3-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM3-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM3-4B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openbmb/MiniCPM3-4B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM3-4B", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM3-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM3-4B" # 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/MiniCPM3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM3-4B
- SGLang
How to use openbmb/MiniCPM3-4B 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/MiniCPM3-4B" \ --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/MiniCPM3-4B", "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/MiniCPM3-4B" \ --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/MiniCPM3-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM3-4B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM3-4B
Commit History
-
Remove 'Args:' if there are none
Verified signature3d4716e
-
Implemented nested types++
Verified signature0258b84
-
Fixed boolean default arguments
Verified signaturec97ecd6 -
Fixed missing condition for system <|im_end|>
Verified signature3bcbd7b -
Added support for argument pattern
Verified signature39cf8dd -
Added support for default arguments
Verified signature7e9c9d4
-
Add full tool calling support to chat template
Verified signatureThis adds full tool calling support to the chat template, producing pretty much identical results as the the prompt processing code in `tokenization_minicpm.py`. Fully supports generating `tool_call` (requires `arguments` to be a dict (as supported in recent `transformers`) and not a string) and `thought` history. Also sets `add_bos_token` to false to prevent `<s>` from being added to the prompt when not using the chat template, as it clearly should not be.aa415fb
-
Add `model_type` to config (#17)
Verified signature- Add `model_type` to config (5b3a3755c38b0b34f7fc515496abfded12f24103) Co-authored-by: Daniel Huang <pi314ever-intel@users.noreply.huggingface.co>6fcf8b4
-
add library tag (#8)
Verified signature- add library tag (6b05abdbcbd30d105b5a069715c391760fd66804) Co-authored-by: Daniel van Strien <davanstrien@users.noreply.huggingface.co>75f9f10
-
Update README.md
Verified signature8d724f7
-
Update tokenization_minicpm.py
Verified signaturef5d31d8 -
Update README.md
Verified signaturee618f3a -
fix loss in modeling_minicpm.py
FrankC0st1efc345c8 -
update bfcl and livecodebench version
FrankC0st1e65d6b09 -
Update README.md
Verified signature52fc630 -
Update README.md
Verified signaturea18cc45 -
Update README.md
Verified signature84b4815 -
Update README.md
Verified signaturef03dca5 -
Update README.md
Verified signatured7cca6a -
update readme
FrankC0st1e65aff61 -
add vllm inference example
FrankC0st1e49e4794 -
update readme
FrankC0st1e6c769fa -
fix: empty system prompt
FrankC0st1e43b498b
-
fix bug in .py
FrankC0st1ea4f2dcb -
change name to minicpm3
FrankC0st1e8fa0de6
-
fix name_or_path in config.json
FrankC0st1e91a5e0a -
initial commit
yanhui4a38946 -
initial commit
Verified signature760549e