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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: mistralai/Mistral-Nemo-Base-2407
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
- fr
|
6 |
+
- de
|
7 |
+
- es
|
8 |
+
- it
|
9 |
+
- pt
|
10 |
+
- ru
|
11 |
+
- zh
|
12 |
+
- ja
|
13 |
+
license: apache-2.0
|
14 |
+
extra_gated_description: If you want to learn more about how we process your personal
|
15 |
+
data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
|
16 |
+
model-index:
|
17 |
+
- name: Mistral-Nemo-Instruct-2407
|
18 |
+
results: []
|
19 |
+
---
|
20 |
+
|
21 |
+
# Model Card for Mistral-Nemo-Instruct-2407
|
22 |
+
|
23 |
+
The Mistral-Nemo-Instruct-2407 Large Language Model (LLM) is an instruct fine-tuned version of the [Mistral-Nemo-Base-2407](https://huggingface.co/mistralai/Mistral-Nemo-Base-2407). Trained jointly by Mistral AI and NVIDIA, it significantly outperforms existing models smaller or similar in size.
|
24 |
+
|
25 |
+
For more details about this model please refer to our release [blog post](https://mistral.ai/news/mistral-nemo/).
|
26 |
+
|
27 |
+
## Key features
|
28 |
+
- Released under the **Apache 2 License**
|
29 |
+
- Pre-trained and instructed versions
|
30 |
+
- Trained with a **128k context window**
|
31 |
+
- Trained on a large proportion of **multilingual and code data**
|
32 |
+
- Drop-in replacement of Mistral 7B
|
33 |
+
|
34 |
+
## Model Architecture
|
35 |
+
Mistral Nemo is a transformer model, with the following architecture choices:
|
36 |
+
- **Layers:** 40
|
37 |
+
- **Dim:** 5,120
|
38 |
+
- **Head dim:** 128
|
39 |
+
- **Hidden dim:** 14,336
|
40 |
+
- **Activation Function:** SwiGLU
|
41 |
+
- **Number of heads:** 32
|
42 |
+
- **Number of kv-heads:** 8 (GQA)
|
43 |
+
- **Vocabulary size:** 2**17 ~= 128k
|
44 |
+
- **Rotary embeddings (theta = 1M)**
|
45 |
+
|
46 |
+
## Metrics
|
47 |
+
|
48 |
+
### Main Benchmarks
|
49 |
+
|
50 |
+
| Benchmark | Score |
|
51 |
+
| --- | --- |
|
52 |
+
| HellaSwag (0-shot) | 83.5% |
|
53 |
+
| Winogrande (0-shot) | 76.8% |
|
54 |
+
| OpenBookQA (0-shot) | 60.6% |
|
55 |
+
| CommonSenseQA (0-shot) | 70.4% |
|
56 |
+
| TruthfulQA (0-shot) | 50.3% |
|
57 |
+
| MMLU (5-shot) | 68.0% |
|
58 |
+
| TriviaQA (5-shot) | 73.8% |
|
59 |
+
| NaturalQuestions (5-shot) | 31.2% |
|
60 |
+
|
61 |
+
### Multilingual Benchmarks (MMLU)
|
62 |
+
|
63 |
+
| Language | Score |
|
64 |
+
| --- | --- |
|
65 |
+
| French | 62.3% |
|
66 |
+
| German | 62.7% |
|
67 |
+
| Spanish | 64.6% |
|
68 |
+
| Italian | 61.3% |
|
69 |
+
| Portuguese | 63.3% |
|
70 |
+
| Russian | 59.2% |
|
71 |
+
| Chinese | 59.0% |
|
72 |
+
| Japanese | 59.0% |
|
73 |
+
|
74 |
+
## Usage
|
75 |
+
|
76 |
+
The model can be used with three different frameworks
|
77 |
+
|
78 |
+
- [`mistral_inference`](https://github.com/mistralai/mistral-inference): See [here](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407#mistral-inference)
|
79 |
+
- [`transformers`](https://github.com/huggingface/transformers): See [here](#transformers)
|
80 |
+
- [`NeMo`](https://github.com/NVIDIA/NeMo): See [nvidia/Mistral-NeMo-12B-Instruct](https://huggingface.co/nvidia/Mistral-NeMo-12B-Instruct)
|
81 |
+
|
82 |
+
### Mistral Inference
|
83 |
+
|
84 |
+
#### Install
|
85 |
+
|
86 |
+
It is recommended to use `mistralai/Mistral-Nemo-Instruct-2407` with [mistral-inference](https://github.com/mistralai/mistral-inference). For HF transformers code snippets, please keep scrolling.
|
87 |
+
|
88 |
+
```
|
89 |
+
pip install mistral_inference
|
90 |
+
```
|
91 |
+
|
92 |
+
#### Download
|
93 |
+
|
94 |
+
```py
|
95 |
+
from huggingface_hub import snapshot_download
|
96 |
+
from pathlib import Path
|
97 |
+
|
98 |
+
mistral_models_path = Path.home().joinpath('mistral_models', 'Nemo-Instruct')
|
99 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
100 |
+
|
101 |
+
snapshot_download(repo_id="mistralai/Mistral-Nemo-Instruct-2407", allow_patterns=["params.json", "consolidated.safetensors", "tekken.json"], local_dir=mistral_models_path)
|
102 |
+
```
|
103 |
+
|
104 |
+
#### Chat
|
105 |
+
|
106 |
+
After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
|
107 |
+
|
108 |
+
```
|
109 |
+
mistral-chat $HOME/mistral_models/Nemo-Instruct --instruct --max_tokens 256 --temperature 0.35
|
110 |
+
```
|
111 |
+
|
112 |
+
*E.g.* Try out something like:
|
113 |
+
```
|
114 |
+
How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar.
|
115 |
+
```
|
116 |
+
|
117 |
+
#### Instruct following
|
118 |
+
|
119 |
+
```py
|
120 |
+
from mistral_inference.transformer import Transformer
|
121 |
+
from mistral_inference.generate import generate
|
122 |
+
|
123 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
124 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
125 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
126 |
+
|
127 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")
|
128 |
+
model = Transformer.from_folder(mistral_models_path)
|
129 |
+
|
130 |
+
prompt = "How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar."
|
131 |
+
|
132 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])
|
133 |
+
|
134 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
135 |
+
|
136 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
137 |
+
result = tokenizer.decode(out_tokens[0])
|
138 |
+
|
139 |
+
print(result)
|
140 |
+
```
|
141 |
+
|
142 |
+
#### Function calling
|
143 |
+
|
144 |
+
```py
|
145 |
+
from mistral_common.protocol.instruct.tool_calls import Function, Tool
|
146 |
+
from mistral_inference.transformer import Transformer
|
147 |
+
from mistral_inference.generate import generate
|
148 |
+
|
149 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
150 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
151 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
152 |
+
|
153 |
+
|
154 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")
|
155 |
+
model = Transformer.from_folder(mistral_models_path)
|
156 |
+
|
157 |
+
completion_request = ChatCompletionRequest(
|
158 |
+
tools=[
|
159 |
+
Tool(
|
160 |
+
function=Function(
|
161 |
+
name="get_current_weather",
|
162 |
+
description="Get the current weather",
|
163 |
+
parameters={
|
164 |
+
"type": "object",
|
165 |
+
"properties": {
|
166 |
+
"location": {
|
167 |
+
"type": "string",
|
168 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
169 |
+
},
|
170 |
+
"format": {
|
171 |
+
"type": "string",
|
172 |
+
"enum": ["celsius", "fahrenheit"],
|
173 |
+
"description": "The temperature unit to use. Infer this from the users location.",
|
174 |
+
},
|
175 |
+
},
|
176 |
+
"required": ["location", "format"],
|
177 |
+
},
|
178 |
+
)
|
179 |
+
)
|
180 |
+
],
|
181 |
+
messages=[
|
182 |
+
UserMessage(content="What's the weather like today in Paris?"),
|
183 |
+
],
|
184 |
+
)
|
185 |
+
|
186 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
187 |
+
|
188 |
+
out_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
189 |
+
result = tokenizer.decode(out_tokens[0])
|
190 |
+
|
191 |
+
print(result)
|
192 |
+
```
|
193 |
+
|
194 |
+
### Transformers
|
195 |
+
|
196 |
+
> [!IMPORTANT]
|
197 |
+
> NOTE: Until a new release has been made, you need to install transformers from source:
|
198 |
+
> ```sh
|
199 |
+
> pip install git+https://github.com/huggingface/transformers.git
|
200 |
+
> ```
|
201 |
+
|
202 |
+
If you want to use Hugging Face `transformers` to generate text, you can do something like this.
|
203 |
+
|
204 |
+
```py
|
205 |
+
from transformers import pipeline
|
206 |
+
|
207 |
+
messages = [
|
208 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
209 |
+
{"role": "user", "content": "Who are you?"},
|
210 |
+
]
|
211 |
+
chatbot = pipeline("text-generation", model="mistralai/Mistral-Nemo-Instruct-2407",max_new_tokens=128)
|
212 |
+
chatbot(messages)
|
213 |
+
```
|
214 |
+
|
215 |
+
## Function calling with `transformers`
|
216 |
+
|
217 |
+
To use this example, you'll need `transformers` version 4.42.0 or higher. Please see the
|
218 |
+
[function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling)
|
219 |
+
in the `transformers` docs for more information.
|
220 |
+
|
221 |
+
```python
|
222 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
223 |
+
import torch
|
224 |
+
|
225 |
+
model_id = "mistralai/Mistral-Nemo-Instruct-2407"
|
226 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
227 |
+
|
228 |
+
def get_current_weather(location: str, format: str):
|
229 |
+
"""
|
230 |
+
Get the current weather
|
231 |
+
|
232 |
+
Args:
|
233 |
+
location: The city and state, e.g. San Francisco, CA
|
234 |
+
format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
|
235 |
+
"""
|
236 |
+
pass
|
237 |
+
|
238 |
+
conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
|
239 |
+
tools = [get_current_weather]
|
240 |
+
|
241 |
+
# format and tokenize the tool use prompt
|
242 |
+
inputs = tokenizer.apply_chat_template(
|
243 |
+
conversation,
|
244 |
+
tools=tools,
|
245 |
+
add_generation_prompt=True,
|
246 |
+
return_dict=True,
|
247 |
+
return_tensors="pt",
|
248 |
+
)
|
249 |
+
|
250 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
251 |
+
|
252 |
+
inputs.to(model.device)
|
253 |
+
outputs = model.generate(**inputs, max_new_tokens=1000)
|
254 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
255 |
+
```
|
256 |
+
|
257 |
+
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
|
258 |
+
results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
|
259 |
+
see the [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling),
|
260 |
+
and note that Mistral **does** use tool call IDs, so these must be included in your tool calls and tool results. They should be
|
261 |
+
exactly 9 alphanumeric characters.
|
262 |
+
|
263 |
+
> [!TIP]
|
264 |
+
> Unlike previous Mistral models, Mistral Nemo requires smaller temperatures. We recommend to use a temperature of 0.3.
|
265 |
+
|
266 |
+
## Limitations
|
267 |
+
|
268 |
+
The Mistral Nemo Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
|
269 |
+
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
|
270 |
+
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
|
271 |
+
|
272 |
+
## The Mistral AI Team
|
273 |
+
|
274 |
+
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
|