Mistral Small 4 是一款功能强大的混合模型,既能作为通用指令模型,也能作为推理模型。它将 Instruct、Reasoning(前称 Magistral)和 Devstral 这三个不同模型家族的能力整合到了一个统一的模型中。
凭借其多模态能力、高效的架构和灵活的模式切换,它成为适用于任何任务的强大通用模型。在延迟优化配置下,Mistral Small 4 的端到端完成时间缩短了 40%;在吞吐量优化配置下,与 Mistral Small 3 相比,其每秒处理的请求量提升了 3 倍。
[!Tip] 此检查点是 mistralai/Mistral-Small-4-119B-2603 的训练后激活量化版本。 它是通过 llm-compressor 创建的,是与 vLLM 和 Red Hat 团队合作的成果。 特别感谢 Dipika Sikka。 我们还要感谢 NVIDIA 在 SGLang 和 vLLM 方面提供的专业知识和贡献,以确保内核优化。
Mistral Small 4 包含以下架构选择:
Mistral Small 4 具备以下能力:
'none' → 不使用推理'high' → 使用推理(复杂提示推荐)
复杂任务请使用 reasoning_effort="high"reasoning_effort="high" 时建议设为 0.7。reasoning_effort="none" 时,温度值根据任务在 0.0 到 0.7 之间调整。Mistral Small 4 适用于通用聊天助手、编码、智能体任务以及推理任务(需开启推理模式)。其多模态能力还支持文档和图像理解,可用于数据提取与分析。
其能力特别适合以下场景:
Mistral Small 4 也非常适合通过定制和微调来适应更专业的任务。
您可以在多个推理库中找到对 Mistral Small 4 的支持:
我们建议将 Mistral Small 4 与 vLLM 库 结合使用,以实现生产级推理。
[!提示] 使用我们的自定义 Docker 镜像,该镜像包含 vLLM 中工具调用和推理解析的修复,以及最新版本的 Transformers。我们正与 vLLM 团队合作,尽快合并这些修复。
自定义 Docker
使用以下 Docker 镜像:mistralllm/vllm-ms4:latest:
docker pull mistralllm/vllm-ms4:latest
docker run -it mistralllm/vllm-ms4:latest手动安装
或者,从以下 PR 安装 vllm:Add Mistral Guidance。
注意:此 PR 预计将在未来 1-2 周内合并到
vllm主分支(截至 2026 年 3 月 16 日)。可通过 此处 跟踪更新。
git clone --branch fix_mistral_parsing https://github.com/juliendenize/vllm.gitVLLM_USE_PRECOMPILED=1 pip install --editable .transformers:
uv pip install git+https://github.com/huggingface/transformers.gitmistral_common >= 1.10.0:
python -c "import mistral_common; print(mistral_common.__version__)"我们建议采用服务器/客户端架构:
vllm serve mistralai/Mistral-Small-4-119B-2603-NVFP4 --max-model-len 262144 --tensor-parallel-size 2 --attention-backend TRITON_MLA \
--tool-call-parser mistral --enable-auto-tool-choice --reasoning-parser mistral --max_num_batched_tokens 16384 --max_num_seqs 128 \
--gpu_memory_utilization 0.8Mistral Small 4 能够严格按照您的指令执行。
from datetime import datetime, timedelta
from openai import OpenAI
from huggingface_hub import hf_hub_download
# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
TEMP = 0.1
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
models = client.models.list()
model = models.data[0].id
def load_system_prompt(repo_id: str, filename: str) -> str:
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
with open(file_path, "r") as file:
system_prompt = file.read()
today = datetime.today().strftime("%Y-%m-%d")
yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
model_name = repo_id.split("/")[-1]
return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{
"role": "user",
"content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
},
]
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=TEMP,
reasoning_effort="none",
)
assistant_message = response.choices[0].message.content
print(assistant_message)借助我们简单的 Python 计算器工具来解一些方程吧。
import json
from datetime import datetime, timedelta
from openai import OpenAI
from huggingface_hub import hf_hub_download
# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
TEMP = 0.1
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
models = client.models.list()
model = models.data[0].id
def load_system_prompt(repo_id: str, filename: str) -> str:
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
with open(file_path, "r") as file:
system_prompt = file.read()
today = datetime.today().strftime("%Y-%m-%d")
yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
model_name = repo_id.split("/")[-1]
return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
def my_calculator(expression: str) -> str:
return str(eval(expression))
tools = [
{
"type": "function",
"function": {
"name": "my_calculator",
"description": "A calculator that can evaluate a mathematical expression.",
"parameters": {
"type": "object",
"properties": {
"expression": {
"type": "string",
"description": "The mathematical expression to evaluate.",
},
},
"required": ["expression"],
},
},
},
{
"type": "function",
"function": {
"name": "rewrite",
"description": "Rewrite a given text for improved clarity",
"parameters": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "The input text to rewrite",
}
},
},
},
},
]
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Thanks to your calculator, compute the results for the equations that involve numbers displayed in the image.",
},
{
"type": "image_url",
"image_url": {
"url": image_url,
},
},
],
},
]
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=TEMP,
tools=tools,
tool_choice="auto",
reasoning_effort="none",
)
tool_calls = response.choices[0].message.tool_calls
results = []
for tool_call in tool_calls:
function_name = tool_call.function.name
function_args = tool_call.function.arguments
if function_name == "my_calculator":
result = my_calculator(**json.loads(function_args))
results.append(result)
messages.append({"role": "assistant", "tool_calls": tool_calls})
for tool_call, result in zip(tool_calls, results):
messages.append(
{
"role": "tool",
"tool_call_id": tool_call.id,
"name": tool_call.function.name,
"content": result,
}
)
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=TEMP,
reasoning_effort="none",
)
print(response.choices[0].message.content)我们来看看 Mistral Small 4 是否知道何时选择对抗!
from datetime import datetime, timedelta
from openai import OpenAI
from huggingface_hub import hf_hub_download
# Modify OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
TEMP = 0.7
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
models = client.models.list()
model = models.data[0].id
def load_system_prompt(repo_id: str, filename: str) -> str:
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
with open(file_path, "r") as file:
system_prompt = file.read()
today = datetime.today().strftime("%Y-%m-%d")
yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
model_name = repo_id.split("/")[-1]
return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What action do you think I should take in this situation? List all the possible actions and explain why you think they are good or bad.",
},
{"type": "image_url", "image_url": {"url": image_url}},
],
},
]
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=TEMP,
reasoning_effort="high",
)
print(response.choices[0].message.content)本模型根据 Apache 2.0 许可协议 进行许可。
您不得将本模型用于侵犯、盗用或违反任何第三方权利(包括知识产权)的行为。