xumingtensor commited on
Commit
c544148
·
verified ·
1 Parent(s): f435456

Update README.md

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