hehua2008 commited on
Commit
86fb24b
·
verified ·
1 Parent(s): 32468fd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +463 -199
README.md CHANGED
@@ -36,144 +36,81 @@ tags:
36
  - mistral-common
37
  ---
38
 
39
- # Model Card for Mistral-Small-3.1-24B-Instruct-2503
40
 
41
- Building upon Mistral Small 3 (2501), Mistral Small 3.1 (2503) **adds state-of-the-art vision understanding** and enhances **long context capabilities up to 128k tokens** without compromising text performance.
42
- With 24 billion parameters, this model achieves top-tier capabilities in both text and vision tasks.
43
- This model is an instruction-finetuned version of: [Mistral-Small-3.1-24B-Base-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Base-2503).
44
 
45
- Mistral Small 3.1 can be deployed locally and is exceptionally "knowledge-dense," fitting within a single RTX 4090 or a 32GB RAM MacBook once quantized.
 
 
 
46
 
47
- It is ideal for:
48
- - Fast-response conversational agents.
49
- - Low-latency function calling.
50
- - Subject matter experts via fine-tuning.
51
- - Local inference for hobbyists and organizations handling sensitive data.
52
- - Programming and math reasoning.
53
- - Long document understanding.
54
- - Visual understanding.
55
-
56
- For enterprises requiring specialized capabilities (increased context, specific modalities, domain-specific knowledge, etc.), we will release commercial models beyond what Mistral AI contributes to the community.
57
-
58
- Learn more about Mistral Small 3.1 in our [blog post](https://mistral.ai/news/mistral-small-3-1/).
59
 
60
  ## Key Features
61
- - **Vision:** Vision capabilities enable the model to analyze images and provide insights based on visual content in addition to text.
62
- - **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, Farsi.
63
- - **Agent-Centric:** Offers best-in-class agentic capabilities with native function calling and JSON outputting.
64
- - **Advanced Reasoning:** State-of-the-art conversational and reasoning capabilities.
65
- - **Apache 2.0 License:** Open license allowing usage and modification for both commercial and non-commercial purposes.
66
- - **Context Window:** A 128k context window.
67
- - **System Prompt:** Maintains strong adherence and support for system prompts.
68
- - **Tokenizer:** Utilizes a Tekken tokenizer with a 131k vocabulary size.
69
 
70
  ## Benchmark Results
71
 
72
- When available, we report numbers previously published by other model providers, otherwise we re-evaluate them using our own evaluation harness.
73
-
74
- ### Pretrain Evals
75
 
76
- | Model | MMLU (5-shot) | MMLU Pro (5-shot CoT) | TriviaQA | GPQA Main (5-shot CoT)| MMMU |
77
- |--------------------------------|---------------|-----------------------|------------|-----------------------|-----------|
78
- | **Small 3.1 24B Base** | **81.01%** | **56.03%** | 80.50% | **37.50%** | **59.27%**|
79
- | Gemma 3 27B PT | 78.60% | 52.20% | **81.30%** | 24.30% | 56.10% |
80
 
81
- ### Instruction Evals
82
 
83
- #### Text
 
 
 
84
 
85
- | Model | MMLU | MMLU Pro (5-shot CoT) | MATH | GPQA Main (5-shot CoT) | GPQA Diamond (5-shot CoT )| MBPP | HumanEval | SimpleQA (TotalAcc)|
86
- |--------------------------------|-----------|-----------------------|------------------------|------------------------|---------------------------|-----------|-----------|--------------------|
87
- | **Small 3.1 24B Instruct** | 80.62% | 66.76% | 69.30% | **44.42%** | **45.96%** | 74.71% | **88.41%**| **10.43%** |
88
- | Gemma 3 27B IT | 76.90% | **67.50%** | **89.00%** | 36.83% | 42.40% | 74.40% | 87.80% | 10.00% |
89
- | GPT4o Mini | **82.00%**| 61.70% | 70.20% | 40.20% | 39.39% | 84.82% | 87.20% | 9.50% |
90
- | Claude 3.5 Haiku | 77.60% | 65.00% | 69.20% | 37.05% | 41.60% | **85.60%**| 88.10% | 8.02% |
91
- | Cohere Aya-Vision 32B | 72.14% | 47.16% | 41.98% | 34.38% | 33.84% | 70.43% | 62.20% | 7.65% |
92
 
93
- #### Vision
94
 
95
- | Model | MMMU | MMMU PRO | Mathvista | ChartQA | DocVQA | AI2D | MM MT Bench |
96
- |--------------------------------|------------|-----------|-----------|-----------|-----------|-------------|-------------|
97
- | **Small 3.1 24B Instruct** | 64.00% | **49.25%**| **68.91%**| 86.24% | **94.08%**| **93.72%** | **7.3** |
98
- | Gemma 3 27B IT | **64.90%** | 48.38% | 67.60% | 76.00% | 86.60% | 84.50% | 7 |
99
- | GPT4o Mini | 59.40% | 37.60% | 56.70% | 76.80% | 86.70% | 88.10% | 6.6 |
100
- | Claude 3.5 Haiku | 60.50% | 45.03% | 61.60% | **87.20%**| 90.00% | 92.10% | 6.5 |
101
- | Cohere Aya-Vision 32B | 48.20% | 31.50% | 50.10% | 63.04% | 72.40% | 82.57% | 4.1 |
102
 
103
- ### Multilingual Evals
104
 
105
- | Model | Average | European | East Asian | Middle Eastern |
106
- |--------------------------------|------------|------------|------------|----------------|
107
- | **Small 3.1 24B Instruct** | **71.18%** | **75.30%** | **69.17%** | 69.08% |
108
- | Gemma 3 27B IT | 70.19% | 74.14% | 65.65% | 70.76% |
109
- | GPT4o Mini | 70.36% | 74.21% | 65.96% | **70.90%** |
110
- | Claude 3.5 Haiku | 70.16% | 73.45% | 67.05% | 70.00% |
111
- | Cohere Aya-Vision 32B | 62.15% | 64.70% | 57.61% | 64.12% |
112
 
113
- ### Long Context Evals
114
 
115
- | Model | LongBench v2 | RULER 32K | RULER 128K |
116
- |--------------------------------|-----------------|-------------|------------|
117
- | **Small 3.1 24B Instruct** | **37.18%** | **93.96%** | 81.20% |
118
- | Gemma 3 27B IT | 34.59% | 91.10% | 66.00% |
119
- | GPT4o Mini | 29.30% | 90.20% | 65.8% |
120
- | Claude 3.5 Haiku | 35.19% | 92.60% | **91.90%** |
121
-
122
- ## Basic Instruct Template (V7-Tekken)
123
-
124
- ```
125
- <s>[SYSTEM_PROMPT]<system prompt>[/SYSTEM_PROMPT][INST]<user message>[/INST]<assistant response></s>[INST]<user message>[/INST]
126
- ```
127
- *`<system_prompt>`, `<user message>` and `<assistant response>` are placeholders.*
128
 
129
- ***Please make sure to use [mistral-common](https://github.com/mistralai/mistral-common) as the source of truth***
130
 
131
  ## Usage
132
 
133
  The model can be used with the following frameworks;
134
- - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm)
 
135
 
136
  **Note 1**: We recommend using a relatively low temperature, such as `temperature=0.15`.
137
 
138
- **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 the following
139
- system prompt:
140
-
141
- ```
142
- system_prompt = """You are Mistral Small 3.1, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.
143
- You power an AI assistant called Le Chat.
144
- Your knowledge base was last updated on 2023-10-01.
145
- The current date is {today}.
146
-
147
- When you're not sure about some information, you say that you don't have the information and don't make up anything.
148
- If the user's question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. "What are some good restaurants around me?" => "Where are you?" or "When is the next flight to Tokyo" => "Where do you travel from?").
149
- You are always very attentive to dates, in particular you try to resolve dates (e.g. "yesterday" is {yesterday}) and when asked about information at specific dates, you discard information that is at another date.
150
- You follow these instructions in all languages, and always respond to the user in the language they use or request.
151
- Next sections describe the capabilities that you have.
152
-
153
- # WEB BROWSING INSTRUCTIONS
154
-
155
- You cannot perform any web search or access internet to open URLs, links etc. If it seems like the user is expecting you to do so, you clarify the situation and ask the user to copy paste the text directly in the chat.
156
-
157
- # MULTI-MODAL INSTRUCTIONS
158
-
159
- You have the ability to read images, but you cannot generate images.
160
- You cannot read nor transcribe audio files or videos."""
161
- ```
162
 
163
  ### vLLM (recommended)
164
 
165
- We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
166
- to implement production-ready inference pipelines.
167
 
168
- **_Installation_**
169
 
170
- Make sure you install [`vLLM >= 0.8.1`](https://github.com/vllm-project/vllm/releases/tag/v0.8.1):
171
 
172
  ```
173
  pip install vllm --upgrade
174
  ```
175
 
176
- Doing so should automatically install [`mistral_common >= 1.5.4`](https://github.com/mistralai/mistral-common/releases/tag/v1.5.4).
177
 
178
  To check:
179
  ```
@@ -182,31 +119,53 @@ python -c "import mistral_common; print(mistral_common.__version__)"
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
- #### Server
186
 
187
- We recommand that you use Mistral-Small-3.1-24B-Instruct-2503 in a server/client setting.
188
 
189
  1. Spin up a server:
190
 
191
  ```
192
- vllm serve mistralai/Mistral-Small-3.1-24B-Instruct-2503 --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
 
 
 
 
193
  ```
194
 
195
- **Note:** Running Mistral-Small-3.1-24B-Instruct-2503 on GPU requires ~55 GB of GPU RAM in bf16 or fp16.
 
 
 
 
196
 
 
197
 
198
- 2. To ping the client you can use a simple Python snippet.
 
 
 
199
 
200
  ```py
201
- import requests
202
- import json
203
- from huggingface_hub import hf_hub_download
204
  from datetime import datetime, timedelta
205
 
206
- url = "http://<your-server-url>:8000/v1/chat/completions"
207
- headers = {"Content-Type": "application/json", "Authorization": "Bearer token"}
 
 
 
 
208
 
209
- model = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
 
 
 
 
 
 
 
 
 
210
 
211
 
212
  def load_system_prompt(repo_id: str, filename: str) -> str:
@@ -219,9 +178,9 @@ def load_system_prompt(repo_id: str, filename: str) -> str:
219
  return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
220
 
221
 
222
- SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
223
-
224
- image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
225
 
226
  messages = [
227
  {"role": "system", "content": SYSTEM_PROMPT},
@@ -230,93 +189,102 @@ messages = [
230
  "content": [
231
  {
232
  "type": "text",
233
- "text": "Which of the depicted countries has the best food? Which the second and third and fourth? Name the country, its color on the map and one its city that is visible on the map, but is not the capital. Make absolutely sure to only name a city that can be seen on the map.",
234
  },
235
  {"type": "image_url", "image_url": {"url": image_url}},
236
  ],
237
  },
238
  ]
239
 
240
- data = {"model": model, "messages": messages, "temperature": 0.15}
241
 
242
- response = requests.post(url, headers=headers, data=json.dumps(data))
243
- print(response.json()["choices"][0]["message"]["content"])
244
- # Determining the "best" food is highly subjective and depends on personal preferences. However, based on general popularity and recognition, here are some countries known for their cuisine:
 
 
 
245
 
246
- # 1. **Italy** - Color: Light Green - City: Milan
247
- # - Italian cuisine is renowned worldwide for its pasta, pizza, and various regional specialties.
248
 
249
- # 2. **France** - Color: Brown - City: Lyon
250
- # - French cuisine is celebrated for its sophistication, including dishes like coq au vin, bouillabaisse, and pastries like croissants and éclairs.
 
251
 
252
- # 3. **Spain** - Color: Yellow - City: Bilbao
253
- # - Spanish cuisine offers a variety of flavors, from paella and tapas to jamón ibérico and churros.
 
254
 
255
- # 4. **Greece** - Not visible on the map
256
- # - Greek cuisine is known for dishes like moussaka, souvlaki, and baklava. Unfortunately, Greece is not visible on the provided map, so I cannot name a city.
 
257
 
258
- # Since Greece is not visible on the map, I'll replace it with another country known for its good food:
 
 
259
 
260
- # 4. **Turkey** - Color: Light Green (east part of the map) - City: Istanbul
261
- # - Turkish cuisine is diverse and includes dishes like kebabs, meze, and baklava.
262
  ```
 
263
 
264
- ### Function calling
265
 
266
- Mistral-Small-3.1-24-Instruct-2503 is excellent at function / tool calling tasks via vLLM. *E.g.:*
267
 
268
  <details>
269
- <summary>Example</summary>
270
 
271
  ```py
272
- import requests
273
- import json
274
  from huggingface_hub import hf_hub_download
275
- from datetime import datetime, timedelta
276
 
277
- url = "http://<your-url>:8000/v1/chat/completions"
278
- headers = {"Content-Type": "application/json", "Authorization": "Bearer token"}
 
 
 
 
279
 
280
- model = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
 
 
 
281
 
 
 
282
 
283
  def load_system_prompt(repo_id: str, filename: str) -> str:
284
  file_path = hf_hub_download(repo_id=repo_id, filename=filename)
285
  with open(file_path, "r") as file:
286
  system_prompt = file.read()
287
- today = datetime.today().strftime("%Y-%m-%d")
288
- yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
289
- model_name = repo_id.split("/")[-1]
290
- return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
291
 
 
 
292
 
293
- SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
294
-
295
 
296
  tools = [
297
  {
298
  "type": "function",
299
  "function": {
300
- "name": "get_current_weather",
301
- "description": "Get the current weather in a given location",
302
  "parameters": {
303
  "type": "object",
304
  "properties": {
305
- "city": {
306
- "type": "string",
307
- "description": "The city to find the weather for, e.g. 'San Francisco'",
308
- },
309
- "state": {
310
  "type": "string",
311
- "description": "The state abbreviation, e.g. 'CA' for California",
312
  },
313
  "unit": {
314
  "type": "string",
315
- "description": "The unit for temperature",
316
- "enum": ["celsius", "fahrenheit"],
317
  },
318
  },
319
- "required": ["city", "state", "unit"],
320
  },
321
  },
322
  },
@@ -370,65 +338,361 @@ messages = [
370
  },
371
  {
372
  "role": "user",
373
- "content": "Can you tell me what the temperature will be in Dallas, in Fahrenheit?",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  },
375
  ]
376
 
377
- data = {"model": model, "messages": messages, "tools": tools, "temperature": 0.15}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
 
379
- response = requests.post(url, headers=headers, data=json.dumps(data))
380
- print(response.json()["choices"][0]["message"]["tool_calls"])
381
- # [{'id': '8PdihwL6d', 'type': 'function', 'function': {'name': 'get_current_weather', 'arguments': '{"city": "Dallas", "state": "TX", "unit": "fahrenheit"}'}}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  ```
383
 
384
  </details>
385
 
386
- #### Offline
387
 
388
- ```py
389
- from vllm import LLM
390
- from vllm.sampling_params import SamplingParams
391
- from datetime import datetime, timedelta
392
 
393
- SYSTEM_PROMPT = "You are a conversational agent that always answers straight to the point, always end your accurate response with an ASCII drawing of a cat."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
 
395
- user_prompt = "Give me 5 non-formal ways to say 'See you later' in French."
 
 
 
 
 
 
 
 
 
 
 
 
396
 
397
  messages = [
 
398
  {
399
- "role": "system",
400
- "content": SYSTEM_PROMPT
401
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  {
403
  "role": "user",
404
- "content": user_prompt
 
 
 
 
 
 
405
  },
406
  ]
407
- model_name = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
408
- # note that running this model on GPU requires over 60 GB of GPU RAM
409
- llm = LLM(model=model_name, tokenizer_mode="mistral")
410
-
411
- sampling_params = SamplingParams(max_tokens=512, temperature=0.15)
412
- outputs = llm.chat(messages, sampling_params=sampling_params)
413
-
414
- print(outputs[0].outputs[0].text)
415
- # Here are five non-formal ways to say "See you later" in French:
416
-
417
- # 1. **À plus tard** - Until later
418
- # 2. **À toute** - See you soon (informal)
419
- # 3. **Salut** - Bye (can also mean hi)
420
- # 4. **À plus** - See you later (informal)
421
- # 5. **Ciao** - Bye (informal, borrowed from Italian)
422
-
423
- # ```
424
- # /\_/\
425
- # ( o.o )
426
- # > ^ <
427
- # ```
428
- ```
429
 
430
- ### Transformers (untested)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
 
432
- Transformers-compatible model weights are also uploaded (thanks a lot @cyrilvallez).
433
- However the transformers implementation was **not throughly tested**, but only on "vibe-checks".
434
- Hence, we can only ensure 100% correct behavior when using the original weight format with vllm (see above).
 
36
  - mistral-common
37
  ---
38
 
39
+ # Mistral-Small-3.2-24B-Instruct-2506
40
 
41
+ 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-Instruct-2503).
 
 
42
 
43
+ Small-3.2 improves in the following categories:
44
+ - **Instruction following**: Small-3.2 is better at following precise instructions
45
+ - **Repetition errors**: Small-3.2 produces less infinite generations or repetitive answers
46
+ - **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))
47
 
48
+ 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-Instruct-2503).
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ## Key Features
51
+ - same as [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#key-features)
 
 
 
 
 
 
 
52
 
53
  ## Benchmark Results
54
 
55
+ We compare Mistral-Small-3.2-24B to [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503).
56
+ 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-Instruct-2503#benchmark-results)
 
57
 
58
+ ### Text
 
 
 
59
 
60
+ #### Instruction Following / Chat / Tone
61
 
62
+ | Model | Wildbench v2 | Arena Hard v2 | IF (Internal; accuracy) |
63
+ |-------|---------------|---------------|------------------------|
64
+ | Small 3.1 24B Instruct | 55.6% | 19.56% | 82.75% |
65
+ | **Small 3.2 24B Instruct** | **65.33%** | **43.1%** | **84.78%** |
66
 
67
+ #### Infinite Generations
 
 
 
 
 
 
68
 
69
+ Small 3.2 reduces infinite generations by 2x on challenging, long and repetitive prompts.
70
 
71
+ | Model | Infinite Generations (Internal; Lower is better) |
72
+ |-------|-------|
73
+ | Small 3.1 24B Instruct | 2.11% |
74
+ | **Small 3.2 24B Instruct** | **1.29%** |
 
 
 
75
 
76
+ #### STEM
77
 
78
+ | 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)|
79
+ |--------------------------------|-----------|-----------------------|------------------------|------------------------|---------------------------|--------------------|-------------------------|--------------------|
80
+ | Small 3.1 24B Instruct | 80.62% | 66.76% | 69.30% | 44.42% | 45.96% | 74.63% | 88.99% | 10.43% |
81
+ | **Small 3.2 24B Instruct** | 80.50% | **69.06%** | 69.42% | 44.22% | 46.13% | **78.33%** | **92.90%** | **12.10%** |
 
 
 
82
 
83
+ ### Vision
84
 
85
+ | Model | MMMU | Mathvista | ChartQA | DocVQA | AI2D |
86
+ |--------------------------------|------------|-----------|-----------|-----------|-----------|
87
+ | Small 3.1 24B Instruct | **64.00%** | **68.91%**| 86.24% | 94.08% | 93.72% |
88
+ | **Small 3.2 24B Instruct** | 62.50% | 67.09% | **87.4%** | 94.86% | 92.91% |
 
 
 
 
 
 
 
 
 
89
 
 
90
 
91
  ## Usage
92
 
93
  The model can be used with the following frameworks;
94
+ - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
95
+ - [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
96
 
97
  **Note 1**: We recommend using a relatively low temperature, such as `temperature=0.15`.
98
 
99
+ **Note 2**: Make sure to add a system prompt to the model to best tailor it to 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  ### vLLM (recommended)
102
 
103
+ We recommend using this model with [vLLM](https://github.com/vllm-project/vllm).
 
104
 
105
+ #### Installation
106
 
107
+ Make sure to install [`vLLM >= 0.9.1`](https://github.com/vllm-project/vllm/releases/tag/v0.9.1):
108
 
109
  ```
110
  pip install vllm --upgrade
111
  ```
112
 
113
+ Doing so should automatically install [`mistral_common >= 1.6.2`](https://github.com/mistralai/mistral-common/releases/tag/v1.6.2).
114
 
115
  To check:
116
  ```
 
119
 
120
  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).
121
 
122
+ #### Serve
123
 
124
+ We recommend that you use Mistral-Small-3.2-24B-Instruct-2506 in a server/client setting.
125
 
126
  1. Spin up a server:
127
 
128
  ```
129
+ vllm serve mistralai/Mistral-Small-3.2-24B-Instruct-2506 \
130
+ --tokenizer_mode mistral --config_format mistral \
131
+ --load_format mistral --tool-call-parser mistral \
132
+ --enable-auto-tool-choice --limit-mm-per-prompt '{"image":10}' \
133
+ --tensor-parallel-size 2
134
  ```
135
 
136
+ **Note:** Running Mistral-Small-3.2-24B-Instruct-2506 on GPU requires ~55 GB of GPU RAM in bf16 or fp16.
137
+
138
+
139
+ 2. To ping the client you can use a simple Python snippet. See the following examples.
140
+
141
 
142
+ #### Vision reasoning
143
 
144
+ Leverage the vision capabilities of Mistral-Small-3.2-24B-Instruct-2506 to make the best choice given a scenario, go catch them all !
145
+
146
+ <details>
147
+ <summary>Python snippet</summary>
148
 
149
  ```py
 
 
 
150
  from datetime import datetime, timedelta
151
 
152
+ from openai import OpenAI
153
+ from huggingface_hub import hf_hub_download
154
+
155
+ # Modify OpenAI's API key and API base to use vLLM's API server.
156
+ openai_api_key = "EMPTY"
157
+ openai_api_base = "http://localhost:8000/v1"
158
 
159
+ TEMP = 0.15
160
+ MAX_TOK = 131072
161
+
162
+ client = OpenAI(
163
+ api_key=openai_api_key,
164
+ base_url=openai_api_base,
165
+ )
166
+
167
+ models = client.models.list()
168
+ model = models.data[0].id
169
 
170
 
171
  def load_system_prompt(repo_id: str, filename: str) -> str:
 
178
  return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
179
 
180
 
181
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
182
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
183
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
184
 
185
  messages = [
186
  {"role": "system", "content": SYSTEM_PROMPT},
 
189
  "content": [
190
  {
191
  "type": "text",
192
+ "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.",
193
  },
194
  {"type": "image_url", "image_url": {"url": image_url}},
195
  ],
196
  },
197
  ]
198
 
 
199
 
200
+ response = client.chat.completions.create(
201
+ model=model,
202
+ messages=messages,
203
+ temperature=TEMP,
204
+ max_tokens=MAX_TOK,
205
+ )
206
 
207
+ print(response.choices[0].message.content)
208
+ # 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:
209
 
210
+ # 1. **FIGHT**:
211
+ # - **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.
212
+ # - **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.
213
 
214
+ # 2. **BAG**:
215
+ # - **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.
216
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat the Pidgey quickly.
217
 
218
+ # 3. **POKÉMON**:
219
+ # - **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.
220
+ # - **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.
221
 
222
+ # 4. **RUN**:
223
+ # - **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.
224
+ # - **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.
225
 
226
+ # ### Recommendation:
227
+ # 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.
228
  ```
229
+ </details>
230
 
231
+ #### Function calling
232
 
233
+ Mistral-Small-3.2-24B-Instruct-2506 is excellent at function / tool calling tasks via vLLM. *E.g.:*
234
 
235
  <details>
236
+ <summary>Python snippet - easy</summary>
237
 
238
  ```py
239
+ from openai import OpenAI
 
240
  from huggingface_hub import hf_hub_download
 
241
 
242
+ # Modify OpenAI's API key and API base to use vLLM's API server.
243
+ openai_api_key = "EMPTY"
244
+ openai_api_base = "http://localhost:8000/v1"
245
+
246
+ TEMP = 0.15
247
+ MAX_TOK = 131072
248
 
249
+ client = OpenAI(
250
+ api_key=openai_api_key,
251
+ base_url=openai_api_base,
252
+ )
253
 
254
+ models = client.models.list()
255
+ model = models.data[0].id
256
 
257
  def load_system_prompt(repo_id: str, filename: str) -> str:
258
  file_path = hf_hub_download(repo_id=repo_id, filename=filename)
259
  with open(file_path, "r") as file:
260
  system_prompt = file.read()
261
+ return system_prompt
 
 
 
262
 
263
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
264
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
265
 
266
+ image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
 
267
 
268
  tools = [
269
  {
270
  "type": "function",
271
  "function": {
272
+ "name": "get_current_population",
273
+ "description": "Get the up-to-date population of a given country.",
274
  "parameters": {
275
  "type": "object",
276
  "properties": {
277
+ "country": {
 
 
 
 
278
  "type": "string",
279
+ "description": "The country to find the population of.",
280
  },
281
  "unit": {
282
  "type": "string",
283
+ "description": "The unit for the population.",
284
+ "enum": ["millions", "thousands"],
285
  },
286
  },
287
+ "required": ["country", "unit"],
288
  },
289
  },
290
  },
 
338
  },
339
  {
340
  "role": "user",
341
+ "content": [
342
+ {
343
+ "type": "text",
344
+ "text": "Can you tell me what is the biggest country depicted on the map?",
345
+ },
346
+ {
347
+ "type": "image_url",
348
+ "image_url": {
349
+ "url": image_url,
350
+ },
351
+ },
352
+ ],
353
+ }
354
+ ]
355
+
356
+ response = client.chat.completions.create(
357
+ model=model,
358
+ messages=messages,
359
+ temperature=TEMP,
360
+ max_tokens=MAX_TOK,
361
+ tools=tools,
362
+ tool_choice="auto",
363
+ )
364
+
365
+ assistant_message = response.choices[0].message.content
366
+ print(assistant_message)
367
+ # The biggest country depicted on the map is Russia.
368
+
369
+ messages.extend([
370
+ {"role": "assistant", "content": assistant_message},
371
+ {"role": "user", "content": "What is the population of that country in millions?"},
372
+ ])
373
+
374
+ response = client.chat.completions.create(
375
+ model=model,
376
+ messages=messages,
377
+ temperature=TEMP,
378
+ max_tokens=MAX_TOK,
379
+ tools=tools,
380
+ tool_choice="auto",
381
+ )
382
+
383
+ print(response.choices[0].message.tool_calls)
384
+ # [ChatCompletionMessageToolCall(id='3e92V6Vfo', function=Function(arguments='{"country": "Russia", "unit": "millions"}', name='get_current_population'), type='function')]
385
+ ```
386
+
387
+ </details>
388
+
389
+ <details>
390
+ <summary>Python snippet - complex</summary>
391
+
392
+ ```python
393
+ import json
394
+ from openai import OpenAI
395
+ from huggingface_hub import hf_hub_download
396
+
397
+ # Modify OpenAI's API key and API base to use vLLM's API server.
398
+ openai_api_key = "EMPTY"
399
+ openai_api_base = "http://localhost:8000/v1"
400
+
401
+ TEMP = 0.15
402
+ MAX_TOK = 131072
403
+
404
+ client = OpenAI(
405
+ api_key=openai_api_key,
406
+ base_url=openai_api_base,
407
+ )
408
+
409
+ models = client.models.list()
410
+ model = models.data[0].id
411
+
412
+
413
+ def load_system_prompt(repo_id: str, filename: str) -> str:
414
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
415
+ with open(file_path, "r") as file:
416
+ system_prompt = file.read()
417
+ return system_prompt
418
+
419
+
420
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
421
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
422
+
423
+ image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
424
+
425
+
426
+ def my_calculator(expression: str) -> str:
427
+ return str(eval(expression))
428
+
429
+
430
+ tools = [
431
+ {
432
+ "type": "function",
433
+ "function": {
434
+ "name": "my_calculator",
435
+ "description": "A calculator that can evaluate a mathematical expression.",
436
+ "parameters": {
437
+ "type": "object",
438
+ "properties": {
439
+ "expression": {
440
+ "type": "string",
441
+ "description": "The mathematical expression to evaluate.",
442
+ },
443
+ },
444
+ "required": ["expression"],
445
+ },
446
+ },
447
+ },
448
+ {
449
+ "type": "function",
450
+ "function": {
451
+ "name": "rewrite",
452
+ "description": "Rewrite a given text for improved clarity",
453
+ "parameters": {
454
+ "type": "object",
455
+ "properties": {
456
+ "text": {
457
+ "type": "string",
458
+ "description": "The input text to rewrite",
459
+ }
460
+ },
461
+ },
462
+ },
463
  },
464
  ]
465
 
466
+ messages = [
467
+ {"role": "system", "content": SYSTEM_PROMPT},
468
+ {
469
+ "role": "user",
470
+ "content": [
471
+ {
472
+ "type": "text",
473
+ "text": "Can you calculate the results for all the equations displayed in the image? Only compute the ones that involve numbers.",
474
+ },
475
+ {
476
+ "type": "image_url",
477
+ "image_url": {
478
+ "url": image_url,
479
+ },
480
+ },
481
+ ],
482
+ },
483
+ ]
484
 
485
+ response = client.chat.completions.create(
486
+ model=model,
487
+ messages=messages,
488
+ temperature=TEMP,
489
+ max_tokens=MAX_TOK,
490
+ tools=tools,
491
+ tool_choice="auto",
492
+ )
493
+
494
+ tool_calls = response.choices[0].message.tool_calls
495
+ print(tool_calls)
496
+ # [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')]
497
+
498
+ results = []
499
+ for tool_call in tool_calls:
500
+ function_name = tool_call.function.name
501
+ function_args = tool_call.function.arguments
502
+ if function_name == "my_calculator":
503
+ result = my_calculator(**json.loads(function_args))
504
+ results.append(result)
505
+
506
+ messages.append({"role": "assistant", "tool_calls": tool_calls})
507
+ for tool_call, result in zip(tool_calls, results):
508
+ messages.append(
509
+ {
510
+ "role": "tool",
511
+ "tool_call_id": tool_call.id,
512
+ "name": tool_call.function.name,
513
+ "content": result,
514
+ }
515
+ )
516
+
517
+
518
+ response = client.chat.completions.create(
519
+ model=model,
520
+ messages=messages,
521
+ temperature=TEMP,
522
+ max_tokens=MAX_TOK,
523
+ )
524
+
525
+ print(response.choices[0].message.content)
526
+ # Here are the results for the equations that involve numbers:
527
+
528
+ # 1. \( 6 + 2 \times 3 = 12 \)
529
+ # 3. \( 19 - (8 + 2) + 1 = 10 \)
530
+
531
+ # For the other equations, you need to substitute the variables with specific values to compute the results.
532
  ```
533
 
534
  </details>
535
 
536
+ #### Instruction following
537
 
538
+ Mistral-Small-3.2-24B-Instruct-2506 will follow your instructions down to the last letter !
 
 
 
539
 
540
+ <details>
541
+ <summary>Python snippet</summary>
542
+
543
+ ```python
544
+ from openai import OpenAI
545
+ from huggingface_hub import hf_hub_download
546
+
547
+ # Modify OpenAI's API key and API base to use vLLM's API server.
548
+ openai_api_key = "EMPTY"
549
+ openai_api_base = "http://localhost:8000/v1"
550
+
551
+ TEMP = 0.15
552
+ MAX_TOK = 131072
553
+
554
+ client = OpenAI(
555
+ api_key=openai_api_key,
556
+ base_url=openai_api_base,
557
+ )
558
 
559
+ models = client.models.list()
560
+ model = models.data[0].id
561
+
562
+
563
+ def load_system_prompt(repo_id: str, filename: str) -> str:
564
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
565
+ with open(file_path, "r") as file:
566
+ system_prompt = file.read()
567
+ return system_prompt
568
+
569
+
570
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
571
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
572
 
573
  messages = [
574
+ {"role": "system", "content": SYSTEM_PROMPT},
575
  {
576
+ "role": "user",
577
+ "content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
578
  },
579
+ ]
580
+
581
+ response = client.chat.completions.create(
582
+ model=model,
583
+ messages=messages,
584
+ temperature=TEMP,
585
+ max_tokens=MAX_TOK,
586
+ )
587
+
588
+ assistant_message = response.choices[0].message.content
589
+ print(assistant_message)
590
+
591
+ # Here's a sentence where each word starts with the next letter of the alphabet, starting from 'a' and ending with 'z':
592
+
593
+ # "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."
594
+
595
+ # This sentence follows the sequence from A to Z without skipping any letters.
596
+ ```
597
+ </details>
598
+
599
+ ### Transformers
600
+
601
+ You can also use Mistral-Small-3.2-24B-Instruct-2506 with `Transformers` !
602
+
603
+ 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.
604
+
605
+ ```bash
606
+ pip install mistral-common --upgrade
607
+ ```
608
+
609
+ Then load our tokenizer along with the model and generate:
610
+
611
+ <details>
612
+ <summary>Python snippet</summary>
613
+
614
+ ```python
615
+ from datetime import datetime, timedelta
616
+ import torch
617
+
618
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
619
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
620
+ from huggingface_hub import hf_hub_download
621
+ from transformers import Mistral3ForConditionalGeneration
622
+
623
+
624
+ def load_system_prompt(repo_id: str, filename: str) -> str:
625
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
626
+ with open(file_path, "r") as file:
627
+ system_prompt = file.read()
628
+ today = datetime.today().strftime("%Y-%m-%d")
629
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
630
+ model_name = repo_id.split("/")[-1]
631
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
632
+
633
+
634
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
635
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
636
+
637
+ tokenizer = MistralTokenizer.from_hf_hub(model_id)
638
+
639
+ model = Mistral3ForConditionalGeneration.from_pretrained(
640
+ model_id, torch_dtype=torch.bfloat16
641
+ )
642
+
643
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
644
+
645
+ messages = [
646
+ {"role": "system", "content": SYSTEM_PROMPT},
647
  {
648
  "role": "user",
649
+ "content": [
650
+ {
651
+ "type": "text",
652
+ "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.",
653
+ },
654
+ {"type": "image_url", "image_url": {"url": image_url}},
655
+ ],
656
  },
657
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
 
659
+ tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
660
+
661
+ input_ids = torch.tensor([tokenized.tokens])
662
+ attention_mask = torch.ones_like(input_ids)
663
+ pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
664
+ image_sizes = torch.tensor([pixel_values.shape[-2:]])
665
+
666
+ output = model.generate(
667
+ input_ids=input_ids,
668
+ attention_mask=attention_mask,
669
+ pixel_values=pixel_values,
670
+ image_sizes=image_sizes,
671
+ max_new_tokens=1000,
672
+ )[0]
673
+
674
+ decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
675
+ print(decoded_output)
676
+ # 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:
677
+
678
+ # 1. **FIGHT**:
679
+ # - **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.
680
+ # - **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.
681
+
682
+ # 2. **BAG**:
683
+ # - **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.
684
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
685
+
686
+ # 3. **POKÉMON**:
687
+ # - **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.
688
+ # - **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.
689
+
690
+ # 4. **RUN**:
691
+ # - **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.
692
+ # - **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.
693
+
694
+ # ### Recommendation:
695
+ # 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.
696
+ ```
697
 
698
+ </details>