mgoin commited on
Commit
8242979
·
verified ·
1 Parent(s): 41a1b56

Create README.md

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