coder3101 commited on
Commit
4e4c1df
·
verified ·
1 Parent(s): 380244f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +634 -107
README.md CHANGED
@@ -1,199 +1,726 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
 
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
 
 
 
 
 
 
 
 
9
 
 
10
 
 
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
 
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
 
 
 
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
- ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
 
76
- ## Training Details
 
 
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
 
 
 
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
106
 
107
- ### Testing Data, Factors & Metrics
 
108
 
109
- #### Testing Data
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
112
 
113
- [More Information Needed]
 
 
 
114
 
115
- #### Factors
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
 
 
 
 
 
 
 
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
 
 
124
 
125
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- #### Summary
 
132
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
 
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
 
 
154
 
155
- ### Model Architecture and Objective
 
 
 
156
 
157
- [More Information Needed]
158
 
159
- ### Compute Infrastructure
 
 
 
 
 
 
 
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
 
 
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
 
 
 
176
 
177
- [More Information Needed]
 
 
 
 
 
 
178
 
179
- **APA:**
 
 
180
 
181
- [More Information Needed]
 
 
182
 
183
- ## Glossary [optional]
 
 
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
186
 
187
- [More Information Needed]
 
 
188
 
189
- ## More Information [optional]
 
 
190
 
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
+ library_name: vllm
3
+ language:
4
+ - en
5
+ - fr
6
+ - de
7
+ - es
8
+ - pt
9
+ - it
10
+ - ja
11
+ - ko
12
+ - ru
13
+ - zh
14
+ - ar
15
+ - fa
16
+ - id
17
+ - ms
18
+ - ne
19
+ - pl
20
+ - ro
21
+ - sr
22
+ - sv
23
+ - tr
24
+ - uk
25
+ - vi
26
+ - hi
27
+ - bn
28
+ license: apache-2.0
29
+ inference: false
30
+ base_model:
31
+ - mistralai/Mistral-Small-3.1-24B-Base-2503
32
+ extra_gated_description: If you want to learn more about how we process your personal
33
+ data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
34
+ tags:
35
+ - mistral-common
36
+ - heretic
37
+ - uncensored
38
+ - decensored
39
+ - abliterated
40
  ---
41
+ # This is a decensored version of [mistralai/Mistral-Small-3.2-24B-Instruct-2506](https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506), made using [Heretic](https://github.com/p-e-w/heretic) v1.1.0
42
 
43
+ ## Abliteration parameters
44
 
45
+ | Parameter | Value |
46
+ | :-------- | :---: |
47
+ | **direction_index** | per layer |
48
+ | **attn.o_proj.max_weight** | 1.28 |
49
+ | **attn.o_proj.max_weight_position** | 23.69 |
50
+ | **attn.o_proj.min_weight** | 0.06 |
51
+ | **attn.o_proj.min_weight_distance** | 6.19 |
52
+ | **mlp.down_proj.max_weight** | 1.43 |
53
+ | **mlp.down_proj.max_weight_position** | 24.70 |
54
+ | **mlp.down_proj.min_weight** | 0.73 |
55
+ | **mlp.down_proj.min_weight_distance** | 22.95 |
56
 
57
+ ## Performance
58
 
59
+ | Metric | This model | Original model ([mistralai/Mistral-Small-3.2-24B-Instruct-2506](https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506)) |
60
+ | :----- | :--------: | :---------------------------: |
61
+ | **KL divergence** | 0.1383 | 0 *(by definition)* |
62
+ | **Refusals** | 5/100 | 97/100 |
63
 
64
+ -----
65
 
 
66
 
67
+ # Mistral-Small-3.2-24B-Instruct-2506
68
 
69
+ 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).
70
 
71
+ Small-3.2 improves in the following categories:
72
+ - **Instruction following**: Small-3.2 is better at following precise instructions
73
+ - **Repetition errors**: Small-3.2 produces less infinite generations or repetitive answers
74
+ - **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))
 
 
 
75
 
76
+ 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).
77
 
