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
update README.md
Browse files
README.md
CHANGED
|
@@ -208,8 +208,35 @@ print(response.choices[0].message.content)
|
|
| 208 |
|
| 209 |
### Inference with [vLLM](https://github.com/vllm-project/vllm)
|
| 210 |
For now, you need to install the latest version of vLLM.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
```
|
| 214 |
|
| 215 |
## Evaluation Results
|
|
|
|
| 208 |
|
| 209 |
### Inference with [vLLM](https://github.com/vllm-project/vllm)
|
| 210 |
For now, you need to install the latest version of vLLM.
|
| 211 |
+
```
|
| 212 |
+
pip install -U vllm \
|
| 213 |
+
--pre \
|
| 214 |
+
--extra-index-url https://wheels.vllm.ai/nightly
|
| 215 |
+
```
|
| 216 |
|
| 217 |
+
Then you can inference MiniCPM4-8B with vLLM:
|
| 218 |
+
```python
|
| 219 |
+
from transformers import AutoTokenizer
|
| 220 |
+
from vllm import LLM, SamplingParams
|
| 221 |
+
|
| 222 |
+
model_name = "openbmb/MiniCPM4-8B"
|
| 223 |
+
prompt = [{"role": "user", "content": "Please recommend 5 tourist attractions in Beijing. "}]
|
| 224 |
+
|
| 225 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 226 |
+
input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
|
| 227 |
+
|
| 228 |
+
llm = LLM(
|
| 229 |
+
model=model_name,
|
| 230 |
+
trust_remote_code=True,
|
| 231 |
+
max_num_batched_tokens=32768,
|
| 232 |
+
dtype="bfloat16",
|
| 233 |
+
gpu_memory_utilization=0.8,
|
| 234 |
+
)
|
| 235 |
+
sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
|
| 236 |
+
|
| 237 |
+
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
|
| 238 |
+
|
| 239 |
+
print(outputs[0].outputs[0].text)
|
| 240 |
```
|
| 241 |
|
| 242 |
## Evaluation Results
|