Building upon
Mistral Small 3.2 (2506),
with added reasoning capabilities, undergoing SFT from Magistral Medium traces and RL on top, it's a small, efficient reasoning model with 24B parameters.
Magistral Small can be deployed locally, fitting within a single RTX 4090 or a 32GB RAM MacBook once quantized.
This is the GGUF version of the
Magistral-Small-2509 model. We released the BF16 weights as well as the
following quantized format:
We recommend to use Magistral Small 1.2 GGUF with
llama.cpp along with
mistral-common >= 1.8.5 server. See
here for the documentation of
mistral-common server.
-
Install
llama.cpp following their
guidelines.
-
Install mistral-common >= 1.8.5 with its dependencies.
1pip install -U "huggingface_hub[cli]"
2
3huggingface-cli download \
4"mistralai/Magistral-Small-2509-GGUF" \
5--include "Magistral-Small-2509-Q4_K_M.gguf" \
6--local-dir "mistralai/Magistral-Small-2509-GGUF/"
This is the server that will handle tokenization and detokenization and call the llama.cpp server for generations.
1mistral_common serve mistralai/Magistral-Small-2509 \
2--host localhost --port 6000 \
3--engine-url http://localhost:8080 --engine-backend llama_cpp \
4--timeout 300
generate: call
mistral-common that will tokenizer, call the
llama.cpp server to generate new tokens and detokenize the output to an
AssistantMessage with think chunk and tool calls parsed.
1from mistral_common.protocol.instruct.messages import AssistantMessage
2from mistral_common.protocol.instruct.request import ChatCompletionRequest
3from mistral_common.experimental.app.models import OpenAIChatCompletionRequest
4from fastapi.encoders import jsonable_encoder
5import requests
6
7mistral_common_url = "http://127.0.0.1:6000"
8
9def generate(
10 request: dict | ChatCompletionRequest | OpenAIChatCompletionRequest, url: str
11) -> AssistantMessage:
12 response = requests.post(
13 f"{url}/v1/chat/completions", json=jsonable_encoder(request)
14 )
15 if response.status_code != 200:
16 raise ValueError(f"Error: {response.status_code} - {response.text}")
17 return AssistantMessage(**response.json())
1from typing import Any
2from huggingface_hub import hf_hub_download
3
4
5TEMP = 0.7
6TOP_P = 0.95
7MAX_TOK = 131072
8
9def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
10 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
11 with open(file_path, "r") as file:
12 system_prompt = file.read()
13
14 index_begin_think = system_prompt.find("[THINK]")
15 index_end_think = system_prompt.find("[/THINK]")
16
17 return {
18 "role": "system",
19 "content": [
20 {"type": "text", "text": system_prompt[:index_begin_think]},
21 {
22 "type": "thinking",
23 "thinking": system_prompt[
24 index_begin_think + len("[THINK]") : index_end_think
25 ],
26 "closed": True,
27 },
28 {
29 "type": "text",
30 "text": system_prompt[index_end_think + len("[/THINK]") :],
31 },
32 ],
33 }
34
35SYSTEM_PROMPT = load_system_prompt("mistralai/Magistral-Small-2509", "SYSTEM_PROMPT.txt")
36
37query = "Use each number in 2,5,6,3 exactly once, along with any combination of +, -, ×, ÷ (and parentheses for grouping), to make the number 24."
38
39messages = [SYSTEM_PROMPT, {"role": "user", "content": [{"type": "text", "text": query}]}]
40
41request = {"messages": messages, "temperature": TEMP, "top_p": TOP_P, "max_tokens": MAX_TOK}
42
43generated_message = generate(request, mistral_common_url)
44print(generated_message)