Instructions to use deepseek-ai/DeepSeek-V4-Pro with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-V4-Pro with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-V4-Pro") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V4-Pro") model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-V4-Pro") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use deepseek-ai/DeepSeek-V4-Pro with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-V4-Pro" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-V4-Pro", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/deepseek-ai/DeepSeek-V4-Pro
- SGLang
How to use deepseek-ai/DeepSeek-V4-Pro 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 "deepseek-ai/DeepSeek-V4-Pro" \ --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": "deepseek-ai/DeepSeek-V4-Pro", "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 "deepseek-ai/DeepSeek-V4-Pro" \ --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": "deepseek-ai/DeepSeek-V4-Pro", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use deepseek-ai/DeepSeek-V4-Pro with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-V4-Pro
DeepSeek model output sometimes contains DSML tool-call markup
DeepSeek model output sometimes contains DSML tool-call markup, but the API/client does not parse it into structured tool_calls. Instead, the whole assistant message is returned as plain text in message.content.
Example returned content:
I will search several relevant directions first.<||DSML||tool_calls><||DSML||invoke name="doc_knowlegebase"><||DSML||parameter name="query" string="true">bond detail fields display</||DSML||parameter></||DSML||invoke></||DSML||tool_calls>
Expected behavior:
The DSML block should be parsed into a structured tool call, for example:
{
"tool_calls": [
{
"type": "function",
"function": {
"name": "doc_knowlegebase",
"arguments": "{\"query\":\"bond detail fields display\"}"
}
}
]
}
Actual behavior:
The DSML block is returned inside normal assistant text content, so downstream code receives it as a plain string and must manually parse it.
Possible issue:
The emitted DSML token appears degraded from the documented full-width format:
<|DSML|tool_calls>
to an ASCII double-pipe-like form:
<||DSML||tool_calls>
Also, the markup may be emitted without the newlines expected by the reference parser. This likely prevents the tool-call parser from recognizing the DSML block.
Suggested fix:
The official parser/client should either:
- Normalize DSML token variants such as
<||DSML||...>back to<|DSML|...>, and tolerate compact markup without newlines. - Or ensure the model/API always emits the documented canonical DSML format before tool-call parsing.
This is how I handled it.
import json
import re
import sys
from pathlib import Path
sys.path.insert(0, str(Path("encoding").resolve()))
from encoding_dsv4 import eos_token, parse_message_from_completion_text
DSML_TOKEN = "|DSML|"
def normalize_dsml_token_variants(text: str) -> str:
"""Convert degraded DSML tokens like <||DSML||tag> to canonical DSML tokens."""
double_pipe = r"(?:\|\s*\|||\s*|)"
text = re.sub(
rf"<\s*(/?)\s*{double_pipe}\s*DSML\s*{double_pipe}\s*([A-Za-z_][\w]*)\s*>",
lambda match: f"<{match.group(1)}{DSML_TOKEN}{match.group(2)}>",
text,
)
text = re.sub(
rf"<\s*(/?)\s*{double_pipe}\s*DSML\s*{double_pipe}\s*([A-Za-z_][\w]*)\s+",
lambda match: f"<{match.group(1)}{DSML_TOKEN}{match.group(2)} ",
text,
)
return text
def normalize_dsml_message(text: str) -> str:
"""Normalize compact DSML tool calls into the strict parser format."""
text = normalize_dsml_token_variants(text)
tool_calls_start = f"<{DSML_TOKEN}tool_calls>"
tool_calls_end = f"</{DSML_TOKEN}tool_calls>"
start_index = text.find(tool_calls_start)
if start_index == -1:
return text if text.endswith(eos_token) else f"{text}{eos_token}"
end_index = text.find(tool_calls_end, start_index)
if end_index == -1:
raise ValueError("Missing DSML tool_calls closing tag")
end_index += len(tool_calls_end)
content = text[:start_index].rstrip()
tool_calls = text[start_index:end_index].strip()
tail = text[end_index:].strip()
if tail and tail != eos_token:
raise ValueError(f"Unexpected content after DSML tool calls: {tail}")
escaped_dsml_token = re.escape(DSML_TOKEN)
tool_calls = re.sub(rf"(<{escaped_dsml_token}tool_calls>)\s*", r"\1\n", tool_calls)
tool_calls = re.sub(rf">\s*<{escaped_dsml_token}invoke", f">\n<{DSML_TOKEN}invoke", tool_calls)
tool_calls = re.sub(rf">\s*<{escaped_dsml_token}parameter", f">\n<{DSML_TOKEN}parameter", tool_calls)
tool_calls = re.sub(
rf"</{escaped_dsml_token}parameter>\s*<{escaped_dsml_token}parameter",
f"</{DSML_TOKEN}parameter>\n<{DSML_TOKEN}parameter",
tool_calls,
)
tool_calls = re.sub(
rf"</{escaped_dsml_token}parameter>\s*</{escaped_dsml_token}invoke>",
f"</{DSML_TOKEN}parameter>\n</{DSML_TOKEN}invoke>",
tool_calls,
)
tool_calls = re.sub(
rf"</{escaped_dsml_token}invoke>\s*<{escaped_dsml_token}invoke",
f"</{DSML_TOKEN}invoke>\n<{DSML_TOKEN}invoke",
tool_calls,
)
tool_calls = re.sub(
rf"</{escaped_dsml_token}invoke>\s*</{escaped_dsml_token}tool_calls>",
f"</{DSML_TOKEN}invoke>\n</{DSML_TOKEN}tool_calls>",
tool_calls,
)
return f"{content}\n\n{tool_calls}{eos_token}"
def parse_deepseek_message(text: str) -> dict:
normalized_text = normalize_dsml_message(text)
return parse_message_from_completion_text(normalized_text, thinking_mode="chat")
if __name__ == "__main__":
completion = """我先并行搜索几个关键方向:SKILL文件、六扇门/七巧板相关需求文档、公司债券要素以及定期报告提醒相关内容。<||DSML||tool_calls><||DSML||invoke name="doc_knowlegebase"><||DSML||parameter name="query" string="true">七巧板 需求 债券 详情 字段 展示</||DSML||parameter></||DSML||invoke></||DSML||tool_calls>"""
parsed = parse_deepseek_message(completion)
tool_calls = parsed["tool_calls"]
print(json.dumps(tool_calls, ensure_ascii=False, indent=2))
args = json.loads(tool_calls[0]["function"]["arguments"])
print(args)