Views
No views yet
[!NOTE]
Includes our GGUF chat template fixes! Tool calling works as well!
If you are usingllama.cpp, use--jinjato enable the system prompt.
./llama.cpp/llama-cli -hf unsloth/Mistral-Small-3.2-24B-Instruct-2506-GGUF:UD-Q4_K_XL --jinja --temp 0.15 --top-k -1 --top-p 1.00 -ngl 99ollama run hf.co/unsloth/Mistral-Small-3.2-24B-Instruct-2506-GGUF:UD-Q4_K_XL| Model | Wildbench v2 | Arena Hard v2 | IF (Internal; accuracy) |
|---|---|---|---|
| Small 3.1 24B Instruct | 55.6% | 19.56% | 82.75% |
| Small 3.2 24B Instruct | 65.33% | 43.1% | 84.78% |
| Model | Infinite Generations (Internal; Lower is better) |
|---|---|
| Small 3.1 24B Instruct | 2.11% |
| Small 3.2 24B Instruct | 1.29% |
| 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) |
|---|---|---|---|---|---|---|---|---|
| Small 3.1 24B Instruct | 80.62% | 66.76% | 69.30% | 44.42% | 45.96% | 74.63% | 88.99% | 10.43% |
| Small 3.2 24B Instruct | 80.50% | 69.06% | 69.42% | 44.22% | 46.13% | 78.33% | 92.90% | 12.10% |
| Model | MMMU | Mathvista | ChartQA | DocVQA | AI2D |
|---|---|---|---|---|---|
| Small 3.1 24B Instruct | 64.00% | 68.91% | 86.24% | 94.08% | 93.72% |
| Small 3.2 24B Instruct | 62.50% | 67.09% | 87.4% | 94.86% | 92.91% |
vllm (recommended): See heretransformers: See heretemperature=0.15.vLLM >= 0.9.1:pip install vllm --upgrademistral_common >= 1.6.2.python -c "import mistral_common; print(mistral_common.__version__)"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 21from datetime import datetime, timedelta
2
3from openai import OpenAI
4from huggingface_hub import hf_hub_download
5
6# Modify OpenAI's API key and API base to use vLLM's API server.
7openai_api_key = "EMPTY"
8openai_api_base = "http://localhost:8000/v1"
9
10TEMP = 0.15
11MAX_TOK = 131072
12
13client = OpenAI(
14 api_key=openai_api_key,
15 base_url=openai_api_base,
16)
17
18models = client.models.list()
19model = models.data[0].id
20
21
22def load_system_prompt(repo_id: str, filename: str) -> str:
23 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
24 with open(file_path, "r") as file:
25 system_prompt = file.read()
26 today = datetime.today().strftime("%Y-%m-%d")
27 yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
28 model_name = repo_id.split("/")[-1]
29 return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
30
31
32model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
33SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
34image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
35
36messages = [
37 {"role": "system", "content": SYSTEM_PROMPT},
38 {
39 "role": "user",
40 "content": [
41 {
42 "type": "text",
43 "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.",
44 },
45 {"type": "image_url", "image_url": {"url": image_url}},
46 ],
47 },
48]
49
50
51response = client.chat.completions.create(
52 model=model,
53 messages=messages,
54 temperature=TEMP,
55 max_tokens=MAX_TOK,
56)
57
58print(response.choices[0].message.content)
59# 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:
60
61# 1. **FIGHT**:
62# - **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.
63# - **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.
64
65# 2. **BAG**:
66# - **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.
67# - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat the Pidgey quickly.
68
69# 3. **POKÉMON**:
70# - **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.
71# - **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.
72
73# 4. **RUN**:
74# - **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.
75# - **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.
76
77# ### Recommendation:
78# 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.1from openai import OpenAI
2from huggingface_hub import hf_hub_download
3
4# Modify OpenAI's API key and API base to use vLLM's API server.
5openai_api_key = "EMPTY"
6openai_api_base = "http://localhost:8000/v1"
7
8TEMP = 0.15
9MAX_TOK = 131072
10
11client = OpenAI(
12 api_key=openai_api_key,
13 base_url=openai_api_base,
14)
15
16models = client.models.list()
17model = models.data[0].id
18
19def load_system_prompt(repo_id: str, filename: str) -> str:
20 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
21 with open(file_path, "r") as file:
22 system_prompt = file.read()
23 return system_prompt
24
25model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
26SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
27
28image_url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
29
30tools = [
31 {
32 "type": "function",
33 "function": {
34 "name": "get_current_population",
35 "description": "Get the up-to-date population of a given country.",
36 "parameters": {
37 "type": "object",
38 "properties": {
39 "country": {
40 "type": "string",
41 "description": "The country to find the population of.",
42 },
43 "unit": {
44 "type": "string",
45 "description": "The unit for the population.",
46 "enum": ["millions", "thousands"],
47 },
48 },
49 "required": ["country", "unit"],
50 },
51 },
52 },
53 {
54 "type": "function",
55 "function": {
56 "name": "rewrite",
57 "description": "Rewrite a given text for improved clarity",
58 "parameters": {
59 "type": "object",
60 "properties": {
61 "text": {
62 "type": "string",
63 "description": "The input text to rewrite",
64 }
65 },
66 },
67 },
68 },
69]
70
71messages = [
72 {"role": "system", "content": SYSTEM_PROMPT},
73 {
74 "role": "user",
75 "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.",
76 },
77 {
78 "role": "assistant",
79 "content": "",
80 "tool_calls": [
81 {
82 "id": "bbc5b7ede",
83 "type": "function",
84 "function": {
85 "name": "rewrite",
86 "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."}',
87 },
88 }
89 ],
90 },
91 {
92 "role": "tool",
93 "content": '{"action":"rewrite","outcome":"OpenAI is a FOR-profit company."}',
94 "tool_call_id": "bbc5b7ede",
95 "name": "rewrite",
96 },
97 {
98 "role": "assistant",
99 "content": "---\n\nOpenAI is a FOR-profit company.",
100 },
101 {
102 "role": "user",
103 "content": [
104 {
105 "type": "text",
106 "text": "Can you tell me what is the biggest country depicted on the map?",
107 },
108 {
109 "type": "image_url",
110 "image_url": {
111 "url": image_url,
112 },
113 },
114 ],
115 }
116]
117
118response = client.chat.completions.create(
119 model=model,
120 messages=messages,
121 temperature=TEMP,
122 max_tokens=MAX_TOK,
123 tools=tools,
124 tool_choice="auto",
125)
126
127assistant_message = response.choices[0].message.content
128print(assistant_message)
129# The biggest country depicted on the map is Russia.
130
131messages.extend([
132 {"role": "assistant", "content": assistant_message},
133 {"role": "user", "content": "What is the population of that country in millions?"},
134])
135
136response = client.chat.completions.create(
137 model=model,
138 messages=messages,
139 temperature=TEMP,
140 max_tokens=MAX_TOK,
141 tools=tools,
142 tool_choice="auto",
143)
144
145print(response.choices[0].message.tool_calls)
146# [ChatCompletionMessageToolCall(id='3e92V6Vfo', function=Function(arguments='{"country": "Russia", "unit": "millions"}', name='get_current_population'), type='function')]1import json
2from openai import OpenAI
3from huggingface_hub import hf_hub_download
4
5# Modify OpenAI's API key and API base to use vLLM's API server.
6openai_api_key = "EMPTY"
7openai_api_base = "http://localhost:8000/v1"
8
9TEMP = 0.15
10MAX_TOK = 131072
11
12client = OpenAI(
13 api_key=openai_api_key,
14 base_url=openai_api_base,
15)
16
17models = client.models.list()
18model = models.data[0].id
19
20
21def load_system_prompt(repo_id: str, filename: str) -> str:
22 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
23 with open(file_path, "r") as file:
24 system_prompt = file.read()
25 return system_prompt
26
27
28model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
29SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
30
31image_url = "https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"
32
33
34def my_calculator(expression: str) -> str:
35 return str(eval(expression))
36
37
38tools = [
39 {
40 "type": "function",
41 "function": {
42 "name": "my_calculator",
43 "description": "A calculator that can evaluate a mathematical expression.",
44 "parameters": {
45 "type": "object",
46 "properties": {
47 "expression": {
48 "type": "string",
49 "description": "The mathematical expression to evaluate.",
50 },
51 },
52 "required": ["expression"],
53 },
54 },
55 },
56 {
57 "type": "function",
58 "function": {
59 "name": "rewrite",
60 "description": "Rewrite a given text for improved clarity",
61 "parameters": {
62 "type": "object",
63 "properties": {
64 "text": {
65 "type": "string",
66 "description": "The input text to rewrite",
67 }
68 },
69 },
70 },
71 },
72]
73
74messages = [
75 {"role": "system", "content": SYSTEM_PROMPT},
76 {
77 "role": "user",
78 "content": [
79 {
80 "type": "text",
81 "text": "Can you calculate the results for all the equations displayed in the image? Only compute the ones that involve numbers.",
82 },
83 {
84 "type": "image_url",
85 "image_url": {
86 "url": image_url,
87 },
88 },
89 ],
90 },
91]
92
93response = client.chat.completions.create(
94 model=model,
95 messages=messages,
96 temperature=TEMP,
97 max_tokens=MAX_TOK,
98 tools=tools,
99 tool_choice="auto",
100)
101
102tool_calls = response.choices[0].message.tool_calls
103print(tool_calls)
104# [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')]
105
106results = []
107for tool_call in tool_calls:
108 function_name = tool_call.function.name
109 function_args = tool_call.function.arguments
110 if function_name == "my_calculator":
111 result = my_calculator(**json.loads(function_args))
112 results.append(result)
113
114messages.append({"role": "assistant", "tool_calls": tool_calls})
115for tool_call, result in zip(tool_calls, results):
116 messages.append(
117 {
118 "role": "tool",
119 "tool_call_id": tool_call.id,
120 "name": tool_call.function.name,
121 "content": result,
122 }
123 )
124
125
126response = client.chat.completions.create(
127 model=model,
128 messages=messages,
129 temperature=TEMP,
130 max_tokens=MAX_TOK,
131)
132
133print(response.choices[0].message.content)
134# Here are the results for the equations that involve numbers:
135
136# 1. \( 6 + 2 \times 3 = 12 \)
137# 3. \( 19 - (8 + 2) + 1 = 10 \)
138
139# For the other equations, you need to substitute the variables with specific values to compute the results.1from openai import OpenAI
2from huggingface_hub import hf_hub_download
3
4# Modify OpenAI's API key and API base to use vLLM's API server.
5openai_api_key = "EMPTY"
6openai_api_base = "http://localhost:8000/v1"
7
8TEMP = 0.15
9MAX_TOK = 131072
10
11client = OpenAI(
12 api_key=openai_api_key,
13 base_url=openai_api_base,
14)
15
16models = client.models.list()
17model = models.data[0].id
18
19
20def load_system_prompt(repo_id: str, filename: str) -> str:
21 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
22 with open(file_path, "r") as file:
23 system_prompt = file.read()
24 return system_prompt
25
26
27model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
28SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
29
30messages = [
31 {"role": "system", "content": SYSTEM_PROMPT},
32 {
33 "role": "user",
34 "content": "Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",
35 },
36]
37
38response = client.chat.completions.create(
39 model=model,
40 messages=messages,
41 temperature=TEMP,
42 max_tokens=MAX_TOK,
43)
44
45assistant_message = response.choices[0].message.content
46print(assistant_message)
47
48# Here's a sentence where each word starts with the next letter of the alphabet, starting from 'a' and ending with 'z':
49
50# "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."
51
52# This sentence follows the sequence from A to Z without skipping any letters.Transformers !Transformers make sure to have installed mistral-common >= 1.6.2 to use our tokenizer.pip install mistral-common --upgrade1from datetime import datetime, timedelta
2import torch
3
4from mistral_common.protocol.instruct.request import ChatCompletionRequest
5from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from huggingface_hub import hf_hub_download
7from transformers import Mistral3ForConditionalGeneration
8
9
10def load_system_prompt(repo_id: str, filename: str) -> str:
11 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
12 with open(file_path, "r") as file:
13 system_prompt = file.read()
14 today = datetime.today().strftime("%Y-%m-%d")
15 yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
16 model_name = repo_id.split("/")[-1]
17 return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
18
19
20model_id = "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
21SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
22
23tokenizer = MistralTokenizer.from_hf_hub(model_id)
24
25model = Mistral3ForConditionalGeneration.from_pretrained(
26 model_id, torch_dtype=torch.bfloat16
27)
28
29image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
30
31messages = [
32 {"role": "system", "content": SYSTEM_PROMPT},
33 {
34 "role": "user",
35 "content": [
36 {
37 "type": "text",
38 "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.",
39 },
40 {"type": "image_url", "image_url": {"url": image_url}},
41 ],
42 },
43]
44
45tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
46
47input_ids = torch.tensor([tokenized.tokens])
48attention_mask = torch.ones_like(input_ids)
49pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
50image_sizes = torch.tensor([pixel_values.shape[-2:]])
51
52output = model.generate(
53 input_ids=input_ids,
54 attention_mask=attention_mask,
55 pixel_values=pixel_values,
56 image_sizes=image_sizes,
57 max_new_tokens=1000,
58)[0]
59
60decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
61print(decoded_output)
62# 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:
63
64# 1. **FIGHT**:
65# - **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.
66# - **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.
67
68# 2. **BAG**:
69# - **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.
70# - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
71
72# 3. **POKÉMON**:
73# - **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.
74# - **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.
75
76# 4. **RUN**:
77# - **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.
78# - **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.
79
80# ### Recommendation:
81# 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.