shimmyshimmer commited on
Commit
29c5c0c
·
verified ·
1 Parent(s): ddce610

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +265 -3
README.md CHANGED
@@ -1,3 +1,265 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - mistralai/Magistral-Small-2506
4
+ - mistralai/Mistral-Small-3.1-24B-Instruct-2503
5
+ license: apache-2.0
6
+ pipeline_tag: text2text-generation
7
+ tags:
8
+ - mistral
9
+ - unsloth
10
+ language:
11
+ - en
12
+ - fr
13
+ - de
14
+ - es
15
+ - pt
16
+ - it
17
+ - ja
18
+ - ko
19
+ - ru
20
+ - zh
21
+ - ar
22
+ - fa
23
+ - id
24
+ - ms
25
+ - ne
26
+ - pl
27
+ - ro
28
+ - sr
29
+ - sv
30
+ - tr
31
+ - uk
32
+ - vi
33
+ - hi
34
+ - bn
35
+ ---
36
+ > [!NOTE]
37
+ > Magistral, enhanced with optional Vision support. <br> You should use `--jinja` to enable the system prompt in `llama.cpp`
38
+ <div>
39
+ <p style="margin-bottom: 0; margin-top: 0;">
40
+ <strong>Learn to run Magistral correctly - <a href="https://docs.unsloth.ai/basics/magistral">Read our Guide</a>.</strong>
41
+ </p>
42
+ <p style="margin-top: 0;margin-bottom: 0;">
43
+ <em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves SOTA performance in model quantization.</em>
44
+ </p>
45
+ <div style="display: flex; gap: 5px; align-items: center; ">
46
+ <a href="https://github.com/unslothai/unsloth/">
47
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
48
+ </a>
49
+ <a href="https://discord.gg/unsloth">
50
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
51
+ </a>
52
+ <a href="https://docs.unsloth.ai/basics/magistral">
53
+ <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
54
+ </a>
55
+ </div>
56
+ <h1 style="margin-top: 0rem;">✨ Run & Fine-tune Magistral with Unsloth!</h1>
57
+ </div>
58
+
59
+ - Fine-tune Mistral v0.3 (7B) for free using our Google [Colab notebook here](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_(7B)-Conversational.ipynb)!
60
+ - Read our Blog about Magistral support: [docs.unsloth.ai/basics/devstral](https://docs.unsloth.ai/basics/devstral)
61
+ - View the rest of our notebooks in our [docs here](https://docs.unsloth.ai/get-started/unsloth-notebooks).
62
+
63
+ ---
64
+ language:
65
+ - en
66
+ - fr
67
+ - de
68
+ - es
69
+ - pt
70
+ - it
71
+ - ja
72
+ - ko
73
+ - ru
74
+ - zh
75
+ - ar
76
+ - fa
77
+ - id
78
+ - ms
79
+ - ne
80
+ - pl
81
+ - ro
82
+ - sr
83
+ - sv
84
+ - tr
85
+ - uk
86
+ - vi
87
+ - hi
88
+ - bn
89
+ license: apache-2.0
90
+ library_name: vllm
91
+ inference: false
92
+ base_model:
93
+ - mistralai/Mistral-Small-3.1-24B-Instruct-2503
94
+ extra_gated_description: >-
95
+ If you want to learn more about how we process your personal data, please read
96
+ our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
97
+ ---
98
+
99
+ # Model Card for Magistral-Small-2506
100
+
101
+ Building upon Mistral Small 3.1 (2503), **with added reasoning capabilities**, undergoing SFT from Magistral Medium traces and RL on top, it's a small, efficient reasoning model with 24B parameters.
102
+
103
+ Magistral Small can be deployed locally, fitting within a single RTX 4090 or a 32GB RAM MacBook once quantized.
104
+
105
+ Learn more about Magistral in our [blog post](https://mistral.ai/news/magistral/).
106
+
107
+ ## Key Features
108
+ - **Reasoning:** Capable of long chains of reasoning traces before providing an answer.
109
+ - **Multilingual:** Supports dozens of languages, including English, French, German, Greek, Hindi, Indonesian, Italian, Japanese, Korean, Malay, Nepali, Polish, Portuguese, Romanian, Russian, Serbian, Spanish, Swedish, Turkish, Ukrainian, Vietnamese, Arabic, Bengali, Chinese, and Farsi.
110
+ - **Apache 2.0 License:** Open license allowing usage and modification for both commercial and non-commercial purposes.
111
+ - **Context Window:** A 128k context window, **but** performance might degrade past **40k**. Hence we recommend setting the maximum model length to 40k.
112
+
113
+ ## Benchmark Results
114
+
115
+ | Model | AIME24 pass@1 | AIME25 pass@1 | GPQA Diamond | Livecodebench (v5) |
116
+ |-------|-------------|-------------|--------------|-------------------|
117
+ | Magistral Medium | 73.59% | 64.95% | 70.83% | 59.36% |
118
+ | Magistral Small | 70.68% | 62.76% | 68.18% | 55.84% |
119
+
120
+ ## Sampling parameters
121
+
122
+ Please make sure to use:
123
+ - `top_p`: 0.95
124
+ - `temperature`: 0.7
125
+ - `max_model_len`: 40960
126
+
127
+ ## Basic Chat Template
128
+
129
+ We highly recommend including the default system prompt used during RL for the best results, you can edit and customise it if needed for your specific use case.
130
+
131
+ ```
132
+ <s>[SYSTEM_PROMPT]system_prompt
133
+
134
+ A user will ask you to solve a task. You should first draft your thinking process (inner monologue) until you have derived the final answer. Afterwards, write a self-contained summary of your thoughts (i.e. your summary should be succinct but contain all the critical steps you needed to reach the conclusion). You should use Markdown to format your response. Write both your thoughts and summary in the same language as the task posed by the user. NEVER use \boxed{} in your response.
135
+
136
+ Your thinking process must follow the template below:
137
+ <think>
138
+ 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 a correct answer.
139
+ </think>
140
+
141
+ Here, provide a concise summary that reflects your reasoning and presents a clear final answer to the user. Don't mention that this is a summary.
142
+
143
+ Problem:
144
+
145
+ [/SYSTEM_PROMPT][INST]user_message[/INST]<think>
146
+ reasoning_traces
147
+ </think>
148
+ assistant_response</s>[INST]user_message[/INST]
149
+ ```
150
+ *`system_prompt`, `user_message` and `assistant_response` are placeholders.*
151
+
152
+ We invite you to choose, depending on your use case and requirements, between keeping reasoning traces during multi-turn interactions or keeping only the final assistant response.
153
+
154
+ ***Please make sure to use [mistral-common](https://github.com/mistralai/mistral-common) as the source of truth***
155
+
156
+ ## Usage
157
+
158
+ The model can be used with the following frameworks;
159
+ - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm)
160
+
161
+ ### vLLM (recommended)
162
+
163
+ We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
164
+ to implement production-ready inference pipelines.
165
+
166
+ **_Installation_**
167
+
168
+ Make sure you install the latest [`vLLM`](https://github.com/vllm-project/vllm/) code:
169
+
170
+ ```
171
+ pip install -U vllm \
172
+ --pre \
173
+ --extra-index-url https://wheels.vllm.ai/nightly
174
+ ```
175
+
176
+ Doing so should automatically install [`mistral_common >= 1.6.0`](https://github.com/mistralai/mistral-common/releases/tag/v1.6.0).
177
+
178
+ To check:
179
+ ```
180
+ python -c "import mistral_common; print(mistral_common.__version__)"
181
+ ```
182
+
183
+ You 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).
184
+
185
+
186
+ Serve model as follows:
187
+
188
+ ```
189
+ vllm serve mistralai/magistral-small --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --tensor-parallel-size 2
190
+ ```
191
+
192
+ Ping model as follows:
193
+
194
+ ```py
195
+ from openai import OpenAI
196
+ from huggingface_hub import hf_hub_download
197
+
198
+ # Modify OpenAI's API key and API base to use vLLM's API server.
199
+ openai_api_key = "EMPTY"
200
+ openai_api_base = "http://localhost:8000/v1"
201
+
202
+ TEMP = 0.7
203
+ TOP_P = 0.95
204
+ MAX_TOK = 40_960
205
+
206
+ client = OpenAI(
207
+ api_key=openai_api_key,
208
+ base_url=openai_api_base,
209
+ )
210
+
211
+ models = client.models.list()
212
+ model = models.data[0].id
213
+
214
+ def load_system_prompt(repo_id: str, filename: str) -> str:
215
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
216
+ with open(file_path, "r") as file:
217
+ system_prompt = file.read()
218
+ return system_prompt
219
+
220
+ SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
221
+
222
+ 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."
223
+ # or try out other queries
224
+ # query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."
225
+ # query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133"
226
+ # query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?"
227
+
228
+ messages = [
229
+ {"role": "system", "content": SYSTEM_PROMPT},
230
+ {"role": "user", "content": query}
231
+ ]
232
+ stream = client.chat.completions.create(model=model, messages=messages, stream=True, temperature=TEMP, top_p=TOP_P, max_tokens=MAX_TOK)
233
+
234
+ print("client: Start streaming chat completions...")
235
+ printed_content = False
236
+
237
+ for chunk in stream:
238
+ content = None
239
+ # Check the content is content
240
+ if hasattr(chunk.choices[0].delta, "content"):
241
+ content = chunk.choices[0].delta.content
242
+
243
+ if content is not None:
244
+ if not printed_content:
245
+ printed_content = True
246
+ print("\ncontent:", end="", flush=True)
247
+ # Extract and print the content
248
+ print(content, end="", flush=True)
249
+
250
+ # content:<think>
251
+ # Alright, I need to write 4 sentences where each one has at least 8 words and each subsequent sentence has one fewer word than the previous one.
252
+ # ...
253
+ # Final boxed answer (the four sentences):
254
+
255
+ # \[
256
+ # \boxed{
257
+ # \begin{aligned}
258
+ # &\text{1. The quick brown fox jumps over lazy dog and yells hello.} \\
259
+ # &\text{2. I saw the cat on the stair with my hat.} \\
260
+ # &\text{3. The man in the moon came down quickly today.} \\
261
+ # &\text{4. A cat sat on the mat today patiently.}
262
+ # \end{aligned}
263
+ # }
264
+ # \]
265
+ ```