danielhanchen commited on
Commit
d46d926
·
verified ·
1 Parent(s): cd440fa

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +730 -0
README.md ADDED
@@ -0,0 +1,730 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - fr
5
+ - de
6
+ - es
7
+ - pt
8
+ - it
9
+ - ja
10
+ - ko
11
+ - ru
12
+ - zh
13
+ - ar
14
+ - fa
15
+ - id
16
+ - ms
17
+ - ne
18
+ - pl
19
+ - ro
20
+ - sr
21
+ - sv
22
+ - tr
23
+ - uk
24
+ - vi
25
+ - hi
26
+ - bn
27
+ license: apache-2.0
28
+ library_name: vllm
29
+ inference: false
30
+ base_model:
31
+ - mistralai/Mistral-Small-3.2-24B-Instruct-2506
32
+ pipeline_tag: image-text-to-text
33
+ ---
34
+
35
+ > [!NOTE]
36
+ > If you are using `llama.cpp`, use `--jinja` to enable the system prompt.
37
+ >
38
+
39
+ <div>
40
+ <p style="margin-top: 0;margin-bottom: 0;">
41
+ <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>
42
+ </p>
43
+ <div style="display: flex; gap: 5px; align-items: center; ">
44
+ <a href="https://github.com/unslothai/unsloth/">
45
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
46
+ </a>
47
+ <a href="https://discord.gg/unsloth">
48
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
49
+ </a>
50
+ <a href="https://docs.unsloth.ai/basics/magistral">
51
+ <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
52
+ </a>
53
+ </div>
54
+ <h1 style="margin-top: 0rem;">✨ How to Use Mistral 3.2 Small:</h1>
55
+ </div>
56
+
57
+ Run in llama.cpp:
58
+ ```
59
+ ./llama.cpp/llama-cli -hf unsloth/Mistral-Small-3.2-24B-Instruct-2506-GGUF:UD-Q4_K_XL --jinja --temp 0.15 --top-k -1 --top-p 1.00 -ngl 99
60
+ ```
61
+ Run in Ollama:
62
+ ```
63
+ ollama run hf.co/unsloth/Mistral-Small-3.2-24B-Instruct-2506-GGUF:UD-Q4_K_XL
64
+ ```
65
+
66
+ - Temperature of: 0.15
67
+ - Set top_p to: 1.00
68
+ - Max tokens (context length): 128K
69
+
70
+ - 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)!
71
+ - View the rest of our notebooks in our [docs here](https://docs.unsloth.ai/get-started/unsloth-notebooks).
72
+
73
+ <br>
74
+
75
+ # Mistral-Small-3.2-24B-Instruct-2506
76
+
77
+ Mistral-Small-3.2-24B-Instruct-2506 is a minor update of [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503).
78
+
79
+ Small-3.2 improves in the following categories:
80
+ - **Instruction following**: Small-3.2 is better at following precise instructions
81
+ - **Repetition errors**: Small-3.2 produces less infinite generations or repetitive answers
82
+ - **Function calling**: Small-3.2's function calling template is more robust (see [here](https://github.com/mistralai/mistral-common/blob/535b4d0a0fc94674ea17db6cf8dc2079b81cbcfa/src/mistral_common/tokens/tokenizers/instruct.py#L778) and [examples](#function-calling))
83
+
84
+ In all other categories Small-3.2 should match or slightly improve compared to [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503).
85
+
86
+ ## Key Features
87
+ - same as [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503#key-features)
88
+
89
+ ## Benchmark Results
90
+
91
+ We compare Mistral-Small-3.2-24B to [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503).
92
+ For more comparison against other models of similar size, please check [Mistral-Small-3.1's Benchmarks'](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503#benchmark-results)
93
+
94
+ ### Text
95
+
96
+ #### Instruction Following / Chat / Tone
97
+
98
+ | Model | Wildbench v2 | Arena Hard v2 | IF (Internal; accuracy) |
99
+ |-------|---------------|---------------|------------------------|
100
+ | Small 3.1 24B Instruct | 55.6% | 19.56% | 82.75% |
101
+ | **Small 3.2 24B Instruct** | **65.33%** | **43.1%** | **84.78%** |
102
+
103
+ #### Infinite Generations
104
+
105
+ Small 3.2 reduces infitine generations by 2x on challenging, long and repetitive prompts.
106
+
107
+ | Model | Infinite Generations (Internal; Lower is better) |
108
+ |-------|-------|
109
+ | Small 3.1 24B Instruct | 2.11% |
110
+ | **Small 3.2 24B Instruct** | **1.29%** |
111
+
112
+ #### STEM
113
+
114
+ | Model | MMLU | MMLU Pro (5-shot CoT) | MATH | GPQA Main (5-shot CoT) | GPQA Diamond (5-shot CoT )| MBPP Plus - Pass@5 | HumanEval Plus - Pass@5 | SimpleQA (TotalAcc)|
115
+ |--------------------------------|-----------|-----------------------|------------------------|------------------------|---------------------------|--------------------|-------------------------|--------------------|
116
+ | Small 3.1 24B Instruct | 80.62% | 66.76% | 69.30% | 44.42% | 45.96% | 74.63% | 88.99% | 10.43% |
117
+ | **Small 3.2 24B Instruct** | 80.50% | **69.06%** | 69.42% | 44.22% | 46.13% | **78.33%** | **92.90%** | **12.10%** |
118
+
119
+ ### Vision
120
+
121
+ | Model | MMMU | Mathvista | ChartQA | DocVQA | AI2D |
122
+ |--------------------------------|------------|-----------|-----------|-----------|-----------|
123
+ | Small 3.1 24B Instruct | **64.00%** | **68.91%**| 86.24% | 94.08% | 93.72% |
124
+ | **Small 3.2 24B Instruct** | 62.50% | 67.09% | **87.4%** | 94.86% | 92.91% |
125
+
126
+
127
+ ## Usage
128
+
129
+ The model can be used with the following frameworks;
130
+ - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
131
+ - [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
132
+
133
+ **Note 1**: We recommend using a relatively low temperature, such as `temperature=0.15`.
134
+
135
+ **Note 2**: Make sure to add a system prompt to the model to best tailer it for your needs. If you want to use the model as a general assistant, we recommend to use the one provided in the [SYSTEM_PROMPT.txt](https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506/blob/main/SYSTEM_PROMPT.txt) file.
136
+
137
+ ### vLLM (recommended)
138
+
139
+ We recommend using this model with [vLLM](https://github.com/vllm-project/vllm).
140
+
141
+ #### Installation
142
+
143
+ Make sure to install [`vLLM >= 0.9.1`](https://github.com/vllm-project/vllm/releases/tag/v0.9.1):
144
+
145
+ ```
146
+ pip install vllm --upgrade
147
+ ```
148
+
149
+ Doing so should automatically install [`mistral_common >= 1.6.2`](https://github.com/mistralai/mistral-common/releases/tag/v1.6.2).
150
+
151
+ To check:
152
+ ```
153
+ python -c "import mistral_common; print(mistral_common.__version__)"
154
+ ```
155
+
156
+ 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).
157
+
158
+ #### Serve
159
+
160
+ We recommand that you use Mistral-Small-3.2-24B-Instruct-2506 in a server/client setting.
161
+
162
+ 1. Spin up a server:
163
+
164
+ ```
165
+ vllm serve mistralai/Mistral-Small-3.2-24B-Instruct-2506 --tokenizer_mode mistral --config_format mistral --load_format mistral --tool-call-parser mistral --enable-auto-tool-choice --limit_mm_per_prompt 'image=10' --tensor-parallel-size 2
166
+ ```
167
+
168
+ **Note:** Running Mistral-Small-3.2-24B-Instruct-2506 on GPU requires ~55 GB of GPU RAM in bf16 or fp16.
169
+
170
+
171
+ 2. To ping the client you can use a simple Python snippet. See the following examples.
172
+
173
+
174
+ #### Vision reasoning
175
+
176
+ Take leverage of the vision capabilities of Mistral-Small-3.2-24B-Instruct-2506 to take the best choice given a scenario, go catch them all !
177
+
178
+ <details>
179
+ <summary>Python snippet</summary>
180
+
181
+ ```py
182
+ from datetime import datetime, timedelta
183
+
184
+ from openai import OpenAI
185
+ from huggingface_hub import hf_hub_download
186
+
187
+ # Modify OpenAI's API key and API base to use vLLM's API server.
188
+ openai_api_key = "EMPTY"
189
+ openai_api_base = "http://localhost:8000/v1"
190
+
191
+ TEMP = 0.15
192
+ MAX_TOK = 131072
193
+
194
+ client = OpenAI(
195
+ api_key=openai_api_key,
196
+ base_url=openai_api_base,
197
+ )
198
+
199
+ models = client.models.list()
200
+ model = models.data[0].id
201
+
202
+
203
+ def load_system_prompt(repo_id: str, filename: str) -> str:
204
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
205
+ with open(file_path, "r") as file:
206
+ system_prompt = file.read()
207
+ today = datetime.today().strftime("%Y-%m-%d")
208
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
209
+ model_name = repo_id.split("/")[-1]
210
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
211
+
212
+
213
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
214
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
215
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
216
+
217
+ messages = [
218
+ {"role": "system", "content": SYSTEM_PROMPT},
219
+ {
220
+ "role": "user",
221
+ "content": [
222
+ {
223
+ "type": "text",
224
+ "text": "What action do you think I should take in this situation? List all the possible actions and explain why you think they are good or bad.",
225
+ },
226
+ {"type": "image_url", "image_url": {"url": image_url}},
227
+ ],
228
+ },
229
+ ]
230
+
231
+
232
+ response = client.chat.completions.create(
233
+ model=model,
234
+ messages=messages,
235
+ temperature=TEMP,
236
+ max_tokens=MAX_TOK,
237
+ )
238
+
239
+ print(response.choices[0].message.content)
240
+ # In this situation, you are playing a Pokémon game where your Pikachu (Level 42) is facing a wild Pidgey (Level 17). Here are the possible actions you can take and an analysis of each:
241
+
242
+ # 1. **FIGHT**:
243
+ # - **Pros**: Pikachu is significantly higher level than the wild Pidgey, which suggests that it should be able to defeat Pidgey easily. This could be a good opportunity to gain experience points and possibly items or money.
244
+ # - **Cons**: There is always a small risk of Pikachu fainting, especially if Pidgey has a powerful move or a status effect that could hinder Pikachu. However, given the large level difference, this risk is minimal.
245
+
246
+ # 2. **BAG**:
247
+ # - **Pros**: You might have items in your bag that could help in this battle, such as Potions, Poké Balls, or Berries. Using an item could help you capture the Pidgey or heal your Pikachu if needed.
248
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat the Pidgey quickly.
249
+
250
+ # 3. **POKÉMON**:
251
+ # - **Pros**: You might have another Pokémon in your party that is better suited for this battle or that you want to gain experience. Switching Pokémon could also be a strategic move if you want to train a lower-level Pokémon.
252
+ # - **Cons**: Switching Pokémon might not be necessary since Pikachu is at a significant advantage. It could also waste time and potentially give Pidgey a turn to attack.
253
+
254
+ # 4. **RUN**:
255
+ # - **Pros**: Running away could save time and conserve your Pokémon's health and resources. If you are in a hurry or do not need the experience or items, running away is a safe option.
256
+ # - **Cons**: Running away means you miss out on the experience points and potential items or money that you could gain from defeating the Pidgey. It also means you do not get the chance to capture the Pidgey if you wanted to.
257
+
258
+ # ### Recommendation:
259
+ # Given the significant level advantage, the best action is likely to **FIGHT**. This will allow you to quickly defeat the Pidgey, gain experience points, and potentially earn items or money. If you are concerned about Pikachu's health, you could use an item from your **BAG** to heal it before or during the battle. Running away or switching Pokémon does not seem necessary in this situation.
260
+ ```
261
+ </details>
262
+
263
+ #### Function calling
264
+
265
+ Mistral-Small-3.2-24B-Instruct-2506 is excellent at function / tool calling tasks via vLLM. *E.g.:*
266
+
267
+ <details>
268
+ <summary>Python snippet - easy</summary>
269
+
270
+ ```py
271
+ from openai import OpenAI
272
+ from huggingface_hub import hf_hub_download
273
+
274
+ # Modify OpenAI's API key and API base to use vLLM's API server.
275
+ openai_api_key = "EMPTY"
276
+ openai_api_base = "http://localhost:8000/v1"
277
+
278
+ TEMP = 0.15
279
+ MAX_TOK = 131072
280
+
281
+ client = OpenAI(
282
+ api_key=openai_api_key,
283
+ base_url=openai_api_base,
284
+ )
285
+
286
+ models = client.models.list()
287
+ model = models.data[0].id
288
+
289
+ def load_system_prompt(repo_id: str, filename: str) -> str:
290
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
291
+ with open(file_path, "r") as file:
292
+ system_prompt = file.read()
293
+ return system_prompt
294
+
295
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
296
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
297
+
298
+ image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
299
+
300
+ tools = [
301
+ {
302
+ "type": "function",
303
+ "function": {
304
+ "name": "get_current_population",
305
+ "description": "Get the up-to-date population of a given country.",
306
+ "parameters": {
307
+ "type": "object",
308
+ "properties": {
309
+ "country": {
310
+ "type": "string",
311
+ "description": "The country to find the population of.",
312
+ },
313
+ "unit": {
314
+ "type": "string",
315
+ "description": "The unit for the population.",
316
+ "enum": ["millions", "thousands"],
317
+ },
318
+ },
319
+ "required": ["country", "unit"],
320
+ },
321
+ },
322
+ },
323
+ {
324
+ "type": "function",
325
+ "function": {
326
+ "name": "rewrite",
327
+ "description": "Rewrite a given text for improved clarity",
328
+ "parameters": {
329
+ "type": "object",
330
+ "properties": {
331
+ "text": {
332
+ "type": "string",
333
+ "description": "The input text to rewrite",
334
+ }
335
+ },
336
+ },
337
+ },
338
+ },
339
+ ]
340
+
341
+ messages = [
342
+ {"role": "system", "content": SYSTEM_PROMPT},
343
+ {
344
+ "role": "user",
345
+ "content": "Could you please make the below article more concise?\n\nOpenAI is an artificial intelligence research laboratory consisting of the non-profit OpenAI Incorporated and its for-profit subsidiary corporation OpenAI Limited Partnership.",
346
+ },
347
+ {
348
+ "role": "assistant",
349
+ "content": "",
350
+ "tool_calls": [
351
+ {
352
+ "id": "bbc5b7ede",
353
+ "type": "function",
354
+ "function": {
355
+ "name": "rewrite",
356
+ "arguments": '{"text": "OpenAI is an artificial intelligence research laboratory consisting of the non-profit OpenAI Incorporated and its for-profit subsidiary corporation OpenAI Limited Partnership."}',
357
+ },
358
+ }
359
+ ],
360
+ },
361
+ {
362
+ "role": "tool",
363
+ "content": '{"action":"rewrite","outcome":"OpenAI is a FOR-profit company."}',
364
+ "tool_call_id": "bbc5b7ede",
365
+ "name": "rewrite",
366
+ },
367
+ {
368
+ "role": "assistant",
369
+ "content": "---\n\nOpenAI is a FOR-profit company.",
370
+ },
371
+ {
372
+ "role": "user",
373
+ "content": [
374
+ {
375
+ "type": "text",
376
+ "text": "Can you tell me what is the biggest country depicted on the map?",
377
+ },
378
+ {
379
+ "type": "image_url",
380
+ "image_url": {
381
+ "url": image_url,
382
+ },
383
+ },
384
+ ],
385
+ }
386
+ ]
387
+
388
+ response = client.chat.completions.create(
389
+ model=model,
390
+ messages=messages,
391
+ temperature=TEMP,
392
+ max_tokens=MAX_TOK,
393
+ tools=tools,
394
+ tool_choice="auto",
395
+ )
396
+
397
+ assistant_message = response.choices[0].message.content
398
+ print(assistant_message)
399
+ # The biggest country depicted on the map is Russia.
400
+
401
+ messages.extend([
402
+ {"role": "assistant", "content": assistant_message},
403
+ {"role": "user", "content": "What is the population of that country in millions?"},
404
+ ])
405
+
406
+ response = client.chat.completions.create(
407
+ model=model,
408
+ messages=messages,
409
+ temperature=TEMP,
410
+ max_tokens=MAX_TOK,
411
+ tools=tools,
412
+ tool_choice="auto",
413
+ )
414
+
415
+ print(response.choices[0].message.tool_calls)
416
+ # [ChatCompletionMessageToolCall(id='3e92V6Vfo', function=Function(arguments='{"country": "Russia", "unit": "millions"}', name='get_current_population'), type='function')]
417
+ ```
418
+
419
+ </details>
420
+
421
+ <details>
422
+ <summary>Python snippet - complex</summary>
423
+
424
+ ```python
425
+ import json
426
+ from openai import OpenAI
427
+ from huggingface_hub import hf_hub_download
428
+
429
+ # Modify OpenAI's API key and API base to use vLLM's API server.
430
+ openai_api_key = "EMPTY"
431
+ openai_api_base = "http://localhost:8000/v1"
432
+
433
+ TEMP = 0.15
434
+ MAX_TOK = 131072
435
+
436
+ client = OpenAI(
437
+ api_key=openai_api_key,
438
+ base_url=openai_api_base,
439
+ )
440
+
441
+ models = client.models.list()
442
+ model = models.data[0].id
443
+
444
+
445
+ def load_system_prompt(repo_id: str, filename: str) -> str:
446
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
447
+ with open(file_path, "r") as file:
448
+ system_prompt = file.read()
449
+ return system_prompt
450
+
451
+
452
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
453
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
454
+
455
+ image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
456
+
457
+
458
+ def my_calculator(expression: str) -> str:
459
+ return str(eval(expression))
460
+
461
+
462
+ tools = [
463
+ {
464
+ "type": "function",
465
+ "function": {
466
+ "name": "my_calculator",
467
+ "description": "A calculator that can evaluate a mathematical expression.",
468
+ "parameters": {
469
+ "type": "object",
470
+ "properties": {
471
+ "expression": {
472
+ "type": "string",
473
+ "description": "The mathematical expression to evaluate.",
474
+ },
475
+ },
476
+ "required": ["expression"],
477
+ },
478
+ },
479
+ },
480
+ {
481
+ "type": "function",
482
+ "function": {
483
+ "name": "rewrite",
484
+ "description": "Rewrite a given text for improved clarity",
485
+ "parameters": {
486
+ "type": "object",
487
+ "properties": {
488
+ "text": {
489
+ "type": "string",
490
+ "description": "The input text to rewrite",
491
+ }
492
+ },
493
+ },
494
+ },
495
+ },
496
+ ]
497
+
498
+ messages = [
499
+ {"role": "system", "content": SYSTEM_PROMPT},
500
+ {
501
+ "role": "user",
502
+ "content": [
503
+ {
504
+ "type": "text",
505
+ "text": "Can you calculate the results for all the equations displayed in the image? Only compute the ones that involve numbers.",
506
+ },
507
+ {
508
+ "type": "image_url",
509
+ "image_url": {
510
+ "url": image_url,
511
+ },
512
+ },
513
+ ],
514
+ },
515
+ ]
516
+
517
+ response = client.chat.completions.create(
518
+ model=model,
519
+ messages=messages,
520
+ temperature=TEMP,
521
+ max_tokens=MAX_TOK,
522
+ tools=tools,
523
+ tool_choice="auto",
524
+ )
525
+
526
+ tool_calls = response.choices[0].message.tool_calls
527
+ print(tool_calls)
528
+ # [ChatCompletionMessageToolCall(id='CyQBSAtGh', function=Function(arguments='{"expression": "6 + 2 * 3"}', name='my_calculator'), type='function'), ChatCompletionMessageToolCall(id='KQqRCqvzc', function=Function(arguments='{"expression": "19 - (8 + 2) + 1"}', name='my_calculator'), type='function')]
529
+
530
+ results = []
531
+ for tool_call in tool_calls:
532
+ function_name = tool_call.function.name
533
+ function_args = tool_call.function.arguments
534
+ if function_name == "my_calculator":
535
+ result = my_calculator(**json.loads(function_args))
536
+ results.append(result)
537
+
538
+ messages.append({"role": "assistant", "tool_calls": tool_calls})
539
+ for tool_call, result in zip(tool_calls, results):
540
+ messages.append(
541
+ {
542
+ "role": "tool",
543
+ "tool_call_id": tool_call.id,
544
+ "name": tool_call.function.name,
545
+ "content": result,
546
+ }
547
+ )
548
+
549
+
550
+ response = client.chat.completions.create(
551
+ model=model,
552
+ messages=messages,
553
+ temperature=TEMP,
554
+ max_tokens=MAX_TOK,
555
+ )
556
+
557
+ print(response.choices[0].message.content)
558
+ # Here are the results for the equations that involve numbers:
559
+
560
+ # 1. \( 6 + 2 \times 3 = 12 \)
561
+ # 3. \( 19 - (8 + 2) + 1 = 10 \)
562
+
563
+ # For the other equations, you need to substitute the variables with specific values to compute the results.
564
+ ```
565
+
566
+ </details>
567
+
568
+ #### Instruction following
569
+
570
+ Mistral-Small-3.2-24B-Instruct-2506 will follow your instructions down to the last letter !
571
+
572
+ <details>
573
+ <summary>Python snippet</summary>
574
+
575
+ ```python
576
+ from openai import OpenAI
577
+ from huggingface_hub import hf_hub_download
578
+
579
+ # Modify OpenAI's API key and API base to use vLLM's API server.
580
+ openai_api_key = "EMPTY"
581
+ openai_api_base = "http://localhost:8000/v1"
582
+
583
+ TEMP = 0.15
584
+ MAX_TOK = 131072
585
+
586
+ client = OpenAI(
587
+ api_key=openai_api_key,
588
+ base_url=openai_api_base,
589
+ )
590
+
591
+ models = client.models.list()
592
+ model = models.data[0].id
593
+
594
+
595
+ def load_system_prompt(repo_id: str, filename: str) -> str:
596
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
597
+ with open(file_path, "r") as file:
598
+ system_prompt = file.read()
599
+ return system_prompt
600
+
601
+
602
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
603
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
604
+
605
+ messages = [
606
+ {"role": "system", "content": SYSTEM_PROMPT},
607
+ {
608
+ "role": "user",
609
+ "content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
610
+ },
611
+ ]
612
+
613
+ response = client.chat.completions.create(
614
+ model=model,
615
+ messages=messages,
616
+ temperature=TEMP,
617
+ max_tokens=MAX_TOK,
618
+ )
619
+
620
+ assistant_message = response.choices[0].message.content
621
+ print(assistant_message)
622
+
623
+ # Here's a sentence where each word starts with the next letter of the alphabet, starting from 'a' and ending with 'z':
624
+
625
+ # "Always brave cats dance elegantly, fluffy giraffes happily ignore jungle kites, lovingly munching nuts, observing playful quails racing swiftly, tiny unicorns vaulting while xylophones yodel zealously."
626
+
627
+ # This sentence follows the sequence from A to Z without skipping any letters.
628
+ ```
629
+ </details>
630
+
631
+ ### Transformers
632
+
633
+ You can also use Mistral-Small-3.2-24B-Instruct-2506 with `Transformers` !
634
+
635
+ To make the best use of our model with `Transformers` make sure to have [installed](https://github.com/mistralai/mistral-common) `mistral-common >= 1.6.2` to use our tokenizer.
636
+
637
+ ```bash
638
+ pip install mistral-common --upgrade
639
+ ```
640
+
641
+ Then load our tokenizer along with the model and generate:
642
+
643
+ <details>
644
+ <summary>Python snippet</summary>
645
+
646
+ ```python
647
+ from datetime import datetime, timedelta
648
+ import torch
649
+
650
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
651
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
652
+ from huggingface_hub import hf_hub_download
653
+ from transformers import Mistral3ForConditionalGeneration
654
+
655
+
656
+ def load_system_prompt(repo_id: str, filename: str) -> str:
657
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
658
+ with open(file_path, "r") as file:
659
+ system_prompt = file.read()
660
+ today = datetime.today().strftime("%Y-%m-%d")
661
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
662
+ model_name = repo_id.split("/")[-1]
663
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
664
+
665
+
666
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
667
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
668
+
669
+ tokenizer = MistralTokenizer.from_hf_hub(model_id)
670
+
671
+ model = Mistral3ForConditionalGeneration.from_pretrained(
672
+ model_id, torch_dtype=torch.bfloat16
673
+ )
674
+
675
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
676
+
677
+ messages = [
678
+ {"role": "system", "content": SYSTEM_PROMPT},
679
+ {
680
+ "role": "user",
681
+ "content": [
682
+ {
683
+ "type": "text",
684
+ "text": "What action do you think I should take in this situation? List all the possible actions and explain why you think they are good or bad.",
685
+ },
686
+ {"type": "image_url", "image_url": {"url": image_url}},
687
+ ],
688
+ },
689
+ ]
690
+
691
+ tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
692
+
693
+ input_ids = torch.tensor([tokenized.tokens])
694
+ attention_mask = torch.ones_like(input_ids)
695
+ pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
696
+ image_sizes = torch.tensor([pixel_values.shape[-2:]])
697
+
698
+ output = model.generate(
699
+ input_ids=input_ids,
700
+ attention_mask=attention_mask,
701
+ pixel_values=pixel_values,
702
+ image_sizes=image_sizes,
703
+ max_new_tokens=1000,
704
+ )[0]
705
+
706
+ decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
707
+ print(decoded_output)
708
+ # In this situation, you are playing a Pokémon game where your Pikachu (Level 42) is facing a wild Pidgey (Level 17). Here are the possible actions you can take and an analysis of each:
709
+
710
+ # 1. **FIGHT**:
711
+ # - **Pros**: Pikachu is significantly higher level than the wild Pidgey, which suggests that it should be able to defeat Pidgey easily. This could be a good opportunity to gain experience points and possibly items or money.
712
+ # - **Cons**: There is always a small risk of Pikachu fainting, especially if Pidgey has a powerful move or a status effect that could hinder Pikachu. However, given the large level difference, this risk is minimal.
713
+
714
+ # 2. **BAG**:
715
+ # - **Pros**: You might have items in your bag that could help in this battle, such as Potions, Poké Balls, or Berries. Using an item could help you capture Pidgey or heal Pikachu if needed.
716
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
717
+
718
+ # 3. **POKÉMON**:
719
+ # - **Pros**: You might have another Pokémon in your party that is better suited for this battle or that you want to gain experience. Switching Pokémon could also be strategic if you want to train a lower-level Pokémon.
720
+ # - **Cons**: Switching Pokémon might not be necessary since Pikachu is at a significant advantage. It could also waste time and potentially give Pidgey a turn to attack.
721
+
722
+ # 4. **RUN**:
723
+ # - **Pros**: Running away could be a quick way to avoid the battle altogether. This might be useful if you are trying to conserve resources or if you are in a hurry to get to another location.
724
+ # - **Cons**: Running away means you miss out on the experience points, items, or money that you could gain from defeating Pidgey. It also might not be the most efficient use of your time if you are trying to train your Pokémon.
725
+
726
+ # ### Recommendation:
727
+ # Given the significant level advantage, the best action to take is likely **FIGHT**. This will allow you to quickly defeat Pidgey and gain experience points for Pikachu. If you are concerned about Pikachu's health, you could use the **BAG** to heal Pikachu before or during the battle. Running away or switching Pokémon does not seem necessary in this situation.
728
+ ```
729
+
730
+ </details>