可用于构建聊天助手、编码代理、文档理解等应用,是统一Instruct、Reasoning、Devstral能力的混合模型,支持256k上下文、多语言及函数调用,经NVFP4量化优化性能。【此简介由AI生成】
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
tekken.jsonLFS | 2 个月前 | |
| 2 个月前 | ||
| 2 个月前 |
license: apache-2.0 language:
- en
- fr
- de
- es
- pt
- it
- ja
- ko
- ru
- zh
- ar
- fa
- id
- ms
- ne
- pl
- ro
- sr
- sv
- tr
- uk
- vi
- hi
- bn tags:
- vLLM
- compressed-tensors base_model:
- mistralai/Mistral-Small-4-119B-2603
Mistral Small 4 119B A6B NVFP4
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 包含以下架构选择:
- MoE:128 个专家,4 个激活。
- 1190 亿参数,每个 token 激活65 亿参数。
- 256k 上下文长度。
- 多模态输入:接受文本和图像输入,输出文本。
- 指令和推理功能,支持函数调用(可按请求配置推理力度)。
Mistral Small 4 具备以下能力:
- 推理模式:可在快速即时回复模式和推理模式之间切换,根据请求在测试时通过计算提升性能。
- 视觉:除文本外,还能分析图像并基于视觉内容提供见解。
- 多语言:支持数十种语言,包括英语、法语、西班牙语、德语、意大利语、葡萄牙语、荷兰语、中文、日语、韩语和阿拉伯语。
- 系统提示:高度遵循并支持系统提示。
- 智能体:具备一流的智能体能力,支持原生函数调用和 JSON 输出。
- 速度优化:提供一流的性能和速度。
- Apache 2.0 许可证:开源许可证,允许商业和非商业使用。
- 大上下文窗口:支持 256k 上下文窗口。
推荐设置
- 推理力度:
'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 的支持:
vLLM(推荐)
我们建议将 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 日)。可通过 此处 跟踪更新。
- 克隆 vLLM:
git clone --branch fix_mistral_parsing https://github.com/juliendenize/vllm.git - 使用预编译内核安装:
VLLM_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.8
服务器 ping 测试
指令遵循能力
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.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 许可协议 进行许可。
您不得将本模型用于侵犯、盗用或违反任何第三方权利(包括知识产权)的行为。