HuggingFace镜像/Mistral-Small-4-119B-2603-eagle
模型介绍文件和版本分析
下载使用量0

Mistral Small 4 119B A6B Eagle

Mistral Small 4 是一款功能强大的混合模型,既能作为通用指令模型,也能作为推理模型。它将 Instruct、Reasoning(前称 Magistral)和 Devstral 这三个不同模型系列的能力整合到了一个统一的模型中。

凭借其多模态能力、高效架构和灵活的模式切换,它成为适用于任何任务的强大通用模型。在延迟优化配置下,Mistral Small 4 的端到端完成时间减少了 40%;在吞吐量优化配置下,与 Mistral Small 3 相比,它每秒能处理 3 倍以上的请求。

主要特性

Mistral Small 4 在架构上做出了以下选择:

  • MoE(混合专家模型):128 个专家,4 个激活。
  • 1190 亿参数,每个 token 激活 65 亿参数。
  • 256k 上下文长度。
  • 多模态输入:接受文本和图像输入,输出文本。
  • 指令和推理功能,支持函数调用(可按请求配置推理力度)。

Mistral Small 4 具备以下能力:

  • 推理模式:可在快速即时回复模式和推理模式之间切换,根据请求通过测试时计算提升性能。
  • 视觉:除文本外,还能分析图像并基于视觉内容提供见解。
  • 多语言:支持数十种语言,包括英语、法语、西班牙语、德语、意大利语、葡萄牙语、荷兰语、中文、日语、韩语和阿拉伯语。
  • 系统提示:高度遵循并支持系统提示。
  • 智能体:具备一流的智能体能力,支持原生函数调用和 JSON 输出。
  • 速度优化:提供一流的性能和速度。
  • Apache 2.0 许可证:开源许可证,允许商业和非商业使用。
  • 大上下文窗口:支持 256k 上下文窗口。

应用场景

Mistral Small 4 设计用于通用聊天助手、编码、智能体任务以及推理任务(需开启推理模式)。其多模态能力还支持文档和图像理解,以进行数据提取和分析。

其能力特别适合:

  • 对编码和智能体能力感兴趣的开发人员,用于软件工程自动化和代码库探索。
  • 寻求通用聊天助手、智能体和文档理解解决方案的企业。
  • 利用其数学和研究能力的研究人员。

Mistral Small 4 也非常适合进行定制和微调,以适应更专业的任务。

推荐设置

  • 推理力度:
    • 'none' → 不使用推理
    • 'high' → 使用推理(推荐用于复杂提示词) 对于复杂任务,请使用 reasoning_effort="high"
  • 温度参数:当 reasoning_effort="high" 时,建议设为 0.7。当 reasoning_effort="none" 时,根据具体任务,温度参数可在 0.0 到 0.7 之间调整。

应用示例

  • 通用聊天助手
  • 文档解析与提取
  • 编码代理
  • 研究助手
  • 定制化与微调
  • 以及更多……

使用方法(vLLM)

我们建议将 Mistral Small 4 Eagle 与 vLLM 库 配合使用,以实现生产级别的推理。

安装步骤

  1. 安装 vLLM nightly 版本
    uv pip install -U vllm \
     --torch-backend=auto \
     --extra-index-url https://wheels.vllm.ai/nightly
  2. 从主分支安装 transformers:
    uv pip install git+https://github.com/huggingface/transformers.git

确保已安装 mistral_common >= 1.10.0:

python -c "import mistral_common; print(mistral_common.__version__)"

模型部署建议

我们建议采用服务器/客户端架构:

vllm serve mistralai/Mistral-Small-4-119B-2603 --max-model-len 262144 --tensor-parallel-size 2 --attention-backend FLASH_ATTN_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 --speculative_config '{
    "model": "mistralai/Mistral-Small-4-119B-2603-eagle",
    "num_speculative_tokens": 3,
    "method": "eagle",
    "max_model_len": "16384"
  }'

测试服务器连接

指令遵循

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 许可协议 授权。

您不得将本模型用于侵犯、盗用或违反任何第三方权利(包括知识产权)的行为。