gabriellarson commited on
Commit
f881f0d
·
verified ·
1 Parent(s): 011abb5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +605 -0
README.md ADDED
@@ -0,0 +1,605 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ extra_gated_description: >-
33
+ If you want to learn more about how we process your personal data, please read
34
+ our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
35
+ pipeline_tag: image-text-to-text
36
+ ---
37
+ # Mistral-Small-3.2-24B-Instruct-2506
38
+
39
+ 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).
40
+
41
+ Small-3.2 improves in the following categories:
42
+ - **Instruction following**: Small-3.2 is better at following precise instructions
43
+ - **Repetition errors**: Small-3.2 produces less infinite generations or repetitive answers
44
+ - **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))
45
+
46
+ 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).
47
+
48
+ ## Key Features
49
+ - same as [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503#key-features)
50
+
51
+ ## Benchmark Results
52
+
53
+ 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).
54
+ 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)
55
+
56
+ ### Text
57
+
58
+ #### Instruction Following / Chat / Tone
59
+
60
+ | Model | Wildbench v2 | Arena Hard v2 | IF (Internal; accuracy) |
61
+ |-------|---------------|---------------|------------------------|
62
+ | Small 3.1 24B Instruct | 55.6% | 19.56% | 82.75% |
63
+ | **Small 3.2 24B Instruct** | **65.33%** | **43.1%** | **84.78%** |
64
+
65
+ #### Infinite Generations
66
+
67
+ Small 3.2 reduces infitine generations by 2x on challenging, long and repetitive prompts.
68
+
69
+ | Model | Infinite Generations (Internal; Lower is better) |
70
+ |-------|-------|
71
+ | Small 3.1 24B Instruct | 2.11% |
72
+ | **Small 3.2 24B Instruct** | **1.29%** |
73
+
74
+ #### STEM
75
+
76
+ | 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)|
77
+ |--------------------------------|-----------|-----------------------|------------------------|------------------------|---------------------------|--------------------|-------------------------|--------------------|
78
+ | Small 3.1 24B Instruct | 80.62% | 66.76% | 69.30% | 44.42% | 45.96% | 74.63% | 88.99% | 10.43% |
79
+ | **Small 3.2 24B Instruct** | 80.50% | **69.06%** | 69.42% | 44.22% | 46.13% | **78.33%** | **92.90%** | **12.10%** |
80
+
81
+ ### Vision
82
+
83
+ | Model | MMMU | Mathvista | ChartQA | DocVQA | AI2D |
84
+ |--------------------------------|------------|-----------|-----------|-----------|-----------|
85
+ | Small 3.1 24B Instruct | **64.00%** | **68.91%**| 86.24% | 94.08% | 93.72% |
86
+ | **Small 3.2 24B Instruct** | 62.50% | 67.09% | **87.4%** | 94.86% | 92.91% |
87
+
88
+
89
+ ## Usage
90
+
91
+ The model can be used with the following frameworks;
92
+ - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
93
+ - [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
94
+
95
+ **Note 1**: We recommend using a relatively low temperature, such as `temperature=0.15`.
96
+
97
+ **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.
98
+
99
+ ### vLLM (recommended)
100
+
101
+ We recommend using this model with [vLLM](https://github.com/vllm-project/vllm).
102
+
103
+ #### Installation
104
+
105
+ Make sure to install [`vLLM >= 0.9.1`](https://github.com/vllm-project/vllm/releases/tag/v0.9.1):
106
+
107
+ ```
108
+ pip install vllm --upgrade
109
+ ```
110
+
111
+ Doing so should automatically install [`mistral_common >= 1.6.2`](https://github.com/mistralai/mistral-common/releases/tag/v1.6.2).
112
+
113
+ To check:
114
+ ```
115
+ python -c "import mistral_common; print(mistral_common.__version__)"
116
+ ```
117
+
118
+ 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).
119
+
120
+ #### Serve
121
+
122
+ We recommand that you use Mistral-Small-3.2-24B-Instruct-2506 in a server/client setting.
123
+
124
+ 1. Spin up a server:
125
+
126
+ ```
127
+ 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
128
+ ```
129
+
130
+ **Note:** Running Mistral-Small-3.2-24B-Instruct-2506 on GPU requires ~55 GB of GPU RAM in bf16 or fp16.
131
+
132
+
133
+ 2. To ping the client you can use a simple Python snippet. See the following examples.
134
+
135
+
136
+ #### Vision reasoning
137
+
138
+ 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 !
139
+
140
+ <details>
141
+ <summary>Python snippet</summary>
142
+
143
+ ```py
144
+ from datetime import datetime, timedelta
145
+ from openai import OpenAI
146
+ from huggingface_hub import hf_hub_download
147
+ # Modify OpenAI's API key and API base to use vLLM's API server.
148
+ openai_api_key = "EMPTY"
149
+ openai_api_base = "http://localhost:8000/v1"
150
+ TEMP = 0.15
151
+ MAX_TOK = 131072
152
+ client = OpenAI(
153
+ api_key=openai_api_key,
154
+ base_url=openai_api_base,
155
+ )
156
+ models = client.models.list()
157
+ model = models.data[0].id
158
+ def load_system_prompt(repo_id: str, filename: str) -> str:
159
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
160
+ with open(file_path, "r") as file:
161
+ system_prompt = file.read()
162
+ today = datetime.today().strftime("%Y-%m-%d")
163
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
164
+ model_name = repo_id.split("/")[-1]
165
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
166
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
167
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
168
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
169
+ messages = [
170
+ {"role": "system", "content": SYSTEM_PROMPT},
171
+ {
172
+ "role": "user",
173
+ "content": [
174
+ {
175
+ "type": "text",
176
+ "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.",
177
+ },
178
+ {"type": "image_url", "image_url": {"url": image_url}},
179
+ ],
180
+ },
181
+ ]
182
+ response = client.chat.completions.create(
183
+ model=model,
184
+ messages=messages,
185
+ temperature=TEMP,
186
+ max_tokens=MAX_TOK,
187
+ )
188
+ print(response.choices[0].message.content)
189
+ # 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:
190
+ # 1. **FIGHT**:
191
+ # - **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.
192
+ # - **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.
193
+ # 2. **BAG**:
194
+ # - **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.
195
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat the Pidgey quickly.
196
+ # 3. **POKÉMON**:
197
+ # - **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.
198
+ # - **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.
199
+ # 4. **RUN**:
200
+ # - **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.
201
+ # - **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.
202
+ # ### Recommendation:
203
+ # 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.
204
+ ```
205
+ </details>
206
+
207
+ #### Function calling
208
+
209
+ Mistral-Small-3.2-24B-Instruct-2506 is excellent at function / tool calling tasks via vLLM. *E.g.:*
210
+
211
+ <details>
212
+ <summary>Python snippet - easy</summary>
213
+
214
+ ```py
215
+ from openai import OpenAI
216
+ from huggingface_hub import hf_hub_download
217
+ # Modify OpenAI's API key and API base to use vLLM's API server.
218
+ openai_api_key = "EMPTY"
219
+ openai_api_base = "http://localhost:8000/v1"
220
+ TEMP = 0.15
221
+ MAX_TOK = 131072
222
+ client = OpenAI(
223
+ api_key=openai_api_key,
224
+ base_url=openai_api_base,
225
+ )
226
+ models = client.models.list()
227
+ model = models.data[0].id
228
+ def load_system_prompt(repo_id: str, filename: str) -> str:
229
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
230
+ with open(file_path, "r") as file:
231
+ system_prompt = file.read()
232
+ return system_prompt
233
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
234
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
235
+ image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
236
+ tools = [
237
+ {
238
+ "type": "function",
239
+ "function": {
240
+ "name": "get_current_population",
241
+ "description": "Get the up-to-date population of a given country.",
242
+ "parameters": {
243
+ "type": "object",
244
+ "properties": {
245
+ "country": {
246
+ "type": "string",
247
+ "description": "The country to find the population of.",
248
+ },
249
+ "unit": {
250
+ "type": "string",
251
+ "description": "The unit for the population.",
252
+ "enum": ["millions", "thousands"],
253
+ },
254
+ },
255
+ "required": ["country", "unit"],
256
+ },
257
+ },
258
+ },
259
+ {
260
+ "type": "function",
261
+ "function": {
262
+ "name": "rewrite",
263
+ "description": "Rewrite a given text for improved clarity",
264
+ "parameters": {
265
+ "type": "object",
266
+ "properties": {
267
+ "text": {
268
+ "type": "string",
269
+ "description": "The input text to rewrite",
270
+ }
271
+ },
272
+ },
273
+ },
274
+ },
275
+ ]
276
+ messages = [
277
+ {"role": "system", "content": SYSTEM_PROMPT},
278
+ {
279
+ "role": "user",
280
+ "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.",
281
+ },
282
+ {
283
+ "role": "assistant",
284
+ "content": "",
285
+ "tool_calls": [
286
+ {
287
+ "id": "bbc5b7ede",
288
+ "type": "function",
289
+ "function": {
290
+ "name": "rewrite",
291
+ "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."}',
292
+ },
293
+ }
294
+ ],
295
+ },
296
+ {
297
+ "role": "tool",
298
+ "content": '{"action":"rewrite","outcome":"OpenAI is a FOR-profit company."}',
299
+ "tool_call_id": "bbc5b7ede",
300
+ "name": "rewrite",
301
+ },
302
+ {
303
+ "role": "assistant",
304
+ "content": "---\n\nOpenAI is a FOR-profit company.",
305
+ },
306
+ {
307
+ "role": "user",
308
+ "content": [
309
+ {
310
+ "type": "text",
311
+ "text": "Can you tell me what is the biggest country depicted on the map?",
312
+ },
313
+ {
314
+ "type": "image_url",
315
+ "image_url": {
316
+ "url": image_url,
317
+ },
318
+ },
319
+ ],
320
+ }
321
+ ]
322
+ response = client.chat.completions.create(
323
+ model=model,
324
+ messages=messages,
325
+ temperature=TEMP,
326
+ max_tokens=MAX_TOK,
327
+ tools=tools,
328
+ tool_choice="auto",
329
+ )
330
+ assistant_message = response.choices[0].message.content
331
+ print(assistant_message)
332
+ # The biggest country depicted on the map is Russia.
333
+ messages.extend([
334
+ {"role": "assistant", "content": assistant_message},
335
+ {"role": "user", "content": "What is the population of that country in millions?"},
336
+ ])
337
+ response = client.chat.completions.create(
338
+ model=model,
339
+ messages=messages,
340
+ temperature=TEMP,
341
+ max_tokens=MAX_TOK,
342
+ tools=tools,
343
+ tool_choice="auto",
344
+ )
345
+ print(response.choices[0].message.tool_calls)
346
+ # [ChatCompletionMessageToolCall(id='3e92V6Vfo', function=Function(arguments='{"country": "Russia", "unit": "millions"}', name='get_current_population'), type='function')]
347
+ ```
348
+
349
+ </details>
350
+
351
+ <details>
352
+ <summary>Python snippet - complex</summary>
353
+
354
+ ```python
355
+ import json
356
+ from openai import OpenAI
357
+ from huggingface_hub import hf_hub_download
358
+ # Modify OpenAI's API key and API base to use vLLM's API server.
359
+ openai_api_key = "EMPTY"
360
+ openai_api_base = "http://localhost:8000/v1"
361
+ TEMP = 0.15
362
+ MAX_TOK = 131072
363
+ client = OpenAI(
364
+ api_key=openai_api_key,
365
+ base_url=openai_api_base,
366
+ )
367
+ models = client.models.list()
368
+ model = models.data[0].id
369
+ def load_system_prompt(repo_id: str, filename: str) -> str:
370
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
371
+ with open(file_path, "r") as file:
372
+ system_prompt = file.read()
373
+ return system_prompt
374
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
375
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
376
+ image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
377
+ def my_calculator(expression: str) -> str:
378
+ return str(eval(expression))
379
+ tools = [
380
+ {
381
+ "type": "function",
382
+ "function": {
383
+ "name": "my_calculator",
384
+ "description": "A calculator that can evaluate a mathematical expression.",
385
+ "parameters": {
386
+ "type": "object",
387
+ "properties": {
388
+ "expression": {
389
+ "type": "string",
390
+ "description": "The mathematical expression to evaluate.",
391
+ },
392
+ },
393
+ "required": ["expression"],
394
+ },
395
+ },
396
+ },
397
+ {
398
+ "type": "function",
399
+ "function": {
400
+ "name": "rewrite",
401
+ "description": "Rewrite a given text for improved clarity",
402
+ "parameters": {
403
+ "type": "object",
404
+ "properties": {
405
+ "text": {
406
+ "type": "string",
407
+ "description": "The input text to rewrite",
408
+ }
409
+ },
410
+ },
411
+ },
412
+ },
413
+ ]
414
+ messages = [
415
+ {"role": "system", "content": SYSTEM_PROMPT},
416
+ {
417
+ "role": "user",
418
+ "content": [
419
+ {
420
+ "type": "text",
421
+ "text": "Can you calculate the results for all the equations displayed in the image? Only compute the ones that involve numbers.",
422
+ },
423
+ {
424
+ "type": "image_url",
425
+ "image_url": {
426
+ "url": image_url,
427
+ },
428
+ },
429
+ ],
430
+ },
431
+ ]
432
+ response = client.chat.completions.create(
433
+ model=model,
434
+ messages=messages,
435
+ temperature=TEMP,
436
+ max_tokens=MAX_TOK,
437
+ tools=tools,
438
+ tool_choice="auto",
439
+ )
440
+ tool_calls = response.choices[0].message.tool_calls
441
+ print(tool_calls)
442
+ # [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')]
443
+ results = []
444
+ for tool_call in tool_calls:
445
+ function_name = tool_call.function.name
446
+ function_args = tool_call.function.arguments
447
+ if function_name == "my_calculator":
448
+ result = my_calculator(**json.loads(function_args))
449
+ results.append(result)
450
+ messages.append({"role": "assistant", "tool_calls": tool_calls})
451
+ for tool_call, result in zip(tool_calls, results):
452
+ messages.append(
453
+ {
454
+ "role": "tool",
455
+ "tool_call_id": tool_call.id,
456
+ "name": tool_call.function.name,
457
+ "content": result,
458
+ }
459
+ )
460
+ response = client.chat.completions.create(
461
+ model=model,
462
+ messages=messages,
463
+ temperature=TEMP,
464
+ max_tokens=MAX_TOK,
465
+ )
466
+ print(response.choices[0].message.content)
467
+ # Here are the results for the equations that involve numbers:
468
+ # 1. \( 6 + 2 \times 3 = 12 \)
469
+ # 3. \( 19 - (8 + 2) + 1 = 10 \)
470
+ # For the other equations, you need to substitute the variables with specific values to compute the results.
471
+ ```
472
+
473
+ </details>
474
+
475
+ #### Instruction following
476
+
477
+ Mistral-Small-3.2-24B-Instruct-2506 will follow your instructions down to the last letter !
478
+
479
+ <details>
480
+ <summary>Python snippet</summary>
481
+
482
+ ```python
483
+ from openai import OpenAI
484
+ from huggingface_hub import hf_hub_download
485
+ # Modify OpenAI's API key and API base to use vLLM's API server.
486
+ openai_api_key = "EMPTY"
487
+ openai_api_base = "http://localhost:8000/v1"
488
+ TEMP = 0.15
489
+ MAX_TOK = 131072
490
+ client = OpenAI(
491
+ api_key=openai_api_key,
492
+ base_url=openai_api_base,
493
+ )
494
+ models = client.models.list()
495
+ model = models.data[0].id
496
+ def load_system_prompt(repo_id: str, filename: str) -> str:
497
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
498
+ with open(file_path, "r") as file:
499
+ system_prompt = file.read()
500
+ return system_prompt
501
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
502
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
503
+ messages = [
504
+ {"role": "system", "content": SYSTEM_PROMPT},
505
+ {
506
+ "role": "user",
507
+ "content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
508
+ },
509
+ ]
510
+ response = client.chat.completions.create(
511
+ model=model,
512
+ messages=messages,
513
+ temperature=TEMP,
514
+ max_tokens=MAX_TOK,
515
+ )
516
+ assistant_message = response.choices[0].message.content
517
+ print(assistant_message)
518
+ # Here's a sentence where each word starts with the next letter of the alphabet, starting from 'a' and ending with 'z':
519
+ # "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."
520
+ # This sentence follows the sequence from A to Z without skipping any letters.
521
+ ```
522
+ </details>
523
+
524
+ ### Transformers
525
+
526
+ You can also use Mistral-Small-3.2-24B-Instruct-2506 with `Transformers` !
527
+
528
+ 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.
529
+
530
+ ```bash
531
+ pip install mistral-common --upgrade
532
+ ```
533
+
534
+ Then load our tokenizer along with the model and generate:
535
+
536
+ <details>
537
+ <summary>Python snippet</summary>
538
+
539
+ ```python
540
+ from datetime import datetime, timedelta
541
+ import torch
542
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
543
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
544
+ from huggingface_hub import hf_hub_download
545
+ from transformers import Mistral3ForConditionalGeneration
546
+ def load_system_prompt(repo_id: str, filename: str) -> str:
547
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
548
+ with open(file_path, "r") as file:
549
+ system_prompt = file.read()
550
+ today = datetime.today().strftime("%Y-%m-%d")
551
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
552
+ model_name = repo_id.split("/")[-1]
553
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
554
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
555
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
556
+ tokenizer = MistralTokenizer.from_hf_hub(model_id)
557
+ model = Mistral3ForConditionalGeneration.from_pretrained(
558
+ model_id, torch_dtype=torch.bfloat16
559
+ )
560
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
561
+ messages = [
562
+ {"role": "system", "content": SYSTEM_PROMPT},
563
+ {
564
+ "role": "user",
565
+ "content": [
566
+ {
567
+ "type": "text",
568
+ "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.",
569
+ },
570
+ {"type": "image_url", "image_url": {"url": image_url}},
571
+ ],
572
+ },
573
+ ]
574
+ tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
575
+ input_ids = torch.tensor([tokenized.tokens])
576
+ attention_mask = torch.ones_like(input_ids)
577
+ pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
578
+ image_sizes = torch.tensor([pixel_values.shape[-2:]])
579
+ output = model.generate(
580
+ input_ids=input_ids,
581
+ attention_mask=attention_mask,
582
+ pixel_values=pixel_values,
583
+ image_sizes=image_sizes,
584
+ max_new_tokens=1000,
585
+ )[0]
586
+ decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
587
+ print(decoded_output)
588
+ # 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:
589
+ # 1. **FIGHT**:
590
+ # - **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.
591
+ # - **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.
592
+ # 2. **BAG**:
593
+ # - **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.
594
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
595
+ # 3. **POKÉMON**:
596
+ # - **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.
597
+ # - **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.
598
+ # 4. **RUN**:
599
+ # - **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.
600
+ # - **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.
601
+ # ### Recommendation:
602
+ # 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.
603
+ ```
604
+
605
+ </details>