说明文档
Devstral Small 1.1
Devstral 是一个面向软件工程任务的智能体大语言模型,由 Mistral AI 和 All Hands AI 联合构建 🙌。Devstral 擅长使用工具探索代码库、编辑多个文件,并为软件工程智能体提供强大支持。该模型在 SWE-bench 上取得了卓越的性能,成为该基准测试中排名第一的开源模型。
它基于 Mistral-Small-3.1 进行微调,因此具有长达 128k token 的上下文窗口。作为代码智能体,Devstral 仅支持文本,在从 Mistral-Small-3.1 微调之前,视觉编码器已被移除。
对于需要专业化能力(增加上下文、特定领域知识等)的企业,我们将发布超越 Mistral AI 对社区贡献的商业模型。
在我们的博客文章中了解更多关于 Devstral 的信息。
与 Devstral Small 1.0 相比的更新:
- 性能提升,请参阅基准测试结果。
Devstral Small 1.1与 OpenHands 搭配使用依然出色。这个新版本对其他提示词和编码环境的泛化能力更强。- 支持 Mistral 的函数调用格式。
主要特性:
- 智能体编码:Devstral 专为擅长智能体编码任务而设计,是软件工程智能体的绝佳选择。
- 轻量级:仅有 240 亿参数的紧凑尺寸,Devstral 足够轻量,可在单张 RTX 4090 或 32GB 内存的 Mac 上运行,非常适合本地部署和设备端使用。
- Apache 2.0 许可证:开放许可证,允许商业和非商业用途的使用和修改。
- 上下文窗口:128k 上下文窗口。
- 分词器:采用 Tekken 分词器,词汇表大小为 131k。
基准测试结果
SWE-Bench
Devstral Small 1.1 在 SWE-Bench Verified 上取得了 53.6% 的得分,比 Devstral Small 1.0 高出 +6.8%,比第二名最先进模型高出 +11.4%。
| 模型 | 智能体脚手架 | SWE-Bench Verified (%) |
|---|---|---|
| Devstral Small 1.1 | OpenHands Scaffold | 53.6 |
| Devstral Small 1.0 | OpenHands Scaffold | 46.8 |
| GPT-4.1-mini | OpenAI Scaffold | 23.6 |
| Claude 3.5 Haiku | Anthropic Scaffold | 40.6 |
| SWE-smith-LM 32B | SWE-agent Scaffold | 40.2 |
| Skywork SWE | OpenHands Scaffold | 38.0 |
| DeepSWE | R2E-Gym Scaffold | 42.2 |
当在相同的测试脚手架(由 All Hands AI 提供的 OpenHands 🙌)下评估时,Devstral 超越了远大于它的模型,如 Deepseek-V3-0324 和 Qwen3 232B-A22B。