78
+ ## Key Features
79
+ - same as [Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503#key-features)
80
 
81
+ ## Benchmark Results
 
 
82
 
83
+ 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).
84
+ 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)
85
 
86
+ ### Text
87
 
88
+ #### Instruction Following / Chat / Tone
89
 
90
+ | Model | Wildbench v2 | Arena Hard v2 | IF (Internal; accuracy) |
91
+ |-------|---------------|---------------|------------------------|
92
+ | Small 3.1 24B Instruct | 55.6% | 19.56% | 82.75% |
93
+ | **Small 3.2 24B Instruct** | **65.33%** | **43.1%** | **84.78%** |
94
 
95
+ #### Infinite Generations
96
 
97
+ Small 3.2 reduces infinite generations by 2x on challenging, long and repetitive prompts.
98
 
99
+ | Model | Infinite Generations (Internal; Lower is better) |
100
+ |-------|-------|
101
+ | Small 3.1 24B Instruct | 2.11% |
102
+ | **Small 3.2 24B Instruct** | **1.29%** |
103
 
104
+ #### STEM
105
 
106
+ | 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)|
107
+ |--------------------------------|-----------|-----------------------|------------------------|------------------------|---------------------------|--------------------|-------------------------|--------------------|
108
+ | Small 3.1 24B Instruct | 80.62% | 66.76% | 69.30% | 44.42% | 45.96% | 74.63% | 88.99% | 10.43% |
109
+ | **Small 3.2 24B Instruct** | 80.50% | **69.06%** | 69.42% | 44.22% | 46.13% | **78.33%** | **92.90%** | **12.10%** |
110
 
111
+ ### Vision
112
 
113
+ | Model | MMMU | Mathvista | ChartQA | DocVQA | AI2D |
114
+ |--------------------------------|------------|-----------|-----------|-----------|-----------|
115
+ | Small 3.1 24B Instruct | **64.00%** | **68.91%**| 86.24% | 94.08% | 93.72% |
116
+ | **Small 3.2 24B Instruct** | 62.50% | 67.09% | **87.4%** | 94.86% | 92.91% |
117
 
 
118
 
119
+ ## Usage
120
 
