coder3101 commited on
Commit
0006062
·
verified ·
1 Parent(s): 32a37d5

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +610 -189
README.md CHANGED
@@ -1,199 +1,620 @@
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
+ - es
7
+ - de
8
+ - it
9
+ - pt
10
+ - nl
11
+ - zh
12
+ - ja
13
+ - ko
14
+ - ar
15
+ license: apache-2.0
16
+ inference: false
17
+ base_model:
18
+ - mistralai/Ministral-3-14B-Base-2512
19
+ extra_gated_description: If you want to learn more about how we process your personal
20
+ data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
21
+ tags:
22
+ - mistral-common
23
+ - heretic
24
+ - uncensored
25
+ - decensored
26
+ - abliterated
27
  ---
28
+ # This is a decensored version of [mistralai/Ministral-3-14B-Reasoning-2512](https://huggingface.co/mistralai/Ministral-3-14B-Reasoning-2512), made using [Heretic](https://github.com/p-e-w/heretic) v1.1.0
29
+
30
+ ## Abliteration parameters
31
+
32
+ | Parameter | Value |
33
+ | :-------- | :---: |
34
+ | **direction_index** | 17.52 |
35
+ | **attn.o_proj.max_weight** | 1.46 |
36
+ | **attn.o_proj.max_weight_position** | 25.35 |
37
+ | **attn.o_proj.min_weight** | 0.09 |
38
+ | **attn.o_proj.min_weight_distance** | 18.63 |
39
+ | **mlp.down_proj.max_weight** | 1.19 |
40
+ | **mlp.down_proj.max_weight_position** | 30.03 |
41
+ | **mlp.down_proj.min_weight** | 0.79 |
42
+ | **mlp.down_proj.min_weight_distance** | 22.65 |
43
+
44
+ ## Performance
45
+
46
+ | Metric | This model | Original model ([mistralai/Ministral-3-14B-Reasoning-2512](https://huggingface.co/mistralai/Ministral-3-14B-Reasoning-2512)) |
47
+ | :----- | :--------: | :---------------------------: |
48
+ | **KL divergence** | 0.0172 | 0 *(by definition)* |
49
+ | **Refusals** | 7/100 | 97/100 |
50
+
51
+ -----
52
+
53
+
54
+ # Ministral 3 14B Reasoning 2512
55
+
56
+ The largest model in the Ministral 3 family, **Ministral 3 14B** offers frontier capabilities and performance comparable to its larger [Mistral Small 3.2 24B](https://huggingface.co/mistralai/Mistral-Small-3.2-Instruct-2506) counterpart. A powerful and efficient language model with vision capabilities.
57
+
58
+ This model is the reasoning post-trained version, trained for reasoning tasks, making it ideal for math, coding and stem related use cases.
59
+
60
+ The Ministral 3 family is designed for edge deployment, capable of running on a wide range of hardware. Ministral 3 14B can even be deployed locally, capable of fitting in 32GB of VRAM in BF16, and less than 24GB of RAM/VRAM when quantized.
61
+
62
+ Learn more in our [blog post](https://mistral.ai/news/mistral-3) and [paper](https://arxiv.org/abs/2601.08584).
63
+
64
+ ## Key Features
65
+ Ministral 3 14B consists of two main architectural components:
66
+ - **13.5B Language Model**
67
+ - **0.4B Vision Encoder**
68
+
69
+ The Ministral 3 14B Reasoning model offers the following capabilities:
70
+ - **Vision**: Enables the model to analyze images and provide insights based on visual content, in addition to text.
71
+ - **Multilingual**: Supports dozens of languages, including English, French, Spanish, German, Italian, Portuguese, Dutch, Chinese, Japanese, Korean, Arabic.
72
+ - **System Prompt**: Maintains strong adherence and support for system prompts.
73
+ - **Agentic**: Offers best-in-class agentic capabilities with native function calling and JSON outputting.
74
+ - **Reasoning**: Excels at complex, multi-step reasoning and dynamic problem-solving.
75
+ - **Edge-Optimized**: Delivers best-in-class performance at a small scale, deployable anywhere.
76
+ - **Apache 2.0 License**: Open-source license allowing usage and modification for both commercial and non-commercial purposes.
77
+ - **Large Context Window**: Supports a 256k context window.
78
+
79
+ ### Use Cases
80
+ Private AI deployments where advanced capabilities meet practical hardware constraints:
81
+ - Private/custom chat and AI assistant deployments in constrained environments
82
+ - Advanced local agentic use cases
83
+ - Fine-tuning and specialization
84
+ - And more...
85
+
86
+ Bringing advanced AI capabilities to most environments.
87
+
88
+ ### Recommended Settings
89
+
90
+ We recommend deploying with the following best practices:
91
+ - System Prompt: Use our provided [system prompt](https://huggingface.co/mistralai/Ministral-3-14B-Reasoning-2512/blob/main/SYSTEM_PROMPT.txt), and append it to your custom system prompt to define a clear environment and use case, including guidance on how to effectively leverage tools in agentic systems.
92
+ - Multi-turn Traces: We highly recommend keeping the reasoning traces in context.
93
+ - Sampling Parameters: Use a **temperature of 1** for most environments ; Different temperatures may be explored for different use cases - developers are encouraged to experiment with alternative settings.
94
+ - Tools: Keep the set of tools well-defined and limit their number to the minimum required for the use case - Avoiding overloading the model with an excessive number of tools.
95
+ - Vision: When deploying with vision capabilities, we recommend maintaining an aspect ratio close to 1:1 (width-to-height) for images. Avoiding the use of overly thin or wide images - crop them as needed to ensure optimal performance.
96
+
97
+ ## Ministral 3 Family
98
+
99
+ | Model Name | Type | Precision | Link |
100
+ |--------------------------------|--------------------|-----------|------------------------------------------------------------------------------------------|
101
+ | Ministral 3 3B Base 2512 | Base pre-trained | BF16 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-3B-Base-2512) |
102
+ | Ministral 3 3B Instruct 2512 | Instruct post-trained | FP8 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-3B-Instruct-2512) |
103
+ | Ministral 3 3B Reasoning 2512 | Reasoning capable | BF16 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-3B-Reasoning-2512) |
104
+ | Ministral 3 8B Base 2512 | Base pre-trained | BF16 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-8B-Base-2512) |
105
+ | Ministral 3 8B Instruct 2512 | Instruct post-trained | FP8 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-8B-Instruct-2512) |
106
+ | Ministral 3 8B Reasoning 2512 | Reasoning capable | BF16 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-8B-Reasoning-2512) |
107
+ | Ministral 3 14B Base 2512 | Base pre-trained | BF16 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-14B-Base-2512) |
108
+ | Ministral 3 14B Instruct 2512 | Instruct post-trained | FP8 | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-14B-Instruct-2512) |
109
+ | **Ministral 3 14B Reasoning 2512** | **Reasoning capable** | **BF16** | [Hugging Face](https://huggingface.co/mistralai/Ministral-3-14B-Reasoning-2512) |
110
 
111
+ Other formats available [here](https://huggingface.co/collections/mistralai/ministral-3-additional-checkpoints).
112
+
113
+ ## Benchmark Results
114
 
115
+ We compare Ministral 3 to similar sized models.
116
 
117
+ ### Reasoning
118
 
119
+ | Model | AIME25 | AIME24 | GPQA Diamond | LiveCodeBench |
120
+ |---------------------------|-------------|-------------|--------------|---------------|
121
+ | **Ministral 3 14B** | <u>0.850</u>| <u>0.898</u>| <u>0.712</u> | <u>0.646</u> |
122
+ | Qwen3-14B (Thinking) | 0.737 | 0.837 | 0.663 | 0.593 |
123
+ | | | | | |
124
+ | **Ministral 3 8B** | 0.787 | <u>0.860</u>| 0.668 | <u>0.616</u> |
125
+ | Qwen3-VL-8B-Thinking | <u>0.798</u>| <u>0.860</u>| <u>0.671</u> | 0.580 |
126
+ | | | | | |
127
+ | **Ministral 3 3B** | <u>0.721</u>| <u>0.775</u>| 0.534 | <u>0.548</u> |
128
+ | Qwen3-VL-4B-Thinking | 0.697 | 0.729 | <u>0.601</u> | 0.513 |
129
 
130
+ ### Instruct
131
 
132
+ | Model | Arena Hard | WildBench | MATH Maj@1 | MM MTBench |
133
+ |---------------------------|-------------|------------|-------------|------------------|
134
+ | **Ministral 3 14B** | <u>0.551</u>| <u>68.5</u>| <u>0.904</u>| <u>8.49</u> |
135
+ | Qwen3 14B (Non-Thinking) | 0.427 | 65.1 | 0.870 | NOT MULTIMODAL |
136
+ | Gemma3-12B-Instruct | 0.436 | 63.2 | 0.854 | 6.70 |
137
+ | | | | | |
138
+ | **Ministral 3 8B** | 0.509 | <u>66.8</u>| 0.876 | <u>8.08</u> |
139
+ | Qwen3-VL-8B-Instruct | <u>0.528</u>| 66.3 | <u>0.946</u>| 8.00 |
140
+ | | | | | |
141
+ | **Ministral 3 3B** | 0.305 | <u>56.8</u>| 0.830 | 7.83 |
142
+ | Qwen3-VL-4B-Instruct | <u>0.438</u>| <u>56.8</u>| <u>0.900</u>| <u>8.01</u> |
143
+ | Qwen3-VL-2B-Instruct | 0.163 | 42.2 | 0.786 | 6.36 |
144
+ | Gemma3-4B-Instruct | 0.318 | 49.1 | 0.759 | 5.23 |
145
 
146
+ ### Base
147
 
148
+ | Model | Multilingual MMLU | MATH CoT 2-Shot | AGIEval 5-shot | MMLU Redux 5-shot | MMLU 5-shot | TriviaQA 5-shot |
149
+ |---------------------|-------------------|-----------------|----------------|-------------------|-------------|-----------------|
150
+ | **Ministral 3 14B** | 0.742 | <u>0.676</u> | 0.648 | 0.820 | 0.794 | 0.749 |
151
+ | Qwen3 14B Base | <u>0.754</u> | 0.620 | <u>0.661</u> | <u>0.837</u> | <u>0.804</u>| 0.703 |
152
+ | Gemma 3 12B Base | 0.690 | 0.487 | 0.587 | 0.766 | 0.745 | <u>0.788</u> |
153
+ | | | | | | | |
154
+ | **Ministral 3 8B** | <u>0.706</u> | <u>0.626</u> | 0.591 | 0.793 | <u>0.761</u>| <u>0.681</u> |
155
+ | Qwen 3 8B Base | 0.700 | 0.576 | <u>0.596</u> | <u>0.794</u> | 0.760 | 0.639 |
156
+ | | | | | | | |
157
+ | **Ministral 3 3B** | 0.652 | <u>0.601</u> | 0.511 | 0.735 | 0.707 | 0.592 |
158
+ | Qwen 3 4B Base | <u>0.677</u> | 0.405 | <u>0.570</u> | <u>0.759</u> | <u>0.713</u>| 0.530 |
159
+ | Gemma 3 4B Base | 0.516 | 0.294 | 0.430 | 0.626 | 0.589 | <u>0.640</u> |
160
+
161
+ ## Usage
162
+
163
+ The model can be used with the following frameworks;
164
+ - [`vllm`](https://github.com/vllm-project/vllm): See [here](#vllm)
165
+ - [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
166
+
167
+ ### vLLM
168
+
169
+ We recommend using this model with [vLLM](https://github.com/vllm-project/vllm).
170
+
171
+ #### Installation
172
+
173
+ Make sure to install **vllm >= 0.12.0**:
174
+
175
+ ```
176
+ pip install vllm --upgrade
177
+ ```
178
+
179
+ Doing so should automatically install [`mistral_common >= 1.8.6`](https://github.com/mistralai/mistral-common/releases/tag/v1.8.6).
180
+
181
+ To check:
182
+ ```
183
+ python -c "import mistral_common; print(mistral_common.__version__)"
184
+ ```
185
+
186
+ You can also make use of a ready-to-go [docker image](https://github.com/vllm-project/vllm/blob/main/docker/Dockerfile) or on the [docker hub](https://hub.docker.com/layers/vllm/vllm-openai/latest).
187
+
188
+ #### Serve
189
+
190
+ To fully exploit the `Ministral-3-14B-Reasoning-2512` we recommed using 2xH200 GPUs for deployment due to its large context. However if you don't need a large context, you can fall back to a single GPU.
191
+
192
+ A simple launch command is:
193
+
194
+ ```bash
195
+
196
+ vllm serve mistralai/Ministral-3-14B-Reasoning-2512 \
197
+ --tensor-parallel-size 2 \
198
+ --tokenizer_mode mistral --config_format mistral --load_format mistral \
199
+ --enable-auto-tool-choice --tool-call-parser mistral \
200
+ --reasoning-parser mistral
201
+ ```
202
+
203
+ Key parameter notes:
204
+
205
+ * enable-auto-tool-choice: Required when enabling tool usage.
206
+ * tool-call-parser mistral: Required when enabling tool usage.
207
+ * reasoning-parser mistral: Required when enabling reasoning.
208
+
209
+ Additional flags:
210
+
211
+ * You can set `--max-model-len` to preserve memory. By default it is set to `262144` which is quite large but not necessary for most scenarios.
212
+ * You can set `--max-num-batched-tokens` to balance throughput and latency, higher means higher throughput but higher latency.
213
+
214
+ #### Usage of the model
215
+
216
+ Here we assume that the model `mistralai/Ministral-3-8B-Reasoning-2512` is served and you can ping it to the domain `localhost` with the port `8000` which is the default for vLLM.
217
+
218
+ <details>
219
+ <summary>Vision Reasoning</summary>
220
+
221
+ Let's see if the Ministral 3 model knows when to pick a fight !
222
+
223
+ ```python
224
+ from typing import Any
225
+
226
+ from openai import OpenAI
227
+ from huggingface_hub import hf_hub_download
228
+
229
+ # Modify OpenAI's API key and API base to use vLLM's API server.
230
+ openai_api_key = "EMPTY"
231
+ openai_api_base = "http://localhost:8000/v1"
232
+
233
+ TEMP = 0.7
234
+ TOP_P = 0.95
235
+ MAX_TOK = 262144
236
+ client = OpenAI(
237
+ api_key=openai_api_key,
238
+ base_url=openai_api_base,
239
+ )
240
+
241
+ models = client.models.list()
242
+ model = models.data[0].id
243
+
244
+
245
+ def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
246
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
247
+ with open(file_path, "r") as file:
248
+ system_prompt = file.read()
249
+
250
+ index_begin_think = system_prompt.find("[THINK]")
251
+ index_end_think = system_prompt.find("[/THINK]")
252
+
253
+ return {
254
+ "role": "system",
255
+ "content": [
256
+ {"type": "text", "text": system_prompt[:index_begin_think]},
257
+ {
258
+ "type": "thinking",
259
+ "thinking": system_prompt[
260
+ index_begin_think + len("[THINK]") : index_end_think
261
+ ],
262
+ "closed": True,
263
+ },
264
+ {
265
+ "type": "text",
266
+ "text": system_prompt[index_end_think + len("[/THINK]") :],
267
+ },
268
+ ],
269
+ }
270
+
271
+
272
+ SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
273
+
274
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
275
+
276
+ messages = [
277
+ SYSTEM_PROMPT,
278
+ {
279
+ "role": "user",
280
+ "content": [
281
+ {
282
+ "type": "text",
283
+ "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.",
284
+ },
285
+ {"type": "image_url", "image_url": {"url": image_url}},
286
+ ],
287
+ },
288
+ ]
289
+
290
+
291
+ stream = client.chat.completions.create(
292
+ model=model,
293
+ messages=messages,
294
+ stream=True,
295
+ temperature=TEMP,
296
+ top_p=TOP_P,
297
+ max_tokens=MAX_TOK,
298
+ )
299
+
300
+ print("client: Start streaming chat completions...:\n")
301
+ printed_reasoning_content = False
302
+ answer = []
303
+
304
+ for chunk in stream:
305
+ reasoning_content = None
306
+ content = None
307
+ # Check the content is reasoning_content or content
308
+ if hasattr(chunk.choices[0].delta, "reasoning_content"):
309
+ reasoning_content = chunk.choices[0].delta.reasoning_content
310
+ if hasattr(chunk.choices[0].delta, "content"):
311
+ content = chunk.choices[0].delta.content
312
+
313
+ if reasoning_content is not None:
314
+ if not printed_reasoning_content:
315
+ printed_reasoning_content = True
316
+ print("Start reasoning:\n", end="", flush=True)
317
+ print(reasoning_content, end="", flush=True)
318
+ elif content is not None:
319
+ # Extract and print the content
320
+ if not reasoning_content and printed_reasoning_content:
321
+ answer.extend(content)
322
+ print(content, end="", flush=True)
323
+
324
+ if answer:
325
+ print("\n\n=============\nAnswer\n=============\n")
326
+ print("".join(answer))
327
+ else:
328
+ print("\n\n=============\nNo Answer\n=============\n")
329
+ print(
330
+ "No answer was generated by the model, probably because the maximum number of tokens was reached."
331
+ )
332
+ ```
333
+
334
+ Now we'll make it compute some maths !
335
+
336
+ ```python
337
+ from typing import Any
338
+
339
+ from openai import OpenAI
340
+ from huggingface_hub import hf_hub_download
341
+
342
+ # Modify OpenAI's API key and API base to use vLLM's API server.
343
+ openai_api_key = "EMPTY"
344
+ openai_api_base = "http://localhost:8000/v1"
345
+
346
+ TEMP = 0.7
347
+ TOP_P = 0.95
348
+ MAX_TOK = 262144
349
+ client = OpenAI(
350
+ api_key=openai_api_key,
351
+ base_url=openai_api_base,
352
+ )
353
+
354
+ models = client.models.list()
355
+ model = models.data[0].id
356
+
357
+
358
+ def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
359
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
360
+ with open(file_path, "r") as file:
361
+ system_prompt = file.read()
362
+
363
+ index_begin_think = system_prompt.find("[THINK]")
364
+ index_end_think = system_prompt.find("[/THINK]")
365
+
366
+ return {
367
+ "role": "system",
368
+ "content": [
369
+ {"type": "text", "text": system_prompt[:index_begin_think]},
370
+ {
371
+ "type": "thinking",
372
+ "thinking": system_prompt[
373
+ index_begin_think + len("[THINK]") : index_end_think
374
+ ],
375
+ "closed": True,
376
+ },
377
+ {
378
+ "type": "text",
379
+ "text": system_prompt[index_end_think + len("[/THINK]") :],
380
+ },
381
+ ],
382
+ }
383
+
384
+
385
+ SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
386
+
387
+ image_url = "https://i.ytimg.com/vi/5Y3xLHeyKZU/hqdefault.jpg"
388
+
389
+ messages = [
390
+ SYSTEM_PROMPT,
391
+ {
392
+ "role": "user",
393
+ "content": [
394
+ {
395
+ "type": "text",
396
+ "text": "Solve the equations. If they contain only numbers, use your calculator, else only think. Answer in the language of the image.",
397
+ },
398
+ {"type": "image_url", "image_url": {"url": image_url}},
399
+ ],
400
+ },
401
+ ]
402
+
403
+ stream = client.chat.completions.create(
404
+ model=model,
405
+ messages=messages,
406
+ stream=True,
407
+ temperature=TEMP,
408
+ top_p=TOP_P,
409
+ max_tokens=MAX_TOK,
410
+ )
411
+
412
+ print("client: Start streaming chat completions...:\n")
413
+ printed_reasoning_content = False
414
+ answer = []
415
+
416
+ for chunk in stream:
417
+ reasoning_content = None
418
+ content = None
419
+ # Check the content is reasoning_content or content
420
+ if hasattr(chunk.choices[0].delta, "reasoning_content"):
421
+ reasoning_content = chunk.choices[0].delta.reasoning_content
422
+ if hasattr(chunk.choices[0].delta, "content"):
423
+ content = chunk.choices[0].delta.content
424
+
425
+ if reasoning_content is not None:
426
+ if not printed_reasoning_content:
427
+ printed_reasoning_content = True
428
+ print("Start reasoning:\n", end="", flush=True)
429
+ print(reasoning_content, end="", flush=True)
430
+ if content is not None:
431
+ # Extract and print the content
432
+ if not reasoning_content and printed_reasoning_content:
433
+ answer.extend(content)
434
+ print(content, end="", flush=True)
435
+
436
+ if answer:
437
+ print("\n\n=============\nAnswer\n=============\n")
438
+ print("".join(answer))
439
+ else:
440
+ print("\n\n=============\nNo Answer\n=============\n")
441
+ print(
442
+ "No answer was generated by the model, probably because the maximum number of tokens was reached."
443
+ )
444
+ ```
445
+
446
+ </details>
447
+
448
+ <details>
449
+ <summary>Text-Only Request</summary>
450
+
451
+ Let's do more maths and leave it up to the model to figure out how to achieve a result.
452
+
453
+ ```python
454
+ from typing import Any
455
+ from openai import OpenAI
456
+ from huggingface_hub import hf_hub_download
457
+
458
+ # Modify OpenAI's API key and API base to use vLLM's API server.
459
+ openai_api_key = "EMPTY"
460
+ openai_api_base = "http://localhost:8000/v1"
461
+
462
+ TEMP = 0.7
463
+ TOP_P = 0.95
464
+ MAX_TOK = 262144
465
+ client = OpenAI(
466
+ api_key=openai_api_key,
467
+ base_url=openai_api_base,
468
+ )
469
+
470
+ models = client.models.list()
471
+ model = models.data[0].id
472
+
473
+
474
+ def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]:
475
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
476
+ with open(file_path, "r") as file:
477
+ system_prompt = file.read()
478
+
479
+ index_begin_think = system_prompt.find("[THINK]")
480
+ index_end_think = system_prompt.find("[/THINK]")
481
+
482
+ return {
483
+ "role": "system",
484
+ "content": [
485
+ {"type": "text", "text": system_prompt[:index_begin_think]},
486
+ {
487
+ "type": "thinking",
488
+ "thinking": system_prompt[
489
+ index_begin_think + len("[THINK]") : index_end_think
490
+ ],
491
+ "closed": True,
492
+ },
493
+ {
494
+ "type": "text",
495
+ "text": system_prompt[index_end_think + len("[/THINK]") :],
496
+ },
497
+ ],
498
+ }
499
+
500
+
501
+ SYSTEM_PROMPT = load_system_prompt(model, "SYSTEM_PROMPT.txt")
502
+
503
+ query = "Use each number in 2,5,6,3 exactly once, along with any combination of +, -, ×, ÷ (and parentheses for grouping), to make the number 24."
504
+
505
+ messages = [
506
+ SYSTEM_PROMPT,
507
+ {"role": "user", "content": query}
508
+ ]
509
+ stream = client.chat.completions.create(
510
+ model=model,
511
+ messages=messages,
512
+ stream=True,
513
+ temperature=TEMP,
514
+ top_p=TOP_P,
515
+ max_tokens=MAX_TOK,
516
+ )
517
+
518
+ print("client: Start streaming chat completions...:\n")
519
+ printed_reasoning_content = False
520
+ answer = []
521
+
522
+ for chunk in stream:
523
+ reasoning_content = None
524
+ content = None
525
+ # Check the content is reasoning_content or content
526
+ if hasattr(chunk.choices[0].delta, "reasoning_content"):
527
+ reasoning_content = chunk.choices[0].delta.reasoning_content
528
+ if hasattr(chunk.choices[0].delta, "content"):
529
+ content = chunk.choices[0].delta.content
530
+
531
+ if reasoning_content is not None:
532
+ if not printed_reasoning_content:
533
+ printed_reasoning_content = True
534
+ print("Start reasoning:\n", end="", flush=True)
535
+ print(reasoning_content, end="", flush=True)
536
+ if content is not None:
537
+ # Extract and print the content
538
+ if not reasoning_content and printed_reasoning_content:
539
+ answer.extend(content)
540
+ print(content, end="", flush=True)
541
+
542
+ if answer:
543
+ print("\n\n=============\nAnswer\n=============\n")
544
+ print("".join(answer))
545
+ else:
546
+ print("\n\n=============\nNo Answer\n=============\n")
547
+ print("No answer was generated by the model, probably because the maximum number of tokens was reached.")
548
+ ```
549
+
550
+ </details>
551
+
552
+ ### Transformers
553
+
554
+ You can also use Ministral 3 3B Reasoning 2512 with `Transformers` !
555
+ Make sure to install `Transformers` from its first v5 release candidate or from "main":
556
+
557
+ ```
558
+ pip install transformers==5.0.0rc0
559
+ ```
560
+
561
+ To make the best use of our model with `Transformers` make sure to have [installed](https://github.com/mistralai/mistral-common) `mistral-common >= 1.8.6` to use our tokenizer.
562
+
563
+ ```bash
564
+ pip install mistral-common --upgrade
565
+ ```
566
+
567
+ Then load our tokenizer along with the model and generate:
568
+
569
+ <details>
570
+ <summary>Python snippet</summary>
571
+
572
+ ```python
573
+ import torch
574
+ from transformers import Mistral3ForConditionalGeneration, MistralCommonBackend
575
+
576
+ model_id = "mistralai/Ministral-3-14B-Reasoning-2512"
577
+
578
+ tokenizer = MistralCommonBackend.from_pretrained(model_id)
579
+ model = Mistral3ForConditionalGeneration.from_pretrained(
580
+ model_id, torch_dtype=torch.bfloat16, device_map="auto"
581
+ )
582
+
583
+ image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
584
+
585
+ messages = [
586
+ {
587
+ "role": "user",
588
+ "content": [
589
+ {
590
+ "type": "text",
591
+ "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.",
592
+ },
593
+ {"type": "image_url", "image_url": {"url": image_url}},
594
+ ],
595
+ },
596
+ ]
597
+
598
+ tokenized = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True)
599
+
600
+ tokenized["input_ids"] = tokenized["input_ids"].to(device="cuda")
601
+ tokenized["pixel_values"] = tokenized["pixel_values"].to(dtype=torch.bfloat16, device="cuda")
602
+ image_sizes = [tokenized["pixel_values"].shape[-2:]]
603
+
604
+ output = model.generate(
605
+ **tokenized,
606
+ image_sizes=image_sizes,
607
+ max_new_tokens=8092,
608
+ )[0]
609
+
610
+ decoded_output = tokenizer.decode(output[len(tokenized["input_ids"][0]):])
611
+ print(decoded_output)
612
+ ```
613
+
614
+ </details>
615
+
616
+ ## License
617
+
618
+ This model is licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.txt).
619
+
620
+ *You must not use this model in a manner that infringes, misappropriates, or otherwise violates any third party’s rights, including intellectual property rights.*