使用方法
我们推荐将 Devstral 与 OpenHands 脚手架一起使用。 您可以通过我们的 API 或本地运行来使用它。
API
按照这些说明创建 Mistral 账户并获取 API 密钥。
然后运行以下命令启动 OpenHands docker 容器。
export MISTRAL_API_KEY=<MY_KEY>
mkdir -p ~/.openhands && echo '{\"language\":\"en\",\"agent\":\"CodeActAgent\",\"max_iterations\":null,\"security_analyzer\":null,\"confirmation_mode\":false,\"llm_model\":\"mistral/devstral-small-2507\",\"llm_api_key\":\"'$MISTRAL_API_KEY'\",\"remote_runtime_resource_factor\":null,\"github_token\":null,\"enable_default_condenser\":true}' > ~/.openhands-state/settings.json
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.48-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.48-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands:/.openhands \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.48
本地推理
该模型也可以使用以下库进行部署:
vllm (推荐):请参阅这里mistral-inference:请参阅这里transformers:请参阅这里LMStudio:请参阅这里llama.cpp:请参阅这里ollama:请参阅这里
vLLM(推荐)
<details> <summary>展开</summary>
我们推荐使用 vLLM 库 来运行此模型,以实现生产就绪的推理流水线。
安装
确保安装 vLLM >= 0.9.1:
pip install vllm --upgrade
同时确保已安装 mistral_common >= 1.7.0。
pip install mistral-common --upgrade
检查版本:
python -c \"import mistral_common; print(mistral_common.__version__)\"
您也可以使用现成的 docker 镜像或 docker hub。
启动服务器
我们建议在服务器/客户端设置中使用 Devstral。
- 启动服务器:
vllm serve mistralai/Devstral-Small-2507 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
- 要测试客户端,您可以使用一个简单的 Python 代码片段。
import requests
import json
from huggingface_hub import hf_hub_download
url = \"http://<your-server-url>:8000/v1/chat/completions\"
headers = {\"Content-Type\": \"application/json\", \"Authorization\": \"Bearer token\"}
model = \"mistralai/Devstral-Small-2507\"
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()
return system_prompt
SYSTEM_PROMPT = load_system_prompt(model, \"SYSTEM_PROMPT.txt\")
messages = [
{\"role\": \"system\", \"content\": SYSTEM_PROMPT},
{
\"role\": \"user\",
\"content\": [
{
\"type\": \"text\",
\"text\": \"<your-command>\",
},
],
},
]
data = {\"model\": model, \"messages\": messages, \"temperature\": 0.15}
# Devstral Small 1.1 支持工具调用。如果您想使用工具,请按以下方式操作:
# tools = [ # 为 vLLM 定义工具
# {
# \"type\": \"function\",
# \"function\": {
# \"name\": \"git_clone\",
# \"description\": \"克隆 git 仓库\",
# \"parameters\": {
# \"type\": \"object\",
# \"properties\": {
# \"url\": {
# \"type\": \"string\",
# \"description\": \"git 仓库的 url\",
# },
# },
# \"required\": [\"url\"],
# },
# },
# }
# ]
# data = {\"model\": model, \"messages\": messages, \"temperature\": 0.15, \"tools\": tools} # 将工具传递给请求体。
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json()[\"choices\"][0][\"message\"][\"content\"])
</details>
Mistral-inference
<details> <summary>展开</summary>
我们推荐使用 mistral-inference 来快速试用/体验 Devstral。
安装
确保已安装 mistral_inference >= 1.6.0。
pip install mistral_inference --upgrade
下载
from huggingface_hub import snapshot_download
from pathlib import Path
mistral_models_path = Path.home().joinpath('mistral_models', 'Devstral')
mistral_models_path.mkdir(parents=True, exist_ok=True)
snapshot_download(repo_id=\"mistralai/Devstral-Small-2507\", allow_patterns=[\"params.json\", \"consolidated.safetensors\", \"tekken.json\"], local_dir=mistral_models_path)
聊天
您可以使用以下命令运行模型:
mistral-chat $HOME/mistral_models/Devstral --instruct --max_tokens 300
然后您可以用任何内容进行提示。
</details>
Transformers
<details> <summary>展开</summary>
要充分利用我们的模型与 transformers,请确保已安装 mistral-common >= 1.7.0 以使用我们的分词器。
pip install mistral-common --upgrade
然后加载我们的分词器和模型并生成:
import torch
from mistral_common.protocol.instruct.messages import (
SystemMessage, UserMessage
)
from mistral_common.protocol.instruct.request import ChatCompletionRequest
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM
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()
return system_prompt
model_id = \"mistralai/Devstral-Small-2507\"
SYSTEM_PROMPT = load_system_prompt(model_id, \"SYSTEM_PROMPT.txt\")
tokenizer = MistralTokenizer.from_hf_hub(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenized = tokenizer.encode_chat_completion(
ChatCompletionRequest(
messages=[
SystemMessage(content=SYSTEM_PROMPT),
UserMessage(content=\"<your-command>\"),
],
)
)
output = model.generate(
input_ids=torch.tensor([tokenized.tokens]),
max_new_tokens=1000,
)[0]
decoded_output = tokenizer.decode(output[len(tokenized.tokens):])
print(decoded_output)
</details>
LM Studio
<details> <summary>展开</summary>
从以下位置下载权重:
- LM Studio GGUF 仓库(推荐):https://huggingface.co/lmstudio-community/Devstral-Small-2507-GGUF
- 我们的 GGUF 仓库:https://huggingface.co/mistralai/Devstral-Small-2507_gguf
pip install -U \"huggingface_hub[cli]\"
huggingface-cli download \
\"lmstudio-community/Devstral-Small-2507-GGUF\" \ # 或 mistralai/Devstral-Small-2507_gguf
--include \"Devstral-Small-2507-Q4_K_M.gguf\" \
--local-dir \"Devstral-Small-2507_gguf/\"
您可以使用 LMStudio 在本地服务该模型。
- 下载 LM Studio 并安装
- 安装
lms cli ~/.lmstudio/bin/lms bootstrap - 在 bash 终端中,在您下载模型检查点的目录(例如
Devstral-Small-2507_gguf)中运行lms import Devstral-Small-2507-Q4_K_M.gguf - 打开 LM Studio 应用程序,点击终端图标进入开发者标签页。点击选择要加载的模型并选择
Devstral Small 2507。切换状态按钮以启动模型,在设置中切换 Serve on Local Network 为开启。 - 在右侧标签页中,您将看到一个 API 标识符,应该是
devstral-small-2507,以及 API Usage 下的 api 地址。记下这个地址,这将用于 OpenHands 或 Cline。
</details>
llama.cpp
<details> <summary>展开</summary>
从 huggingface 下载权重:
pip install -U \"huggingface_hub[cli]\"
huggingface-cli download \
\"mistralai/Devstral-Small-2507_gguf\" \
--include \"Devstral-Small-2507-Q4_K_M.gguf\" \
--local-dir \"mistralai/Devstral-Small-2507_gguf/\"
然后使用 llama.cpp 服务器运行 Devstral。
./llama-server -m mistralai/Devstral-Small-2507_gguf/Devstral-Small-2507-Q4_K_M.gguf -c 0 # -c 配置上下文大小,0 表示模型默认值,这里是 128k。
</details>
OpenHands(推荐)
启动服务器部署 Devstral Small 1.1
确保您已启动如上所述的 OpenAI 兼容服务器(如 vLLM 或 Ollama)。然后,您可以使用 OpenHands 与 Devstral Small 1.1 进行交互。
在本教程中,我们启动了一个 vLLM 服务器,运行以下命令:
vllm serve mistralai/Devstral-Small-2507 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
服务器地址应采用以下格式:http://<your-server-url>:8000/v1
启动 OpenHands
您可以按照这里的说明安装 OpenHands。
启动 OpenHands 最简单的方法是使用 Docker 镜像:
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.48-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.48-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands:/.openhands \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.48
然后,您可以在 http://localhost:3000 访问 OpenHands UI。
连接到服务器
访问 OpenHands UI 时,系统会提示您连接到服务器。您可以使用高级模式连接到您之前启动的服务器。
填写以下字段:
- Custom Model:
openai/mistralai/Devstral-Small-2507 - Base URL:
http://<your-server-url>:8000/v1 - API Key:
token(或您启动服务器时使用的任何其他令牌,如果有的话)
<details> <summary>查看设置</summary>

</details>
Cline
启动服务器部署 Devstral Small 1.1
确保您已启动如上所述的 OpenAI 兼容服务器(如 vLLM 或 Ollama)。然后,您可以使用 OpenHands 与 Devstral Small 1.1 进行交互。
在本教程中,我们启动了一个 vLLM 服务器,运行以下命令:
vllm serve mistralai/Devstral-Small-2507 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
服务器地址应采用以下格式:http://<your-server-url>:8000/v1
启动 Cline
您可以按照这里的说明安装 Cline。然后您可以在设置中配置服务器地址。
<details> <summary>查看设置</summary>

</details>
示例
OpenHands:理解 Mistral Common 的测试覆盖率
我们可以启动 OpenHands 脚手架并将其链接到仓库,以分析测试覆盖率并识别覆盖不足的文件。
这里我们从公开的 mistral-common 仓库开始。
在仓库挂载到工作区后,我们给出以下指令
Check the test coverage of the repo and then create a visualization of test coverage. Try plotting a few different types of graphs and save them to a png.
智能体将首先浏览代码库以检查测试配置和结构。

然后它设置测试依赖项并启动覆盖率测试:

最后,智能体编写必要的代码来可视化覆盖率,导出结果并将图表保存为 png。

在运行结束时,生成了以下图表:

模型能够解释结果:

Cline:构建视频游戏
首先在 VSCode 中初始化 Cline 并将其连接到您之前启动的服务器。
我们给出以下指令来构建视频游戏:
Create a video game that mixes Space Invaders and Pong for the web.
Follow these instructions:
- There are two players one at the top and one at the bottom. The players are controling a bar to bounce a ball.
- The first player plays with the keys \"a\" and \"d\", the second with the right and left arrows.
- The invaders are located at the center of the screen. They shoud look like the ones in Space Invaders. Their goal is to shoot on the players randomly. They cannot be destroyed by the ball that pass through them. This means that invaders never die.
- The players goal is to avoid shootings from the space invaders and send the ball to the edge of the over player.
- The ball bounces on the left and right edges.
- Once the ball touch one of the player's edge, the player loses.
- Once a player is touched 3 times or more by a shooting, the player loses.
- The player winning is the last one standing.
- Display on the UI, the number of times a player touched the ball, and the remaining health.

智能体将首先创建游戏:

然后它会解释如何启动游戏:

最后,游戏已准备好可以玩了:

请随意迭代或向 Devstral 提供更多信息以改进游戏!
Prince-1/Devstral-Small-2507
作者 Prince-1
创建时间: 2025-07-23 06:34:31+00:00
更新时间: 2025-07-23 07:33:07+00:00
在 Hugging Face 上查看