模型简介
模型特点
模型能力
使用案例
语言:
- 英语
- 法语
- 德语
- 西班牙语
- 葡萄牙语
- 意大利语
- 日语
- 韩语
- 俄语
- 中文
- 阿拉伯语
- 波斯语
- 印尼语
- 马来语
- 尼泊尔语
- 波兰语
- 罗马尼亚语
- 塞尔维亚语
- 瑞典语
- 土耳其语
- 乌克兰语
- 越南语
- 印地语
- 孟加拉语
许可证: Apache-2.0
库名称: vllm
推理: 不支持
基础模型:
- mistralai/Devstral-Small-2505
额外授权说明: >- 如需了解我们如何处理您的个人数据,请阅读我们的隐私政策。
任务标签: 文本生成
使用LLMCompressor量化至FP8
适合在双GPU系统(如2x3090)上通过vLLM或SGlang运行:
vllm serve bullerwins/Devstral-Small-2505-fp8 --max-model-len 16000 --host 0.0.0.0 --port 5000 -tp 2 --tokenizer_mode mistral
Devstral-Small-2505
Devstral是由Mistral AI与All Hands AI合作开发的面向软件工程任务的智能体大语言模型。Devstral擅长利用工具探索代码库、编辑多文件及驱动软件工程智能体。该模型在SWE-bench上表现卓越,成为该基准测试中排名第一的开源模型。
它基于Mistral-Small-3.1微调,因此拥有长达128k token的上下文窗口。作为编码智能体,Devstral仅支持文本输入,且在从Mistral-Small-3.1
微调前移除了视觉编码器。
对于需要特殊能力(如扩展上下文、领域特定知识等)的企业用户,我们将发布超越Mistral AI社区贡献的商业模型。
更多关于Devstral的信息,请阅读我们的博客文章。
核心特性:
- 智能编码: Devstral专为智能编码任务设计,是构建软件工程智能体的理想选择。
- 轻量化: 仅240亿参数的紧凑体积,可在单块RTX 4090或32GB内存的Mac上运行,适合本地部署和终端设备使用。
- Apache 2.0许可证: 允许商业和非商业用途的开放许可。
- 上下文窗口: 128k token的超长上下文。
- 分词器: 采用131k词汇量的Tekken分词器。
基准测试结果
SWE-Bench
Devstral在SWE-Bench Verified测试中获得46.8%的分数,较此前开源最佳模型提升6%。
模型 | 脚手架 | SWE-Bench Verified (%) |
---|---|---|
Devstral | OpenHands脚手架 | 46.8 |
GPT-4.1-mini | OpenAI脚手架 | 23.6 |
Claude 3.5 Haiku | Anthropic脚手架 | 40.6 |
SWE-smith-LM 32B | SWE-agent脚手架 | 40.2 |
在相同测试脚手架(由All Hands AI提供的OpenHands)下,Devstral表现远超Deepseek-V3-0324和Qwen3 232B-A22B等更大规模模型。
使用指南
推荐配合OpenHands脚手架使用Devstral。可通过API或本地运行两种方式。
API方式
按照指引创建Mistral账户并获取API密钥。
随后运行以下命令启动OpenHands容器:
export MISTRAL_API_KEY=<我的密钥>
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.39-nikolaik
mkdir -p ~/.openhands-state && echo '{"language":"en","agent":"CodeActAgent","max_iterations":null,"security_analyzer":null,"confirmation_mode":false,"llm_model":"mistral/devstral-small-2505","llm_api_key":"'$MISTRAL_API_KEY'","remote_runtime_resource_factor":null,"github_token":null,"enable_default_condenser":true}' > ~/.openhands-state/settings.json
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.39-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands-state:/.openhands-state \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.39
本地推理
可通过以下库部署模型:
vLLM(推荐)
: 参见此处mistral-inference
: 参见此处transformers
: 参见此处LMStudio
: 参见此处ollama
: 参见此处
OpenHands(推荐)
启动Devstral-Small-2505服务
确保已按上述方式启动vLLM或Ollama等兼容OpenAI的服务器。然后可通过OpenHands与Devstral-Small-2505
交互。
本教程示例使用vLLM服务器启动命令:
vllm serve mistralai/Devstral-Small-2505 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
服务器地址格式应为:http://<服务器地址>:8000/v1
启动OpenHands
安装指南参见此处。
最简单的启动方式是使用Docker镜像:
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands-state:/.openhands-state \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.38
随后可通过http://localhost:3000
访问OpenHands界面。
连接服务器
在OpenHands界面中,系统将提示连接服务器。可通过高级模式连接先前启动的服务器。
填写以下字段:
- 自定义模型:
openai/mistralai/Devstral-Small-2505
- 基础URL:
http://<服务器地址>:8000/v1
- API密钥:
token
(或启动服务器时使用的任意令牌)
使用Devstral驱动的OpenHands
现在即可在OpenHands中开启新对话使用Devstral Small。让我们构建一个待办事项应用。
待办事项应用
- 通过以下提示要求Devstral生成应用:
构建满足以下要求的待办事项应用:
- 使用FastAPI和React构建
- 单页应用功能包括:
- 添加任务
- 删除任务
- 标记任务完成
- 显示任务列表
- 使用SQLite数据库存储任务
- 查看结果
您将看到智能体构建应用的过程,并可浏览生成的代码。
如未自动部署,可要求Devstral部署或手动操作,然后访问前端URL查看应用。
- 迭代优化
获得初步结果后,可要求智能体改进。例如在当前应用中点击任务可标记完成,但添加复选框能提升用户体验。还可要求添加编辑任务或按状态筛选任务的功能。
尽情使用Devstral Small和OpenHands进行开发吧!
vLLM(推荐)
建议使用vLLM库实现生产级推理流程。
安装
确保安装vLLM >= 0.8.5
:
pip install vllm --upgrade
这将自动安装mistral_common >= 1.5.5
。
验证:
python -c "import mistral_common; print(mistral_common.__version__)"
也可使用现成的docker镜像或docker hub。
服务端
建议在服务端/客户端环境中使用Devstral。
- 启动服务:
vllm serve mistralai/Devstral-Small-2505 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
- 客户端调用示例:
import requests
import json
from huggingface_hub import hf_hub_download
url = "http://<服务器地址>:8000/v1/chat/completions"
headers = {"Content-Type": "application/json", "Authorization": "Bearer token"}
model = "mistralai/Devstral-Small-2505"
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": "<您的指令>",
},
],
},
]
data = {"model": model, "messages": messages, "temperature": 0.15}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json()["choices"][0]["message"]["content"])
Mistral推理
推荐使用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-2505", allow_patterns=["params.json", "consolidated.safetensors", "tekken.json"], local_dir=mistral_models_path)
Python
运行命令:
mistral-chat $HOME/mistral_models/Devstral --instruct --max_tokens 300
随后可输入任意提示。
Transformers
为充分发挥模型性能,请确保安装mistral-common >= 1.5.5
以使用我们的分词器。
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 mistral_common.tokens.tokenizers.tekken import SpecialTokenPolicy
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-2505"
tekken_file = hf_hub_download(repo_id=model_id, filename="tekken.json")
SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
tokenizer = MistralTokenizer.from_file(tekken_file)
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenized = tokenizer.encode_chat_completion(
ChatCompletionRequest(
messages=[
SystemMessage(content=SYSTEM_PROMPT),
UserMessage(content="<您的指令>"),
],
)
)
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)
LMStudio
从HuggingFace下载权重:
pip install -U "huggingface_hub[cli]"
huggingface-cli download \
"mistralai/Devstral-Small-2505_gguf" \
--include "devstralQ4_K_M.gguf" \
--local-dir "mistralai/Devstral-Small-2505_gguf/"
可通过LMStudio本地运行模型:
- 下载并安装LM Studio
- 安装CLI工具:
~/.lmstudio/bin/lms bootstrap
- 在模型检查点目录(如
mistralai/Devstral-Small-2505_gguf
)中运行:lms import devstralQ4_K_M.gguf
- 打开LMStudio应用,点击终端图标进入开发者标签页。选择加载模型并选择Devstral Q4 K M。切换状态按钮启动模型,在设置中开启"本地网络服务"。
- 右侧标签页将显示API标识符(应为devstralq4_k_m)和API地址。记下该地址供后续使用。
启动Openhands
现在可通过openhands与LM Studio服务的模型交互。使用docker启动openhands服务器:
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands-state:/.openhands-state \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.38
点击第二行的"查看高级设置"。
在新标签页中开启高级选项。将自定义模型设为mistral/devstralq4_k_m,基础URL设为LM Studio中获取的API地址。API密钥设为dummy。点击保存更改。
Ollama
可通过Ollama CLI运行Devstral:
ollama run devstral


