professorf commited on
Commit
0d7b306
1 Parent(s): 8e6d078

Create README.md

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