Final improvements

#3
by Xenova HF Staff - opened
Files changed (2) hide show
  1. README.md +245 -3
  2. config.json +5 -0
README.md CHANGED
@@ -14,9 +14,13 @@ language:
14
  - ja
15
  - ko
16
  - ar
 
 
 
 
17
  ---
18
  > [!Tip]
19
- > This model was contributed by [Joshua](https://huggingface.co/Xenova) from Hugging Face. We sincerely appreciate the integration and community collaboration. While preliminary functionality checks have been performed, comprehensive testing has not yet been completed. We recommend you to proceed with caution and conducting your own evaluations for specific use cases. If any issues arise, open a PR/Issue here and we will try to address them promptly.
20
 
21
  # Ministral 3 3B Instruct 2512
22
  The smallest model in the Ministral 3 family, **Ministral 3 3B** is a powerful, efficient tiny language model with vision capabilities.
@@ -119,6 +123,139 @@ We compare Ministral 3 to similar sized models.
119
 
120
  ## Usage
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  ### ONNXRuntime
123
 
124
  ```py
@@ -223,9 +360,114 @@ print()
223
  print(processor.batch_decode(generated_tokens, skip_special_tokens=True)[0])
224
  ```
225
 
226
- ### Transformers.js
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
- TODO
229
 
230
  ## License
231
 
 
14
  - ja
15
  - ko
16
  - ar
17
+ library_name: transformers.js
18
+ tags:
19
+ - onnxruntime
20
+ pipeline_tag: image-text-to-text
21
  ---
22
  > [!Tip]
23
+ > This model was contributed by [Xenova](https://huggingface.co/Xenova) from Hugging Face. We sincerely appreciate the integration and community collaboration. While preliminary functionality checks have been performed, comprehensive testing has not yet been completed. We recommend you to proceed with caution and conducting your own evaluations for specific use cases. If any issues arise, open a PR/Issue here and we will try to address them promptly.
24
 
25
  # Ministral 3 3B Instruct 2512
26
  The smallest model in the Ministral 3 family, **Ministral 3 3B** is a powerful, efficient tiny language model with vision capabilities.
 
123
 
124
  ## Usage
125
 
126
+
127
+ ### Transformers.js
128
+
129
+ #### Online WebGPU Demo
130
+
131
+ You can test out the model directly in your browser using our online WebGPU demo: https://huggingface.co/spaces/mistralai/Ministral_3B_WebGPU.
132
+
133
+ <video src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/LA0XUsH9pFZaphbfF-HGm.mp4" controls autoplay muted></video>
134
+
135
+ #### JavaScript
136
+
137
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
138
+ ```bash
139
+ npm i @huggingface/transformers
140
+ ```
141
+
142
+ You can then run the model as follows:
143
+ ```js
144
+ import {
145
+ AutoProcessor,
146
+ AutoModelForImageTextToText,
147
+ load_image,
148
+ TextStreamer,
149
+ } from "@huggingface/transformers";
150
+
151
+ // Load processor and model
152
+ const model_id = "mistralai/Ministral-3-3B-Instruct-2512-ONNX";
153
+ const processor = await AutoProcessor.from_pretrained(model_id);
154
+ const model = await AutoModelForImageTextToText.from_pretrained(model_id, {
155
+ device: "webgpu",
156
+ });
157
+
158
+ // Prepare inputs
159
+ const messages = [
160
+ {
161
+ role: "user",
162
+ content: [
163
+ { type: "image" },
164
+ {
165
+ type: "text",
166
+ 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.",
167
+ },
168
+ ],
169
+ },
170
+ ]
171
+ const prompt = processor.apply_chat_template(messages);
172
+ const url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438";
173
+ const image = await load_image(url);
174
+ const inputs = await processor(image, prompt, { add_special_tokens: false });
175
+
176
+ // Generate response
177
+ const outputs = await model.generate({
178
+ ...inputs,
179
+ max_new_tokens: 2048,
180
+ streamer: new TextStreamer(processor.tokenizer, {
181
+ skip_prompt: true,
182
+ // callback_function: (text) => { /* Do something with the streamed output */ },
183
+ }),
184
+ });
185
+
186
+ // Decode output
187
+ const decoded = processor.batch_decode(
188
+ outputs.slice(null, [inputs.input_ids.dims.at(-1), null]),
189
+ { skip_special_tokens: true },
190
+ );
191
+ console.log(decoded[0]);
192
+ ```
193
+
194
+ <details>
195
+
196
+ <summary>See example output</summary>
197
+
198
+ ```
199
+ In this Pokémon game screenshot, you have several potential actions to consider, depending on the situation and your strategy. Here are the possible actions and their implications:
200
+
201
+ ---
202
+
203
+ ### **1. FIGHT**
204
+ **Description:** Use the Pikachu in your possession to attack the Pidgey.
205
+
206
+ #### **Pros:**
207
+ - **Potential to defeat Pidgey:** If Pikachu has strong moves (e.g., Thunderbolt, Electric Move) and Pidgey is weak to Electric-type attacks, this could be a strong choice.
208
+ - **Experience Gain:** Winning battles typically rewards you with experience points (XP) and sometimes drops Pidgey as a captured Pokémon.
209
+ - **Training Opportunity:** Helps you level up Pikachu, which can improve its stats and access new moves.
210
+
211
+ #### **Cons:**
212
+ - **Risk of Losing Pikachu:** If Pikachu is already at a low HP (e.g., 83/83 is not bad, but if it's lower), a loss could be detrimental.
213
+ - **Move Selection Matters:** If Pikachu doesn’t have a strong move against Pidgey, you might lose the battle unnecessarily.
214
+ - **Stamina Cost:** Battles can consume stamina if you're on a timer-based system (e.g., Pokémon Red/Blue).
215
+
216
+ ---
217
+
218
+ ### **2. RUN**
219
+ **Description:** Use the "Run" option to escape the battle.
220
+
221
+ #### **Pros:**
222
+ - **Avoids Risk:** If you're unsure about Pikachu’s moves or HP, running could save you from a potentially bad outcome.
223
+ - **Preserves Resources:** Running avoids losing Pikachu’s HP, which could be useful if you're running low.
224
+ - **Flexibility:** Allows you to explore or use other Pokémon later.
225
+
226
+ #### **Cons:**
227
+ - **No XP Gain:** Running means you won’t earn XP for defeating Pidgey.
228
+ - **Potential Consequences:** If you run too often, you might miss out on capturing Pidgey or gaining experience.
229
+ - **No Training:** Pikachu won’t level up or gain new moves if you avoid battles.
230
+
231
+ ---
232
+
233
+ ### **3. POKEMON (Select Another Pokémon)**
234
+ **Description:** If you have another Pokémon in your party, you could switch to it.
235
+
236
+ #### **Pros:**
237
+ - **Better Move Selection:** If you have a stronger Pokémon (e.g., a Fire-type or Ground-type) that can handle Pidgey, switching could be beneficial.
238
+ - **Balanced Strategy:** Helps you manage your team better.
239
+ - **Avoids Weaknesses:** If Pikachu is weak to something Pidgey might use, switching could prevent a loss.
240
+
241
+ #### **Cons:**
242
+ - **No Immediate XP Gain:** Switching doesn’t defeat Pidgey, so you won’t earn XP.
243
+ - **Stamina Cost:** Switching might still consume stamina if you're on a timer.
244
+ - **Potential to Lose Pikachu:** If you switch and Pikachu is already at a low HP, you might lose it.
245
+
246
+ ---
247
+
248
+ ### **Best Strategy Based on the Image:**
249
+ - **If you want to capture Pidgey:** Fighting is the best option, as it rewards you with experience and potentially captures Pidgey.
250
+ - **If you're unsure about Pikachu’s moves:** Running could be safer, but you might miss out on XP.
251
+ - **If you have another Pokémon:** Switching could be a good idea if you have a stronger option.
252
+
253
+ Would you like to know what moves Pikachu might have, or do you have another Pokémon in your party? That could help decide the best action!
254
+ ```
255
+
256
+ </details>
257
+
258
+
259
  ### ONNXRuntime
260
 
261
  ```py
 
360
  print(processor.batch_decode(generated_tokens, skip_special_tokens=True)[0])
361
  ```
362
 
363
+ <details>
364
+ <summary>See example output</summary>
365
+
366
+ ```
367
+ In this *Pokémon* game screenshot, you are presented with a battle scenario between **Pidgey** and **Pikachu**. Here are the possible actions along with an analysis of their potential outcomes:
368
+
369
+ ---
370
+
371
+ ### **1. FIGHT**
372
+ **Explanation:**
373
+ - You choose to engage in battle.
374
+ - Pidgey is a **Level 17** Pokémon with basic stats, while Pikachu is a **Level 42** Pokémon with significantly higher HP, Attack, and overall power.
375
+ - **Pros:**
376
+ - Pikachu is stronger and likely to win if it lands a hit.
377
+ - Pidgey may be able to land a few moves before being overwhelmed.
378
+ - **Cons:**
379
+ - Pidgey is likely to lose quickly due to its lower stats and experience.
380
+ - Pikachu may have a high chance of winning in one or two turns.
381
+
382
+ ---
383
+
384
+ ### **2. BAG**
385
+ **Explanation:**
386
+ - You choose to **Bag** Pikachu.
387
+ - **Pros:**
388
+ - You can keep Pikachu in your bag for later use.
389
+ - If you need to switch Pokémon or use Pikachu in another battle, this is a viable option.
390
+ - **Cons:**
391
+ - You miss out on the opportunity to potentially defeat Pidgey and gain experience.
392
+ - If Pidgey is a rare or special Pokémon, bagging it might not be ideal.
393
+
394
+ ---
395
+
396
+ ### **3. RUN**
397
+ **Explanation:**
398
+ - You choose to **Run** (escape the battle).
399
+ - **Pros:**
400
+ - You avoid losing HP and experience points.
401
+ - You can continue your journey without facing a weaker opponent.
402
+ - **Cons:**
403
+ - You might miss out on a chance to level up Pikachu or gain experience.
404
+ - If you are in a competitive setting, running might not be the best strategy.
405
+
406
+ ---
407
+
408
+ ### **Summary of Best Options:**
409
+ - **If you want to continue the game and gain experience:**
410
+ - **Fight** Pikachu, but be prepared for a potentially quick loss.
411
+ - **If you want to save Pikachu for later:**
412
+ - **Bag** Pikachu and continue your journey.
413
+ - **If you want to avoid unnecessary battles:**
414
+ - **Run** away from the battle.
415
+
416
+ Since Pikachu is significantly stronger, **Fighting** is the most straightforward choice, but you might want to consider **Bagging** Pikachu if you want to keep it for later battles. If you're not in a rush, **Running** is also a viable option.
417
+ In this *Pokémon* game screenshot, you are presented with a battle scenario between **Pidgey** and **Pikachu**. Here are the possible actions along with an analysis of their potential outcomes:
418
+
419
+ ---
420
+
421
+ ### **1. FIGHT**
422
+ **Explanation:**
423
+ - You choose to engage in battle.
424
+ - Pidgey is a **Level 17** Pokémon with basic stats, while Pikachu is a **Level 42** Pokémon with significantly higher HP, Attack, and overall power.
425
+ - **Pros:**
426
+ - Pikachu is stronger and likely to win if it lands a hit.
427
+ - Pidgey may be able to land a few moves before being overwhelmed.
428
+ - **Cons:**
429
+ - Pidgey is likely to lose quickly due to its lower stats and experience.
430
+ - Pikachu may have a high chance of winning in one or two turns.
431
+
432
+ ---
433
+
434
+ ### **2. BAG**
435
+ **Explanation:**
436
+ - You choose to **Bag** Pikachu.
437
+ - **Pros:**
438
+ - You can keep Pikachu in your bag for later use.
439
+ - If you need to switch Pokémon or use Pikachu in another battle, this is a viable option.
440
+ - **Cons:**
441
+ - You miss out on the opportunity to potentially defeat Pidgey and gain experience.
442
+ - If Pidgey is a rare or special Pokémon, bagging it might not be ideal.
443
+
444
+ ---
445
+
446
+ ### **3. RUN**
447
+ **Explanation:**
448
+ - You choose to **Run** (escape the battle).
449
+ - **Pros:**
450
+ - You avoid losing HP and experience points.
451
+ - You can continue your journey without facing a weaker opponent.
452
+ - **Cons:**
453
+ - You might miss out on a chance to level up Pikachu or gain experience.
454
+ - If you are in a competitive setting, running might not be the best strategy.
455
+
456
+ ---
457
+
458
+ ### **Summary of Best Options:**
459
+ - **If you want to continue the game and gain experience:**
460
+ - **Fight** Pikachu, but be prepared for a potentially quick loss.
461
+ - **If you want to save Pikachu for later:**
462
+ - **Bag** Pikachu and continue your journey.
463
+ - **If you want to avoid unnecessary battles:**
464
+ - **Run** away from the battle.
465
+
466
+ Since Pikachu is significantly stronger, **Fighting** is the most straightforward choice, but you might want to consider **Bagging** Pikachu if you want to keep it for later battles. If you're not in a rush, **Running** is also a viable option.
467
+ ```
468
+
469
+ </details>
470
 
 
471
 
472
  ## License
473
 
config.json CHANGED
@@ -88,6 +88,11 @@
88
  },
89
  "vision_feature_layer": -1,
90
  "transformers.js_config": {
 
 
 
 
 
91
  "use_external_data_format": {
92
  "embed_tokens.onnx": 1,
93
  "embed_tokens_fp16.onnx": 1,
 
88
  },
89
  "vision_feature_layer": -1,
90
  "transformers.js_config": {
91
+ "dtype": {
92
+ "decoder_model_merged": "q4f16",
93
+ "vision_encoder": "fp16",
94
+ "embed_tokens": "fp16"
95
+ },
96
  "use_external_data_format": {
97
  "embed_tokens.onnx": 1,
98
  "embed_tokens_fp16.onnx": 1,