Text Generation
Transformers
Safetensors
English
Chinese
llama
minicpm
minicpm5
long-context
tool-calling
on-device
edge-ai
conversational
text-generation-inference
Instructions to use openbmb/MiniCPM5-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM5-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM5-2B") 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/MiniCPM5-2B") model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM5-2B", 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/MiniCPM5-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM5-2B" # 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/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM5-2B
- SGLang
How to use openbmb/MiniCPM5-2B 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/MiniCPM5-2B" \ --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/MiniCPM5-2B", "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/MiniCPM5-2B" \ --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/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM5-2B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM5-2B
Remove the dead `<tool_sep>` branch from chat_template.jinja (fixes OpenBMB/MiniCPM#379)
#19
by lhz7891444 - opened
- chat_template.jinja +1 -66
chat_template.jinja
CHANGED
|
@@ -51,71 +51,6 @@
|
|
| 51 |
{%- endif %}
|
| 52 |
{%- endif %}
|
| 53 |
|
| 54 |
-
{%- if message.tool_calls %}
|
| 55 |
-
{%- set content_parts = content.split('<tool_sep>') %}
|
| 56 |
-
{%- set processed_content = content_parts[0] %}
|
| 57 |
-
{%- set tool_calls_count = message.tool_calls|length %}
|
| 58 |
-
{%- set tool_sep_count = content_parts|length - 1 %}
|
| 59 |
-
{%- set min_count = [tool_calls_count, tool_sep_count]|min %}
|
| 60 |
-
|
| 61 |
-
{%- for i in range(1, content_parts|length) %}
|
| 62 |
-
{%- set tool_index = i - 1 %}
|
| 63 |
-
{%- if tool_index < tool_calls_count %}
|
| 64 |
-
{%- set tool_call = message.tool_calls[tool_index] %}
|
| 65 |
-
{%- if tool_call.function %}
|
| 66 |
-
{%- set tool_call = tool_call.function %}
|
| 67 |
-
{%- endif %}
|
| 68 |
-
{%- set single_tool_xml %}
|
| 69 |
-
{{- '<function name="' ~ tool_call.name ~ '">' }}
|
| 70 |
-
{%- if tool_call.arguments %}
|
| 71 |
-
{%- set args_dict = tool_call.arguments %}
|
| 72 |
-
{%- for param_name, param_value in args_dict.items() %}
|
| 73 |
-
{{- '<param name="' ~ param_name ~ '">' }}
|
| 74 |
-
{%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
|
| 75 |
-
{{- '<![CDATA[' + param_value + ']]>' }}
|
| 76 |
-
{%- else %}
|
| 77 |
-
{{- param_value }}
|
| 78 |
-
{%- endif %}
|
| 79 |
-
{{- '</param>' }}
|
| 80 |
-
{%- endfor %}
|
| 81 |
-
{%- endif %}
|
| 82 |
-
{{- '</function>' }}
|
| 83 |
-
{%- endset %}
|
| 84 |
-
{%- set processed_content = processed_content + single_tool_xml + content_parts[i] %}
|
| 85 |
-
{%- else %}
|
| 86 |
-
{%- set processed_content = processed_content + content_parts[i] %}
|
| 87 |
-
{%- endif %}
|
| 88 |
-
{%- endfor %}
|
| 89 |
-
|
| 90 |
-
{%- if tool_calls_count > tool_sep_count %}
|
| 91 |
-
{%- for remaining_index in range(tool_sep_count, tool_calls_count) %}
|
| 92 |
-
{%- set tool_call = message.tool_calls[remaining_index] %}
|
| 93 |
-
{%- if tool_call.function %}
|
| 94 |
-
{%- set tool_call = tool_call.function %}
|
| 95 |
-
{%- endif %}
|
| 96 |
-
{%- set remaining_tool_xml %}
|
| 97 |
-
{{- '<function name="' ~ tool_call.name ~ '">' }}
|
| 98 |
-
{%- if tool_call.arguments %}
|
| 99 |
-
{%- set args_dict = tool_call.arguments %}
|
| 100 |
-
{%- for param_name, param_value in args_dict.items() %}
|
| 101 |
-
{{- '<param name="' ~ param_name ~ '">' }}
|
| 102 |
-
{%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
|
| 103 |
-
{{- '<![CDATA[' + param_value + ']]>' }}
|
| 104 |
-
{%- else %}
|
| 105 |
-
{{- param_value }}
|
| 106 |
-
{%- endif %}
|
| 107 |
-
{{- '</param>' }}
|
| 108 |
-
{%- endfor %}
|
| 109 |
-
{%- endif %}
|
| 110 |
-
{{- '</function>' }}
|
| 111 |
-
{%- endset %}
|
| 112 |
-
{%- set processed_content = processed_content + remaining_tool_xml %}
|
| 113 |
-
{%- endfor %}
|
| 114 |
-
{%- endif %}
|
| 115 |
-
|
| 116 |
-
{%- set content = processed_content %}
|
| 117 |
-
{%- endif %}
|
| 118 |
-
|
| 119 |
{%- if reasoning_content %}
|
| 120 |
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 121 |
{%- elif '<think>' not in content and '</think>' not in content %}
|
|
@@ -124,7 +59,7 @@
|
|
| 124 |
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 125 |
{%- endif %}
|
| 126 |
|
| 127 |
-
{%- if message.tool_calls
|
| 128 |
{%- for tool_call in message.tool_calls %}
|
| 129 |
{%- if (loop.first and content) or (not loop.first) %}
|
| 130 |
{{- '\n' }}
|
|
|
|
| 51 |
{%- endif %}
|
| 52 |
{%- endif %}
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
{%- if reasoning_content %}
|
| 55 |
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 56 |
{%- elif '<think>' not in content and '</think>' not in content %}
|
|
|
|
| 59 |
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 60 |
{%- endif %}
|
| 61 |
|
| 62 |
+
{%- if message.tool_calls %}
|
| 63 |
{%- for tool_call in message.tool_calls %}
|
| 64 |
{%- if (loop.first and content) or (not loop.first) %}
|
| 65 |
{{- '\n' }}
|