The Mistral-Nemo-Instruct-2407 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-Nemo-Base-2407. Trained jointly by Mistral AI and NVIDIA, it significantly outperforms existing models smaller or similar in size.
For more details about this model please refer to our release blog post.
Key features
Released under the Apache 2 License
Pre-trained and instructed versions
Trained with a 128k context window
Trained on a large proportion of multilingual and code data
Drop-in replacement of Mistral 7B
Model Architecture
Mistral Nemo is a transformer model, with the following architecture choices:
Layers: 40
Dim: 5,120
Head dim: 128
Hidden dim: 14,336
Activation Function: SwiGLU
Number of heads: 32
Number of kv-heads: 8 (GQA)
Vocabulary size: 2**17 ~= 128k
Rotary embeddings (theta = 1M)
Metrics
Main Benchmarks
Benchmark
Score
HellaSwag (0-shot)
83.5%
Winogrande (0-shot)
76.8%
OpenBookQA (0-shot)
60.6%
CommonSenseQA (0-shot)
70.4%
TruthfulQA (0-shot)
50.3%
MMLU (5-shot)
68.0%
TriviaQA (5-shot)
73.8%
NaturalQuestions (5-shot)
31.2%
Multilingual Benchmarks (MMLU)
Language
Score
French
62.3%
German
62.7%
Spanish
64.6%
Italian
61.3%
Portuguese
63.3%
Russian
59.2%
Chinese
59.0%
Japanese
59.0%
Usage
The model can be used with three different frameworks
How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar.
Instruct following
py
1from mistral_inference.transformer import Transformer
2from mistral_inference.generate import generate
34from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
5from mistral_common.protocol.instruct.messages import UserMessage
6from mistral_common.protocol.instruct.request import ChatCompletionRequest
78tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")9model = Transformer.from_folder(mistral_models_path)1011prompt ="How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar."1213completion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])1415tokens = tokenizer.encode_chat_completion(completion_request).tokens
1617out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)18result = tokenizer.decode(out_tokens[0])1920print(result)
Function calling
py
1from mistral_common.protocol.instruct.tool_calls import Function, Tool
2from mistral_inference.transformer import Transformer
3from mistral_inference.generate import generate
45from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from mistral_common.protocol.instruct.messages import UserMessage
7from mistral_common.protocol.instruct.request import ChatCompletionRequest
8910tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")11model = Transformer.from_folder(mistral_models_path)1213completion_request = ChatCompletionRequest(14 tools=[15 Tool(16 function=Function(17 name="get_current_weather",18 description="Get the current weather",19 parameters={20"type":"object",21"properties":{22"location":{23"type":"string",24"description":"The city and state, e.g. San Francisco, CA",25},26"format":{27"type":"string",28"enum":["celsius","fahrenheit"],29"description":"The temperature unit to use. Infer this from the users location.",30},31},32"required":["location","format"],33},34)35)36],37 messages=[38 UserMessage(content="What's the weather like today in Paris?"),39],40)4142tokens = tokenizer.encode_chat_completion(completion_request).tokens
4344out_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)45result = tokenizer.decode(out_tokens[0])4647print(result)
Transformers
[!IMPORTANT]
NOTE: Until a new release has been made, you need to install transformers from source:
If you want to use Hugging Face transformers to generate text, you can do something like this.
py
1from transformers import pipeline
23messages =[4{"role":"system","content":"You are a pirate chatbot who always responds in pirate speak!"},5{"role":"user","content":"Who are you?"},6]7chatbot = pipeline("text-generation", model="mistralai/Mistral-Nemo-Instruct-2407",max_new_tokens=128)8chatbot(messages)
Function calling with transformers
To use this example, you'll need transformers version 4.42.0 or higher. Please see the
function calling guide
in the transformers docs for more information.
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
34model_id ="mistralai/Mistral-Nemo-Instruct-2407"5tokenizer = AutoTokenizer.from_pretrained(model_id)67defget_current_weather(location:str,format:str):8"""
9 Get the current weather
1011 Args:
12 location: The city and state, e.g. San Francisco, CA
13 format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
14 """15pass1617conversation =[{"role":"user","content":"What's the weather like in Paris?"}]18tools =[get_current_weather]1920# render the tool use prompt as a string:21tool_use_prompt = tokenizer.apply_chat_template(22 conversation,23 tools=tools,24 tokenize=False,25 add_generation_prompt=True,26)2728inputs = tokenizer(tool_use_prompt, return_tensors="pt")2930model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")3132outputs = model.generate(**inputs, max_new_tokens=1000)33print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Note that, for reasons of space, this example does not show a complete cycle of calling a tool and adding the tool call and tool
results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
see the function calling guide,
and note that Mistral does use tool call IDs, so these must be included in your tool calls and tool results. They should be
exactly 9 alphanumeric characters.
[!TIP]
Unlike previous Mistral models, Mistral Nemo requires smaller temperatures. We recommend to use a temperature of 0.3.
Limitations
The Mistral Nemo Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
The Mistral AI Team
Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Alok Kothari, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Augustin Garreau, Austin Birky, Bam4d, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Carole Rambaud, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gaspard Blanchet, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Henri Roussez, Hichem Sattouf, Ian Mack, Jean-Malo Delignon, Jessica Chudnovsky, Justus Murke, Kartik Khandelwal, Lawrence Stewart, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Marjorie Janiewicz, Mickaël Seznec, Nicolas Schuhl, Niklas Muhs, Olivier de Garrigues, Patrick von Platen, Paul Jacob, Pauline Buche, Pavan Kumar Reddy, Perry Savas, Pierre Stock, Romain Sauvestre, Sagar Vaze, Sandeep Subramanian, Saurabh Garg, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibault Schueller, Thibaut Lavril, Thomas Wang, Théophile Gervet, Timothée Lacroix, Valera Nemychnikova, Wendy Shang, William El Sayed, William Marshall