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)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM3-4B", trust_remote_code=True, dtype="auto") - 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
FrankC0st1e commited on
Commit ·
49e4794
1
Parent(s): 6c769fa
add vllm inference example
Browse files
README.md
CHANGED
|
@@ -18,11 +18,11 @@ MiniCPM3-4B is the 3rd generation of MiniCPM series. The overall performance of
|
|
| 18 |
|
| 19 |
Compared to MiniCPM1.0/MiniCPM2.0, MiniCPM3-4B has a more powerful and versatile skill set to enable more general usage. MiniCPM3-4B supports function call, along with code interpreter. Please refer to []() for usage guidelines.
|
| 20 |
|
| 21 |
-
MiniCPM3-4B has a 32k context window. Equipped with
|
| 22 |
|
| 23 |
## Usage
|
|
|
|
| 24 |
```python
|
| 25 |
-
|
| 26 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 27 |
import torch
|
| 28 |
|
|
@@ -42,7 +42,7 @@ model_outputs = model.generate(
|
|
| 42 |
max_new_tokens=1024,
|
| 43 |
top_p=0.7,
|
| 44 |
temperature=0.7,
|
| 45 |
-
repetition_penalty=1.02
|
| 46 |
)
|
| 47 |
|
| 48 |
output_token_ids = [
|
|
@@ -53,6 +53,29 @@ responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0
|
|
| 53 |
print(responses)
|
| 54 |
```
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
## Evaluation Results
|
| 57 |
|
| 58 |
<table>
|
|
|
|
| 18 |
|
| 19 |
Compared to MiniCPM1.0/MiniCPM2.0, MiniCPM3-4B has a more powerful and versatile skill set to enable more general usage. MiniCPM3-4B supports function call, along with code interpreter. Please refer to []() for usage guidelines.
|
| 20 |
|
| 21 |
+
MiniCPM3-4B has a 32k context window. Equipped with LLMxMapReduce, MiniCPM3-4B can handle infinite contexts theoretically, without requiring huge amount of memory.
|
| 22 |
|
| 23 |
## Usage
|
| 24 |
+
### Inference with Transformers
|
| 25 |
```python
|
|
|
|
| 26 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 27 |
import torch
|
| 28 |
|
|
|
|
| 42 |
max_new_tokens=1024,
|
| 43 |
top_p=0.7,
|
| 44 |
temperature=0.7,
|
| 45 |
+
repetition_penalty=1.02
|
| 46 |
)
|
| 47 |
|
| 48 |
output_token_ids = [
|
|
|
|
| 53 |
print(responses)
|
| 54 |
```
|
| 55 |
|
| 56 |
+
### Inference with [vLLM](https://github.com/vllm-project/vllm)
|
| 57 |
+
```python
|
| 58 |
+
from transformers import AutoTokenizer
|
| 59 |
+
from vllm import LLM, SamplingParams
|
| 60 |
+
|
| 61 |
+
model_name = "openbmb/MiniCPM3-4B"
|
| 62 |
+
prompt = [{"role": "user", "content": "推荐5个北京的景点。"}]
|
| 63 |
+
|
| 64 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 65 |
+
input_text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
|
| 66 |
+
|
| 67 |
+
llm = LLM(
|
| 68 |
+
model=model_name,
|
| 69 |
+
trust_remote_code=True,
|
| 70 |
+
tensor_parallel_size=1
|
| 71 |
+
)
|
| 72 |
+
sampling_params = SamplingParams(top_p=0.7, temperature=0.7, max_tokens=1024, repetition_penalty=1.02)
|
| 73 |
+
|
| 74 |
+
outputs = llm.generate(prompts=input_text, sampling_params=sampling_params)
|
| 75 |
+
|
| 76 |
+
print(outputs[0].outputs[0].text)
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
## Evaluation Results
|
| 80 |
|
| 81 |
<table>
|