[THINK] and [/THINK] special tokens encapsulate the reasoning content in a thinking chunk. This makes it easier to parse the reasoning trace and prevents confusion when the '[THINK]' token is given as a string in the prompt.| Model | AIME24 pass@1 | AIME25 pass@1 | GPQA Diamond | Livecodebench (v5) |
|---|---|---|---|---|
| Magistral Medium 1.1 | 72.03% | 60.99% | 71.46% | 59.35% |
| Magistral Medium 1.0 | 73.59% | 64.95% | 70.83% | 59.36% |
| Magistral Small 1.1 | 70.52% | 62.03% | 65.78% | 59.17% |
| Magistral Small 1.0 | 70.68% | 62.76% | 68.18% | 55.84% |
top_p: 0.95temperature: 0.7max_tokens: 40960First draft your thinking process (inner monologue) until you arrive at a response. Format your response using Markdown, and use LaTeX for any mathematical equations. Write both your thoughts and the response in the same language as the input.Your thinking process must follow the template below:[THINK]Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate the response. Use the same language as the input.[/THINK]Here, provide a self-contained response.
[THINK] and [/THINK] are special tokens that must be encoded as such.mistral-common.vllm (recommended): See belowtransformers: See belowvLLM code:pip install -U vllm \
--pre \
--extra-index-url https://wheels.vllm.ai/nightlymistral_common >= 1.8.2.python -c "import mistral_common; print(mistral_common.__version__)"vllm serve mistralai/Magistral-Small-2507 --reasoning-parser mistral --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 21from typing import Any
2from openai import OpenAI
3from huggingface_hub import hf_hub_download
4
5# Modify OpenAI's API key and API base to use vLLM's API server.
6openai_api_key = "EMPTY"
7openai_api_base = "http://localhost:8000/v1"
8
9TEMP = 0.7
10TOP_P = 0.95
11MAX_TOK = 40_960
12
13client = OpenAI(
14 api_key=openai_api_key,
15 base_url=openai_api_base,
16)
17
18models = client.models.list()
19model = models.data[0].id
20
21def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
22 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
23 with open(file_path, "r") as file:
24 system_prompt = file.read()
25
26 index_begin_think = system_prompt.find("[THINK]")
27 index_end_think = system_prompt.find("[/THINK]")
28
29 return {
30 "role": "system",
31 "content": [
32 {"type": "text", "text": system_prompt[:index_begin_think]},
33 {
34 "type": "thinking",
35 "thinking": system_prompt[
36 index_begin_think + len("[THINK]") : index_end_think
37 ],
38 "closed": True,
39 },
40 {
41 "type": "text",
42 "text": system_prompt[index_end_think + len("[/THINK]") :],
43 },
44 ],
45 }
46
47SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
48
49query = "Write 4 sentences, each with at least 8 words. Now make absolutely sure that every sentence has exactly one word less than the previous sentence."
50# or try out other queries
51# query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."
52# query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133"
53# query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?"
54
55messages = [
56 SYSTEM_PROMPT,
57 {"role": "user", "content": query}
58]
59stream = client.chat.completions.create(
60 model=model,
61 messages=messages,
62 stream=True,
63 temperature=TEMP,
64 top_p=TOP_P,
65 max_tokens=MAX_TOK,
66)
67
68print("client: Start streaming chat completions...:\n")
69printed_reasoning_content = False
70answer = []
71
72for chunk in stream:
73 reasoning_content = None
74 content = None
75 # Check the content is reasoning_content or content
76 if hasattr(chunk.choices[0].delta, "reasoning_content"):
77 reasoning_content = chunk.choices[0].delta.reasoning_content
78 elif hasattr(chunk.choices[0].delta, "content"):
79 content = chunk.choices[0].delta.content
80
81 if reasoning_content is not None:
82 if not printed_reasoning_content:
83 printed_reasoning_content = True
84 print("Start reasoning:\n", end="", flush=True)
85 print(reasoning_content, end="", flush=True)
86 elif content is not None:
87 # Extract and print the content
88 if not reasoning_content and printed_reasoning_content:
89 answer.extend(content)
90 print(content, end="", flush=True)
91
92if answer:
93 print("\n\n=============\nAnswer\n=============\n")
94 print("".join(answer))
95else:
96 print("\n\n=============\nNo Answer\n=============\n")
97 print("No answer was generated by the model, probably because the maximum number of tokens was reached.")
98
99# client: Start streaming chat completions...:
100#
101# Start reasoning:
102# First, I need to write ...
103# ...
104#
105#
106# =============
107# Answer
108# =============
109#
110# Here are four sentences where each has at least 8 words, and each subsequent sentence has exactly one word less than the previous one:
111
112# 1. The quick brown fox jumps over the lazy dog and rests.
113# 2. The lazy dog rests under the big shady tree peacefully.
114# 3. The big shady tree provides ample shade during summer.
115# 4. The tree's leaves are very lush and green.Transformers code:pip install git+https://github.com/huggingface/transformersmistral_common >= 1.8.2:pip install --upgrade mistral-commonpython -c "import mistral_common; print(mistral_common.__version__)"1from typing import Any
2import torch
3
4from huggingface_hub import hf_hub_download
5from transformers import AutoModelForCausalLM, AutoTokenizer
6
7
8TEMP = 0.7
9TOP_P = 0.95
10MAX_TOK = 40_960
11
12def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
13 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
14 with open(file_path, "r") as file:
15 system_prompt = file.read()
16
17 index_begin_think = system_prompt.find("[THINK]")
18 index_end_think = system_prompt.find("[/THINK]")
19
20 return {
21 "role": "system",
22 "content": [
23 {"type": "text", "text": system_prompt[:index_begin_think]},
24 {
25 "type": "thinking",
26 "thinking": system_prompt[
27 index_begin_think + len("[THINK]") : index_end_think
28 ],
29 "closed": True,
30 },
31 {
32 "type": "text",
33 "text": system_prompt[index_end_think + len("[/THINK]") :],
34 },
35 ],
36 }
37
38
39model_id = "mistralai/Magistral-Small-2507"
40SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
41query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133."
42# or try out other queries
43# query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."
44# query = "Write 4 sentences, each with at least 8 words. Now make absolutely sure that every sentence has exactly one word less than the previous sentence."
45# query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?"
46
47
48
49tokenizer = AutoTokenizer.from_pretrained(model_id, tokenizer_type="mistral", use_fast=False)
50model = AutoModelForCausalLM.from_pretrained(
51 model_id, torch_dtype=torch.bfloat16, device_map="auto"
52)
53
54input_ids = tokenizer.apply_chat_template(
55 [
56 SYSTEM_PROMPT,
57 {"role": "user", "content": query},
58 ],
59)
60
61output = model.generate(
62 input_ids=torch.tensor([input_ids], device=model.device),
63 pad_token_id=tokenizer.pad_token_id,
64 eos_token_id=tokenizer.eos_token_id,
65 temperature=TEMP,
66 top_p=TOP_P,
67 do_sample=True,
68 max_new_tokens=MAX_TOK,
69)[0]
70
71decoded_output = tokenizer.decode(output[len(input_ids) :])
72print(decoded_output)
73
74# [THINK]Alright, I need to think of 5 random numbers first. Let's say I pick the numbers 5, 10, 2, 7, and 3.
75#
76# Now, I need to see if I can combine these numbers using addition, multiplication, subtraction, or division to get 133.
77# ...
78# ...
79# ...
80# But if we're to find any five numbers that can be combined to make 133, then yes, such sets exist, like the one demonstrated above.[/THINK]Yes, it is possible to combine some sets of five random numbers to make 133 using basic arithmetic operations. For example, the numbers 13, 10, 1, 2, and 3 can be combined as follows to make 133:
81#
82# \[ (13 \times 10) + (3 \times (2 - 1)) = 130 + 3 = 133 \]
83#
84# However, not all sets of five random numbers can be combined in this way to make 133. For instance, with the numbers 5, 10, 2, 7, and 3, it is not possible to combine them using the allowed operations to get exactly 133.
85#
86# Therefore, the ability to combine five random numbers to make 133 depends on the specific numbers chosen.
87#
88# $133 = (13 \times 10) + (3 \times (2 - 1))$</s>