nm-testing/Devstral-Small-2505-FP8-dynamic
112
1---2language:3- en4- fr5- de6- es7- pt8- it9- ja10- ko11- ru12- zh13- ar14- fa15- id16- ms17- ne18- pl19- ro20- sr21- sv22- tr23- uk24- vi25- hi26- bn27license: apache-2.028library_name: vllm29inference: false30base_model:31- mistralai/Devstral-Small-250532extra_gated_description: >-33 If you want to learn more about how we process your personal data, please read34 our <a href="https://mistral.ai/terms/">Privacy Policy</a>.35pipeline_tag: text2text-generation36---37 38Quantized to FP8-Dynamic with [LLMCompressor](https://github.com/vllm-project/llm-compressor) 39 40`vllm serve nm-testing/Devstral-Small-2505-FP8-dynamic --tokenizer_mode mistral`41 42 43# Devstral-Small-250544 45Devstral is an agentic LLM for software engineering tasks built under a collaboration between [Mistral AI](https://mistral.ai/) and [All Hands AI](https://www.all-hands.dev/) 🙌. Devstral excels at using tools to explore codebases, editing multiple files and power software engineering agents. The model achieves remarkable performance on SWE-bench which positionates it as the #1 open source model on this [benchmark](#benchmark-results). 46 47It is finetuned from [Mistral-Small-3.1](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503), therefore it has a long context window of up to 128k tokens. As a coding agent, Devstral is text-only and before fine-tuning from `Mistral-Small-3.1` the vision encoder was removed.48 49For enterprises requiring specialized capabilities (increased context, domain-specific knowledge, etc.), we will release commercial models beyond what Mistral AI contributes to the community.50 51Learn more about Devstral in our [blog post](https://mistral.ai/news/devstral).52 53 54## Key Features:55- **Agentic coding**: Devstral is designed to excel at agentic coding tasks, making it a great choice for software engineering agents.56- **lightweight**: with its compact size of just 24 billion parameters, Devstral is light enough to run on a single RTX 4090 or a Mac with 32GB RAM, making it an appropriate model for local deployment and on-device use.57- **Apache 2.0 License**: Open license allowing usage and modification for both commercial and non-commercial purposes.58- **Context Window**: A 128k context window.59- **Tokenizer**: Utilizes a Tekken tokenizer with a 131k vocabulary size.60 61 62 63## Benchmark Results64 65### SWE-Bench66 67Devstral achieves a score of 46.8% on SWE-Bench Verified, outperforming prior open-source SoTA by 6%.68 69| Model | Scaffold | SWE-Bench Verified (%) |70|------------------|--------------------|------------------------|71| Devstral | OpenHands Scaffold | **46.8** |72| GPT-4.1-mini | OpenAI Scaffold | 23.6 |73| Claude 3.5 Haiku | Anthropic Scaffold | 40.6 |74| SWE-smith-LM 32B | SWE-agent Scaffold | 40.2 |75 76 77 When evaluated under the same test scaffold (OpenHands, provided by All Hands AI 🙌), Devstral exceeds far larger models such as Deepseek-V3-0324 and Qwen3 232B-A22B.78 7980 81## Usage82 83We recommend to use Devstral with the [OpenHands](https://github.com/All-Hands-AI/OpenHands/tree/main) scaffold.84You can use it either through our API or by running locally. 85 86### API 87Follow these [instructions](https://docs.mistral.ai/getting-started/quickstart/#account-setup) to create a Mistral account and get an API key.88 89Then run these commands to start the OpenHands docker container.90```bash91export MISTRAL_API_KEY=<MY_KEY>92 93docker pull docker.all-hands.dev/all-hands-ai/runtime:0.39-nikolaik94 95mkdir -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.json96 97docker run -it --rm --pull=always \98 -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.39-nikolaik \99 -e LOG_ALL_EVENTS=true \100 -v /var/run/docker.sock:/var/run/docker.sock \101 -v ~/.openhands-state:/.openhands-state \102 -p 3000:3000 \103 --add-host host.docker.internal:host-gateway \104 --name openhands-app \105 docker.all-hands.dev/all-hands-ai/openhands:0.39106```107 108### Local inference 109 110The model can also be deployed with the following libraries:111- [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)112- [`mistral-inference`](https://github.com/mistralai/mistral-inference): See [here](#mistral-inference)113- [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)114- [`LMStudio`](https://lmstudio.ai/): See [here](#lmstudio)115- [`ollama`](https://github.com/ollama/ollama): See [here](#ollama)116 117 118### OpenHands (recommended)119 120#### Launch a server to deploy Devstral-Small-2505121 122Make sure you launched an OpenAI-compatible server such as vLLM or Ollama as described above. Then, you can use OpenHands to interact with `Devstral-Small-2505`.123 124In the case of the tutorial we spineed up a vLLM server running the command:125```bash126vllm 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 2127```128 129The server address should be in the following format: `http://<your-server-url>:8000/v1`130 131#### Launch OpenHands132 133You can follow installation of OpenHands [here](https://docs.all-hands.dev/modules/usage/installation).134 135The easiest way to launch OpenHands is to use the Docker image:136```bash137docker pull docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik138 139docker run -it --rm --pull=always \140 -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik \141 -e LOG_ALL_EVENTS=true \142 -v /var/run/docker.sock:/var/run/docker.sock \143 -v ~/.openhands-state:/.openhands-state \144 -p 3000:3000 \145 --add-host host.docker.internal:host-gateway \146 --name openhands-app \147 docker.all-hands.dev/all-hands-ai/openhands:0.38148```149 150 151Then, you can access the OpenHands UI at `http://localhost:3000`.152 153#### Connect to the server154 155When accessing the OpenHands UI, you will be prompted to connect to a server. You can use the advanced mode to connect to the server you launched earlier.156 157Fill the following fields:158- **Custom Model**: `openai/mistralai/Devstral-Small-2505`159- **Base URL**: `http://<your-server-url>:8000/v1`160- **API Key**: `token` (or any other token you used to launch the server if any)161 162#### Use OpenHands powered by Devstral163 164Now you're good to use Devstral Small inside OpenHands by **starting a new conversation**. Let's build a To-Do list app.165 166<details>167 <summary>To-Do list app</summary168 1691. Let's ask Devstral to generate the app with the following prompt:170 171```txt172Build a To-Do list app with the following requirements:173- Built using FastAPI and React.174- Make it a one page app that:175 - Allows to add a task.176 - Allows to delete a task.177 - Allows to mark a task as done.178 - Displays the list of tasks.179- Store the tasks in a SQLite database.180```181 182183 184 1852. Let's see the result186 187You should see the agent construct the app and be able to explore the code it generated.188 189If it doesn't do it automatically, ask Devstral to deploy the app or do it manually, and then go the front URL deployment to see the app.190 191192193 194 1953. Iterate196 197Now that you have a first result you can iterate on it by asking your agent to improve it. For example, in the app generated we could click on a task to mark it checked but having a checkbox would improve UX. You could also ask it to add a feature to edit a task, or to add a feature to filter the tasks by status.198 199Enjoy building with Devstral Small and OpenHands!200 201</details>202 203 204### vLLM (recommended)205 206We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)207to implement production-ready inference pipelines.208 209**_Installation_**210 211Make sure you install [`vLLM >= 0.8.5`](https://github.com/vllm-project/vllm/releases/tag/v0.8.5):212 213```214pip install vllm --upgrade215```216 217Doing so should automatically install [`mistral_common >= 1.5.5`](https://github.com/mistralai/mistral-common/releases/tag/v1.5.5).218 219To check:220```221python -c "import mistral_common; print(mistral_common.__version__)"222```223 224You can also make use of a ready-to-go [docker image](https://github.com/vllm-project/vllm/blob/main/Dockerfile) or on the [docker hub](https://hub.docker.com/layers/vllm/vllm-openai/latest/images/sha256-de9032a92ffea7b5c007dad80b38fd44aac11eddc31c435f8e52f3b7404bbf39).225 226#### Server227 228We recommand that you use Devstral in a server/client setting. 229 2301. Spin up a server:231 232```233vllm 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 2234```235 236 2372. To ping the client you can use a simple Python snippet.238 239```py240import requests241import json242from huggingface_hub import hf_hub_download243 244 245url = "http://<your-server-url>:8000/v1/chat/completions"246headers = {"Content-Type": "application/json", "Authorization": "Bearer token"}247 248model = "mistralai/Devstral-Small-2505"249 250def load_system_prompt(repo_id: str, filename: str) -> str:251 file_path = hf_hub_download(repo_id=repo_id, filename=filename)252 with open(file_path, "r") as file:253 system_prompt = file.read()254 return system_prompt255 256SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")257 258messages = [259 {"role": "system", "content": SYSTEM_PROMPT},260 {261 "role": "user",262 "content": [263 {264 "type": "text",265 "text": "<your-command>",266 },267 ],268 },269]270 271data = {"model": model, "messages": messages, "temperature": 0.15}272 273response = requests.post(url, headers=headers, data=json.dumps(data))274print(response.json()["choices"][0]["message"]["content"])275```276 277### Mistral-inference278 279We recommend using mistral-inference to quickly try out / "vibe-check" Devstral.280 281#### Install282 283Make sure to have mistral_inference >= 1.6.0 installed.284 285```bash286pip install mistral_inference --upgrade287```288 289#### Download290 291```python292from huggingface_hub import snapshot_download293from pathlib import Path294 295mistral_models_path = Path.home().joinpath('mistral_models', 'Devstral')296mistral_models_path.mkdir(parents=True, exist_ok=True)297 298snapshot_download(repo_id="mistralai/Devstral-Small-2505", allow_patterns=["params.json", "consolidated.safetensors", "tekken.json"], local_dir=mistral_models_path)299```300 301#### Python302 303You can run the model using the following command:304 305```bash306mistral-chat $HOME/mistral_models/Devstral --instruct --max_tokens 300307```308 309You can then prompt it with anything you'd like.310 311### Transformers312 313To make the best use of our model with transformers make sure to have [installed](https://github.com/mistralai/mistral-common) ` mistral-common >= 1.5.5` to use our tokenizer.314 315```bash316pip install mistral-common --upgrade317```318 319Then load our tokenizer along with the model and generate:320 321```python322import torch323 324from mistral_common.protocol.instruct.messages import (325 SystemMessage, UserMessage326)327from mistral_common.protocol.instruct.request import ChatCompletionRequest328from mistral_common.tokens.tokenizers.mistral import MistralTokenizer329from mistral_common.tokens.tokenizers.tekken import SpecialTokenPolicy330from huggingface_hub import hf_hub_download331from transformers import AutoModelForCausalLM332 333def load_system_prompt(repo_id: str, filename: str) -> str:334 file_path = hf_hub_download(repo_id=repo_id, filename=filename)335 with open(file_path, "r") as file:336 system_prompt = file.read()337 return system_prompt338 339model_id = "mistralai/Devstral-Small-2505"340tekken_file = hf_hub_download(repo_id=model_id, filename="tekken.json")341SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")342 343tokenizer = MistralTokenizer.from_file(tekken_file)344 345model = AutoModelForCausalLM.from_pretrained(model_id)346 347tokenized = tokenizer.encode_chat_completion(348 ChatCompletionRequest(349 messages=[350 SystemMessage(content=SYSTEM_PROMPT),351 UserMessage(content="<your-command>"),352 ],353 )354)355 356output = model.generate(357 input_ids=torch.tensor([tokenized.tokens]),358 max_new_tokens=1000,359)[0]360 361decoded_output = tokenizer.decode(output[len(tokenized.tokens):])362print(decoded_output)363```364 365### LMStudio366Download the weights from huggingface:367 368```369pip install -U "huggingface_hub[cli]"370huggingface-cli download \371"mistralai/Devstral-Small-2505_gguf" \372--include "devstralQ4_K_M.gguf" \373--local-dir "mistralai/Devstral-Small-2505_gguf/"374```375 376You can serve the model locally with [LMStudio](https://lmstudio.ai/).377* Download [LM Studio](https://lmstudio.ai/) and install it378* Install `lms cli ~/.lmstudio/bin/lms bootstrap`379* In a bash terminal, run `lms import devstralQ4_K_M.gguf` in the directory where you've downloaded the model checkpoint (e.g. `mistralai/Devstral-Small-2505_gguf`)380* Open the LMStudio application, click the terminal icon to get into the developer tab. Click select a model to load and select Devstral Q4 K M. Toggle the status button to start the model, in setting toggle Serve on Local Network to be on.381* On the right tab, you will see an API identifier which should be devstralq4_k_m and an api address under API Usage. Keep note of this address, we will use it in the next step.382 383Launch Openhands384You can now interact with the model served from LM Studio with openhands. Start the openhands server with the docker385 386```bash387docker pull docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik388docker run -it --rm --pull=always \389 -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.38-nikolaik \390 -e LOG_ALL_EVENTS=true \391 -v /var/run/docker.sock:/var/run/docker.sock \392 -v ~/.openhands-state:/.openhands-state \393 -p 3000:3000 \394 --add-host host.docker.internal:host-gateway \395 --name openhands-app \396 docker.all-hands.dev/all-hands-ai/openhands:0.38397```398 399Click “see advanced setting” on the second line. 400In the new tab, toggle advanced to on. Set the custom model to be mistral/devstralq4_k_m and Base URL the api address we get from the last step in LM Studio. Set API Key to dummy. Click save changes.401 402 403### Ollama404 405You can run Devstral using the [Ollama](https://ollama.ai/) CLI.406 407```bash408ollama run devstral409```410 