121
+ The model can be used with the following frameworks;
122
+ - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
123
+ - [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
124
 
125
+ **Note 1**: We recommend using a relatively low temperature, such as `temperature=0.15`.
126
 
127
+ **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.
128
 
129
+ ### vLLM (recommended)
130
 
131
+ We recommend using this model with [vLLM](https://github.com/vllm-project/vllm).
132
 
133
+ #### Installation
134
 
135
+ Make sure to install [`vLLM >= 0.9.1`](https://github.com/vllm-project/vllm/releases/tag/v0.9.1):
136
 
137
+ ```
138
+ pip install vllm --upgrade
139
+ ```
140
 
141
+ Doing so should automatically install [`mistral_common >= 1.6.2`](https://github.com/mistralai/mistral-common/releases/tag/v1.6.2).
142
 
143
+ To check:
144
+ ```
145
+ python -c "import mistral_common; print(mistral_common.__version__)"
146
+ ```
147
 
148
+ 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).
149
 
150
+ #### Serve
151
 
152
+ We recommend that you use Mistral-Small-3.2-24B-Instruct-2506 in a server/client setting.
153
 
154
+ 1. Spin up a server:
155
 
156
+ ```
157
+ vllm serve mistralai/Mistral-Small-3.2-24B-Instruct-2506 \
158
+ --tokenizer_mode mistral --config_format mistral \
159
+ --load_format mistral --tool-call-parser mistral \
160
+ --enable-auto-tool-choice --limit-mm-per-prompt '{"image":10}' \
161
+ --tensor-parallel-size 2
162
+ ```
163
 
164
+ **Note:** Running Mistral-Small-3.2-24B-Instruct-2506 on GPU requires ~55 GB of GPU RAM in bf16 or fp16.
165
 
 
166
 
167
+ 2. To ping the client you can use a simple Python snippet. See the following examples.
168
 
 
169
 
170
+ #### Vision reasoning
171
 
172
+ Leverage the vision capabilities of Mistral-Small-3.2-24B-Instruct-2506 to make the best choice given a scenario, go catch them all !
173
 
174
+ <details>
175
+ <summary>Python snippet</summary>
176
 
177
+ ```py
178
+ from datetime import datetime, timedelta
179
 
180
+ from openai import OpenAI
181
+ from huggingface_hub import hf_hub_download
182
 
183
+ # Modify OpenAI's API key and API base to use vLLM's API server.
184
+ openai_api_key = "EMPTY"
185
+ openai_api_base = "http://localhost:8000/v1"
186
 
187
+ TEMP = 0.15
188
+ MAX_TOK = 131072
189
 
190
+ client = OpenAI(
191
+ api_key=openai_api_key,
192
+ base_url=openai_api_base,
193
+ )
194
 
195
+ models = client.models.list()
196
+ model = models.data[0].id
197
 
 
198
 
199
+ def load_system_prompt(repo_id: str, filename: str) -> str:
200
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
201
+ with open(file_path, "r") as file:
202
+ system_prompt = file.read()
203
+ today = datetime.today().strftime("%Y-%m-%d")
204
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
205
+ model_name = repo_id.split("/")[-1]
206
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
207
 
 
208
 
209
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
210
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
211
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
212
 
213
+ messages = [
214
+ {"role": "system", "content": SYSTEM_PROMPT},
215
+ {
216
+ "role": "user",
217
+ "content": [
218
+ {
219
+ "type": "text",
220
+ "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.",
221
+ },
222
+ {"type": "image_url", "image_url": {"url": image_url}},
223
+ ],
224
+ },
225
+ ]
226
 
 
227
 
228
+ response = client.chat.completions.create(
229
+ model=model,
230
+ messages=messages,
231
+ temperature=TEMP,
232
+ max_tokens=MAX_TOK,
233
+ )
234
+
235
+ print(response.choices[0].message.content)
236
+ # 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:
237
+
238
+ # 1. **FIGHT**:
239
+ # - **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.
240
+ # - **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.
241
+
242
+ # 2. **BAG**:
243
+ # - **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.
244
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat the Pidgey quickly.
245
+
246
+ # 3. **POKÉMON**:
247
+ # - **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.
248
+ # - **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.
249
+
250
+ # 4. **RUN**:
251
+ # - **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.
252
+ # - **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.
253
+
254
+ # ### Recommendation:
255
+ # 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.
256
+ ```
257
+ </details>
258
+
259
+ #### Function calling
260
+
261
+ Mistral-Small-3.2-24B-Instruct-2506 is excellent at function / tool calling tasks via vLLM. *E.g.:*
262
+
263
+ <details>
264
+ <summary>Python snippet - easy</summary>
265
+
266
+ ```py
267
+ from openai import OpenAI
268
+ from huggingface_hub import hf_hub_download
269
+
270
+ # Modify OpenAI's API key and API base to use vLLM's API server.
271
+ openai_api_key = "EMPTY"
272
+ openai_api_base = "http://localhost:8000/v1"
273
+
274
+ TEMP = 0.15
275
+ MAX_TOK = 131072
276
+
277
+ client = OpenAI(
278
+ api_key=openai_api_key,
279
+ base_url=openai_api_base,
280
+ )
281
+
282
+ models = client.models.list()
283
+ model = models.data[0].id
284
+
285
+ def load_system_prompt(repo_id: str, filename: str) -> str:
286
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
287
+ with open(file_path, "r") as file:
288
+ system_prompt = file.read()
289
+ return system_prompt
290
+
291
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
292
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
293
+
294
+ image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
295
+
296
+ tools = [
297
+ {
298
+ "type": "function",
299
+ "function": {
300
+ "name": "get_current_population",
301
+ "description": "Get the up-to-date population of a given country.",
302
+ "parameters": {
303
+ "type": "object",
304
+ "properties": {
305
+ "country": {
306
+ "type": "string",
307
+ "description": "The country to find the population of.",
308
+ },
309
+ "unit": {
310
+ "type": "string",
311
+ "description": "The unit for the population.",
312
+ "enum": ["millions", "thousands"],
313
+ },
314
+ },
315
+ "required": ["country", "unit"],
316
+ },
317
+ },
318
+ },
319
+ {
320
+ "type": "function",
321
+ "function": {
322
+ "name": "rewrite",
323
+ "description": "Rewrite a given text for improved clarity",
324
+ "parameters": {
325
+ "type": "object",
326
+ "properties": {
327
+ "text": {
328
+ "type": "string",
329
+ "description": "The input text to rewrite",
330
+ }
331
+ },
332
+ },
333
+ },
334
+ },
335
+ ]
336
+
337
+ messages = [
338
+ {"role": "system", "content": SYSTEM_PROMPT},
339
+ {
340
+ "role": "user",
341
+ "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.",
342
+ },
343
+ {
344
+ "role": "assistant",
345
+ "content": "",
346
+ "tool_calls": [
347
+ {
348
+ "id": "bbc5b7ede",
349
+ "type": "function",
350
+ "function": {
351
+ "name": "rewrite",
352
+ "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."}',
353
+ },
354
+ }
355
+ ],
356
+ },
357
+ {
358
+ "role": "tool",
359
+ "content": '{"action":"rewrite","outcome":"OpenAI is a FOR-profit company."}',
360
+ "tool_call_id": "bbc5b7ede",
361
+ "name": "rewrite",
362
+ },
363
+ {
364
+ "role": "assistant",
365
+ "content": "---\n\nOpenAI is a FOR-profit company.",
366
+ },
367
+ {
368
+ "role": "user",
369
+ "content": [
370
+ {
371
+ "type": "text",
372
+ "text": "Can you tell me what is the biggest country depicted on the map?",
373
+ },
374
+ {
375
+ "type": "image_url",
376
+ "image_url": {
377
+ "url": image_url,
378
+ },
379
+ },
380
+ ],
381
+ }
382
+ ]
383
+
384
+ response = client.chat.completions.create(
385
+ model=model,
386
+ messages=messages,
387
+ temperature=TEMP,
388
+ max_tokens=MAX_TOK,
389
+ tools=tools,
390
+ tool_choice="auto",
391
+ )
392
+
393
+ assistant_message = response.choices[0].message.content
394
+ print(assistant_message)
395
+ # The biggest country depicted on the map is Russia.
396
+
397
+ messages.extend([
398
+ {"role": "assistant", "content": assistant_message},
399
+ {"role": "user", "content": "What is the population of that country in millions?"},
400
+ ])
401
+
402
+ response = client.chat.completions.create(
403
+ model=model,
404
+ messages=messages,
405
+ temperature=TEMP,
406
+ max_tokens=MAX_TOK,
407
+ tools=tools,
408
+ tool_choice="auto",
409
+ )
410
+
411
+ print(response.choices[0].message.tool_calls)
412
+ # [ChatCompletionMessageToolCall(id='3e92V6Vfo', function=Function(arguments='{"country": "Russia", "unit": "millions"}', name='get_current_population'), type='function')]
413
+ ```
414
+
415
+ </details>
416
+
417
+ <details>
418
+ <summary>Python snippet - complex</summary>
419
+
420
+ ```python
421
+ import json
422
+ from openai import OpenAI
423
+ from huggingface_hub import hf_hub_download
424
+
425
+ # Modify OpenAI's API key and API base to use vLLM's API server.
426
+ openai_api_key = "EMPTY"
427
+ openai_api_base = "http://localhost:8000/v1"
428
+
429
+ TEMP = 0.15
430
+ MAX_TOK = 131072
431
+
432
+ client = OpenAI(
433
+ api_key=openai_api_key,
434
+ base_url=openai_api_base,
435
+ )
436
+
437
+ models = client.models.list()
438
+ model = models.data[0].id
439
+
440
+
441
+ def load_system_prompt(repo_id: str, filename: str) -> str:
442
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
443
+ with open(file_path, "r") as file:
444
+ system_prompt = file.read()
445
+ return system_prompt
446
+
447
+
448
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
449
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
450
+
451
+ image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
452
+
453
+
454
+ def my_calculator(expression: str) -> str:
455
+ return str(eval(expression))
456
+
457
+
458
+ tools = [
459
+ {
460
+ "type": "function",
461
+ "function": {
462
+ "name": "my_calculator",
463
+ "description": "A calculator that can evaluate a mathematical expression.",
464
+ "parameters": {
465
+ "type": "object",
466
+ "properties": {
467
+ "expression": {
468
+ "type": "string",
469
+ "description": "The mathematical expression to evaluate.",
470
+ },
471
+ },
472
+ "required": ["expression"],
473
+ },
474
+ },
475
+ },
476
+ {
477
+ "type": "function",
478
+ "function": {
479
+ "name": "rewrite",
480
+ "description": "Rewrite a given text for improved clarity",
481
+ "parameters": {
482
+ "type": "object",
483
+ "properties": {
484
+ "text": {
485
+ "type": "string",
486
+ "description": "The input text to rewrite",
487
+ }
488
+ },
489
+ },
490
+ },
491
+ },
492
+ ]
493
+
494
+ messages = [
495
+ {"role": "system", "content": SYSTEM_PROMPT},
496
+ {
497
+ "role": "user",
498
+ "content": [
499
+ {
500
+ "type": "text",
501
+ "text": "Can you calculate the results for all the equations displayed in the image? Only compute the ones that involve numbers.",
502
+ },
503
+ {
504
+ "type": "image_url",
505
+ "image_url": {
506
+ "url": image_url,
507
+ },
508
+ },
509
+ ],
510
+ },
511
+ ]
512
+
513
+ response = client.chat.completions.create(
514
+ model=model,
515
+ messages=messages,
516
+ temperature=TEMP,
517
+ max_tokens=MAX_TOK,
518
+ tools=tools,
519
+ tool_choice="auto",
520
+ )
521
+
522
+ tool_calls = response.choices[0].message.tool_calls
523
+ print(tool_calls)
524
+ # [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')]
525
+
526
+ results = []
527
+ for tool_call in tool_calls:
528
+ function_name = tool_call.function.name
529
+ function_args = tool_call.function.arguments
530
+ if function_name == "my_calculator":
531
+ result = my_calculator(**json.loads(function_args))
532
+ results.append(result)
533
+
534
+ messages.append({"role": "assistant", "tool_calls": tool_calls})
535
+ for tool_call, result in zip(tool_calls, results):
536
+ messages.append(
537
+ {
538
+ "role": "tool",
539
+ "tool_call_id": tool_call.id,
540
+ "name": tool_call.function.name,
541
+ "content": result,
542
+ }
543
+ )
544
+
545
+
546
+ response = client.chat.completions.create(
547
+ model=model,
548
+ messages=messages,
549
+ temperature=TEMP,
550
+ max_tokens=MAX_TOK,
551
+ )
552
+
553
+ print(response.choices[0].message.content)
554
+ # Here are the results for the equations that involve numbers:
555
+
556
+ # 1. \( 6 + 2 \times 3 = 12 \)
557
+ # 3. \( 19 - (8 + 2) + 1 = 10 \)
558
+
559
+ # For the other equations, you need to substitute the variables with specific values to compute the results.
560
+ ```
561
+
562
+ </details>
563
+
564
+ #### Instruction following
565
+
566
+ Mistral-Small-3.2-24B-Instruct-2506 will follow your instructions down to the last letter !
567
+
568
+ <details>
569
+ <summary>Python snippet</summary>
570
+
571
+ ```python
572
+ from openai import OpenAI
573
+ from huggingface_hub import hf_hub_download
574
+
575
+ # Modify OpenAI's API key and API base to use vLLM's API server.
576
+ openai_api_key = "EMPTY"
577
+ openai_api_base = "http://localhost:8000/v1"
578
+
579
+ TEMP = 0.15
580
+ MAX_TOK = 131072
581
+
582
+ client = OpenAI(
583
+ api_key=openai_api_key,
584
+ base_url=openai_api_base,
585
+ )
586
+
587
+ models = client.models.list()
588
+ model = models.data[0].id
589
+
590
+
591
+ def load_system_prompt(repo_id: str, filename: str) -> str:
592
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
593
+ with open(file_path, "r") as file:
594
+ system_prompt = file.read()
595
+ return system_prompt
596
+
597
+
598
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
599
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
600
+
601
+ messages = [
602
+ {"role": "system", "content": SYSTEM_PROMPT},
603
+ {
604
+ "role": "user",
605
+ "content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
606
+ },
607
+ ]
608
+
609
+ response = client.chat.completions.create(
610
+ model=model,
611
+ messages=messages,
612
+ temperature=TEMP,
613
+ max_tokens=MAX_TOK,
614
+ )
615
 
616
+ assistant_message = response.choices[0].message.content
617
+ print(assistant_message)
618
 
619
+ # Here's a sentence where each word starts with the next letter of the alphabet, starting from 'a' and ending with 'z':
620
 
621
+ # "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."
622
 
623
+ # This sentence follows the sequence from A to Z without skipping any letters.
624
+ ```
625
+ </details>
626
 
627
+ ### Transformers
628
 
629
+ You can also use Mistral-Small-3.2-24B-Instruct-2506 with `Transformers` !
630
 
631
+ 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.
632
 
633
+ ```bash
634
+ pip install mistral-common --upgrade
635
+ ```
636
 
637
+ Then load our tokenizer along with the model and generate:
638
 
639
+ <details>
640
+ <summary>Python snippet</summary>
 
 
 
641
 
642
+ ```python
643
+ from datetime import datetime, timedelta
644
+ import torch
645
 
646
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
647
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
648
+ from huggingface_hub import hf_hub_download
649
+ from transformers import Mistral3ForConditionalGeneration
650
 
 
651
 
652
+ def load_system_prompt(repo_id: str, filename: str) -> str:
653
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
654
+ with open(file_path, "r") as file:
655
+ system_prompt = file.read()
656
+ today = datetime.today().strftime("%Y-%m-%d")
657
+ yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
658
+ model_name = repo_id.split("/")[-1]
659
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
660
 
 
661
 
662
+ model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
663
+ SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
664
 
665
+ tokenizer = MistralTokenizer.from_hf_hub(model_id)
666
 
667
+ model = Mistral3ForConditionalGeneration.from_pretrained(
668
+ model_id, torch_dtype=torch.bfloat16
669
+ )
670
 
671
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
672
 
673
+ messages = [
674
+ {"role": "system", "content": SYSTEM_PROMPT},
675
+ {
676
+ "role": "user",
677
+ "content": [
678
+ {
679
+ "type": "text",
680
+ "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.",
681
+ },
682
+ {"type": "image_url", "image_url": {"url": image_url}},
683
+ ],
684
+ },
685
+ ]
686
 
687
+ tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
688
 
689
+ input_ids = torch.tensor([tokenized.tokens])
690
+ attention_mask = torch.ones_like(input_ids)
691
+ pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
692
+ image_sizes = torch.tensor([pixel_values.shape[-2:]])
693
 
694
+ output = model.generate(
695
+ input_ids=input_ids,
696
+ attention_mask=attention_mask,
697
+ pixel_values=pixel_values,
698
+ image_sizes=image_sizes,
699
+ max_new_tokens=1000,
700
+ )[0]
701
 
702
+ decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
703
+ print(decoded_output)
704
+ # 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:
705
 
706
+ # 1. **FIGHT**:
707
+ # - **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.
708
+ # - **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.
709
 
710
+ # 2. **BAG**:
711
+ # - **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.
712
+ # - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
713
 
714
+ # 3. **POKÉMON**:
715
+ # - **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.
716
+ # - **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.
717
 
718
+ # 4. **RUN**:
719
+ # - **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.
720
+ # - **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.
721
 
722
+ # ### Recommendation:
723
+ # 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.
724
+ ```
725
 
726
+ </details>