[!NOTE]
Includes Unsloth chat template fixes! For llama.cpp, use --jinja
Unsloth Dynamic 2.0 achieves superior accuracy & outperforms other leading quants.
Mistral Small 4 119B A6B
Mistral Small 4 is a powerful hybrid model capable of acting as both a general instruction model and a reasoning model. It unifies the capabilities of three different model families—Instruct, Reasoning (previously called Magistral), and Devstral—into a single, unified model.
With its multimodal capabilities, efficient architecture, and flexible mode switching, it is a powerful general-purpose model for any task. In a latency-optimized setup, Mistral Small 4 achieves a 40% reduction in end-to-end completion time, and in a throughput-optimized setup, it handles 3x more requests per second compared to Mistral Small 3.
To further improve efficiency you can either take advantages of:
Mistral Small 4 includes the following architectural choices:
MoE: 128 experts, 4 active.
119B parameters, with 6.5B activated per token.
256k context length.
Multimodal input: Accepts both text and image input, with text output.
Instruct and Reasoning functionalities with function calls (reasoning effort configurable per request).
Mistral Small 4 offers the following capabilities:
Reasoning Mode: Toggle between fast instant reply mode and reasoning mode, boosting performance with test-time compute when requested.
Vision: Analyzes images and provides insights based on visual content, in addition to text.
Multilingual: Supports dozens of languages, including English, French, Spanish, German, Italian, Portuguese, Dutch, Chinese, Japanese, Korean, and Arabic.
System Prompt: Strong adherence and support for system prompts.
Agentic: Best-in-class agentic capabilities with native function calling and JSON output.
Speed-Optimized: Delivers best-in-class performance and speed.
Apache 2.0 License: Open-source license for both commercial and non-commercial use.
Large Context Window: Supports a 256k context window.
Use Cases
Mistral Small 4 is designed for general chat assistants, coding, agentic tasks, and reasoning tasks (with reasoning mode toggled). Its multimodal capabilities also enable document and image understanding for data extraction and analysis.
Its capabilities are ideal for:
Developers interested in coding and agentic capabilities for SWE automation and codebase exploration.
Enterprises seeking general chat assistants, agents, and document understanding.
Researchers leveraging its math and research capabilities.
Mistral Small 4 is also well-suited for customization and fine-tuning for more specialized tasks.
Examples
General chat assistant
Document parsing and extraction
Coding agent
Research assistant
Customization & fine-tuning
And more...
Benchmarks
Comparison with internal models
Depending on your tasks you can trigger reasoning thanks to the support of the per-request parameter reasoning_effort. Set it to:
reasoning_effort="high": Deep, step-by-step reasoning for complex problems, with equivalent verbosity to previous Magistral models such as mistralai/Magistral-Small-2509.
Internal benchmark
Comparing Reasoning Models
Internal benchmark - Reasoning
Comparison with other models
Mistral Small 4 with reasoning achieves competitive scores, matching or surpassing GPT-OSS 120B across all three benchmarks while generating significantly
shorter outputs. On AA LCR, Mistral Small 4 scores 0.72 with just 1.6K characters, whereas Qwen models require 3.5-4x more output (5.8-6.1K)
for comparable performance. On LiveCodeBench, Mistral Small 4 outperforms GPT-OSS 120B while producing 20% less output.
This efficiency reduces latency, inference costs, and improves user experience.
Comparison benchmark - LCR
Comparison benchmark - LiveCodeBench
Comparison benchmark - AIME25
Usage
You can find Mistral Small 4 support on multiple libraries for inference and fine-tuning. We here thank everyone contributors and maintainers that helped us making it happen.
We recommend using Mistral Small 4 with the vLLM library for production-ready inference.
Installation
[!Tip]
Use our custom Docker image with fixes for tool calling and reasoning parsing in vLLM, and the latest Transformers version. We are working with the vLLM team to merge these fixes soon.
Mistral Small 4 can follow your instructions to the letter.
python
1from datetime import datetime, timedelta
23from openai import OpenAI
4from huggingface_hub import hf_hub_download
56# 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"910TEMP =0.11112client = OpenAI(13 api_key=openai_api_key,14 base_url=openai_api_base,15)1617models = client.models.list()18model = models.data[0].id192021defload_system_prompt(repo_id:str, filename:str)->str:22 file_path = hf_hub_download(repo_id=repo_id, filename=filename)23withopen(file_path,"r")asfile:24 system_prompt =file.read()25 today = datetime.today().strftime("%Y-%m-%d")26 yesterday =(datetime.today()- timedelta(days=1)).strftime("%Y-%m-%d")27 model_name = repo_id.split("/")[-1]28return system_prompt.format(name=model_name, today=today, yesterday=yesterday)293031SYSTEM_PROMPT = load_system_prompt(model,"SYSTEM_PROMPT.txt")3233messages =[34{"role":"system","content": SYSTEM_PROMPT},35{36"role":"user",37"content":"Write me a sentence where every word starts with the next letter in the alphabet - start with 'a' and end with 'z'.",38},39]4041response = client.chat.completions.create(42 model=model,43 messages=messages,44 temperature=TEMP,45 reasoning_effort="none",46)4748assistant_message = response.choices[0].message.content
49print(assistant_message)
Tool Call
Let's solve some equations thanks to our simple Python calculator tool.
python
1import json
2from datetime import datetime, timedelta
34from openai import OpenAI
5from huggingface_hub import hf_hub_download
67# Modify OpenAI's API key and API base to use vLLM's API server.8openai_api_key ="EMPTY"9openai_api_base ="http://localhost:8000/v1"1011TEMP =0.11213client = OpenAI(14 api_key=openai_api_key,15 base_url=openai_api_base,16)1718models = client.models.list()19model = models.data[0].id202122defload_system_prompt(repo_id:str, filename:str)->str:23 file_path = hf_hub_download(repo_id=repo_id, filename=filename)24withopen(file_path,"r")asfile: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]29return system_prompt.format(name=model_name, today=today, yesterday=yesterday)303132SYSTEM_PROMPT = load_system_prompt(model,"SYSTEM_PROMPT.txt")3334image_url ="https://math-coaching.com/img/fiche/46/expressions-mathematiques.jpg"353637defmy_calculator(expression:str)->str:38returnstr(eval(expression))394041tools =[42{43"type":"function",44"function":{45"name":"my_calculator",46"description":"A calculator that can evaluate a mathematical expression.",47"parameters":{48"type":"object",49"properties":{50"expression":{51"type":"string",52"description":"The mathematical expression to evaluate.",53},54},55"required":["expression"],56},57},58},59{60"type":"function",61"function":{62"name":"rewrite",63"description":"Rewrite a given text for improved clarity",64"parameters":{65"type":"object",66"properties":{67"text":{68"type":"string",69"description":"The input text to rewrite",70}71},72},73},74},75]7677messages =[78{"role":"system","content": SYSTEM_PROMPT},79{80"role":"user",81"content":[82{83"type":"text",84"text":"Thanks to your calculator, compute the results for the equations that involve numbers displayed in the image.",85},86{87"type":"image_url",88"image_url":{89"url": image_url,90},91},92],93},94]9596response = client.chat.completions.create(97 model=model,98 messages=messages,99 temperature=TEMP,100 tools=tools,101 tool_choice="auto",102 reasoning_effort="none",103)104105tool_calls = response.choices[0].message.tool_calls
106107results =[]108for tool_call in tool_calls:109 function_name = tool_call.function.name
110 function_args = tool_call.function.arguments
111if function_name =="my_calculator":112 result = my_calculator(**json.loads(function_args))113 results.append(result)114115messages.append({"role":"assistant","tool_calls": tool_calls})116for tool_call, result inzip(tool_calls, results):117 messages.append(118{119"role":"tool",120"tool_call_id": tool_call.id,121"name": tool_call.function.name,122"content": result,123}124)125126127response = client.chat.completions.create(128 model=model,129 messages=messages,130 temperature=TEMP,131 reasoning_effort="none",132)133134print(response.choices[0].message.content)
Vision Reasoning
Let's see if the Mistral Small 4 knows when to pick a fight !
python
1from datetime import datetime, timedelta
23from openai import OpenAI
4from huggingface_hub import hf_hub_download
56# 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"910TEMP =0.11112client = OpenAI(13 api_key=openai_api_key,14 base_url=openai_api_base,15)1617models = client.models.list()18model = models.data[0].id192021defload_system_prompt(repo_id:str, filename:str)->str:22 file_path = hf_hub_download(repo_id=repo_id, filename=filename)23withopen(file_path,"r")asfile:24 system_prompt =file.read()25 today = datetime.today().strftime("%Y-%m-%d")26 yesterday =(datetime.today()- timedelta(days=1)).strftime("%Y-%m-%d")27 model_name = repo_id.split("/")[-1]28return system_prompt.format(name=model_name, today=today, yesterday=yesterday)293031SYSTEM_PROMPT = load_system_prompt(model,"SYSTEM_PROMPT.txt")32image_url ="https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"3334messages =[35{"role":"system","content": SYSTEM_PROMPT},36{37"role":"user",38"content":[39{40"type":"text",41"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.",42},43{"type":"image_url","image_url":{"url": image_url}},44],45},46]474849response = client.chat.completions.create(50 model=model,51 messages=messages,52 temperature=TEMP,53 reasoning_effort="high",54)5556print(response.choices[0].message.content)
Transformers
Installation
You need to install the main branch of Transformers to use Mistral Small 4:
Note: Current implementation of Transformers does not support FP8.
Weights have been stored in FP8 and updates to load them in this format are expected, in the meantime we provide BF16 quantization snippets to ease usage.
As soon as support is added, we will update the following code snippet.
Python Inference Snippet
python
1from pathlib import Path
23import torch
4from huggingface_hub import snapshot_download
5from safetensors.torch import load_file
6from tqdm import tqdm
78from transformers import AutoConfig, AutoProcessor, Mistral3ForConditionalGeneration
91011def_descale_fp8_to_bf16(tensor: torch.Tensor, scale_inv: torch.Tensor)-> torch.Tensor:12return(tensor.to(torch.bfloat16)* scale_inv.to(torch.bfloat16)).to(torch.bfloat16)131415def_resolve_model_dir(model_id:str)-> Path:16 local = Path(model_id)17if local.is_dir():18return local
19return Path(snapshot_download(model_id, allow_patterns=["model*.safetensors"]))202122defload_and_dequantize_state_dict(model_id:str)->dict[str, torch.Tensor]:23 model_dir = _resolve_model_dir(model_id)2425 shards =sorted(model_dir.glob("model*.safetensors"))2627 full_state_dict:dict[str, torch.Tensor]={}28for shard in tqdm(shards, desc="Loading safetensors shards"):29 full_state_dict.update(load_file(str(shard)))3031 scale_suffixes =("weight_scale_inv","gate_up_proj_scale_inv","down_proj_scale_inv","up_proj_scale_inv")32 activation_scale_suffixes =("activation_scale","gate_up_proj_activation_scale","down_proj_activation_scale")3334 keys_to_remove:set[str]=set()35 all_keys =list(full_state_dict.keys())3637for key in tqdm(all_keys, desc="Dequantizing FP8 weights to BF16"):38ifany(key.endswith(s)for s in scale_suffixes + activation_scale_suffixes):39continue4041for scale_suffix in scale_suffixes:42if scale_suffix =="weight_scale_inv":43ifnot key.endswith(".weight"):44continue45 scale_key = key.rsplit(".weight",1)[0]+".weight_scale_inv"46else:47 proj_name = scale_suffix.replace("_scale_inv","")48ifnot key.endswith(f".{proj_name}"):49continue50 scale_key = key +"_scale_inv"5152if scale_key in full_state_dict:53 full_state_dict[key]= _descale_fp8_to_bf16(full_state_dict[key], full_state_dict[scale_key])54 keys_to_remove.add(scale_key)5556for key in full_state_dict:57ifany(key.endswith(s)for s in activation_scale_suffixes):58 keys_to_remove.add(key)5960for key in tqdm(keys_to_remove, desc="Removing scale keys"):61del full_state_dict[key]6263return full_state_dict
646566defload_config_without_quantization(model_id:str)-> AutoConfig:67 config = AutoConfig.from_pretrained(model_id)6869ifhasattr(config,"quantization_config"):70del config.quantization_config
7172ifhasattr(config,"text_config")andhasattr(config.text_config,"quantization_config"):73del config.text_config.quantization_config
7475return config
767778model_id ="mistralai/Mistral-Small-4-119B-2603"7980config = load_config_without_quantization(model_id)81state_dict = load_and_dequantize_state_dict(model_id)8283model = Mistral3ForConditionalGeneration.from_pretrained(84None,85 config=config,86 state_dict=state_dict,87 device_map="auto",88)8990processor = AutoProcessor.from_pretrained(model_id)9192image_url ="https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"9394messages =[95{96"role":"user",97"content":[98{99"type":"text",100"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.",101},102{"type":"image_url","image_url":{"url": image_url}},103],104},105]106107inputs = processor.apply_chat_template(108 messages, return_tensors="pt", tokenize=True, return_dict=True, reasoning_effort="high"109)110inputs = inputs.to(model.device)111112output = model.generate(113**inputs,114 max_new_tokens=1024,115)[0]116117# Setting `skip_special_tokens=False` to visualize reasoning trace between [THINK] [/THINK] tags.118decoded_output = processor.decode(output[len(inputs["input_ids"][0]):], skip_special_tokens=False)119print(decoded_output)