LemiSt commited on
Commit
2bda18e
·
verified ·
1 Parent(s): fbf702b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +220 -145
README.md CHANGED
@@ -1,199 +1,274 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
 
 
 
 
 
 
 
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
 
 
 
 
 
 
 
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
55
 
56
- [More Information Needed]
 
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
 
 
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
69
 
70
- ## How to Get Started with the Model
 
 
 
 
 
 
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
 
 
 
75
 
76
- ## Training Details
 
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
81
 
82
- [More Information Needed]
 
 
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
87
 
88
- #### Preprocessing [optional]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- [More Information Needed]
91
 
 
 
92
 
93
- #### Training Hyperparameters
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
 
102
 
103
- ## Evaluation
 
 
 
 
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
 
 
108
 
109
- #### Testing Data
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
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
+ extra_gated_description: If you want to learn more about how we process your personal data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
15
  ---
16
 
17
+ # This is a (8bit, eetq) quantized version of [Mistral-Nemo-Instruct-2407](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407).
18
+ The original model card follows.
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
+ # render the tool use prompt as a string:
242
+ tool_use_prompt = tokenizer.apply_chat_template(
243
+ conversation,
244
+ tools=tools,
245
+ tokenize=False,
246
+ add_generation_prompt=True,
247
+ )
248
+
249
+ inputs = tokenizer(tool_use_prompt, return_tensors="pt")
250
+
251
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
252
+
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