Triangle104 commited on
Commit
27b4e4e
1 Parent(s): b9a3e3a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +225 -0
README.md CHANGED
@@ -22,6 +22,231 @@ tags:
22
  This model was converted to GGUF format from [`mistralai/Mistral-Nemo-Instruct-2407`](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407) using llama.cpp via the ggml.ai's [GGUF-my-repo](https://huggingface.co/spaces/ggml-org/gguf-my-repo) space.
23
  Refer to the [original model card](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407) for more details on the model.
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ## Use with llama.cpp
26
  Install llama.cpp through brew (works on Mac and Linux)
27
 
 
22
  This model was converted to GGUF format from [`mistralai/Mistral-Nemo-Instruct-2407`](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407) using llama.cpp via the ggml.ai's [GGUF-my-repo](https://huggingface.co/spaces/ggml-org/gguf-my-repo) space.
23
  Refer to the [original model card](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407) for more details on the model.
24
 
25
+ ---
26
+ Model details:
27
+ -
28
+ 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.
29
+
30
+ For more details about this model please refer to our release blog post.
31
+ Key features
32
+
33
+ Released under the Apache 2 License
34
+ Pre-trained and instructed versions
35
+ Trained with a 128k context window
36
+ Trained on a large proportion of multilingual and code data
37
+ Drop-in replacement of Mistral 7B
38
+
39
+ Model Architecture
40
+ -
41
+ Mistral Nemo is a transformer model, with the following architecture choices:
42
+
43
+ Layers: 40
44
+ Dim: 5,120
45
+ Head dim: 128
46
+ Hidden dim: 14,336
47
+ Activation Function: SwiGLU
48
+ Number of heads: 32
49
+ Number of kv-heads: 8 (GQA)
50
+ Vocabulary size: 2**17 ~= 128k
51
+ Rotary embeddings (theta = 1M)
52
+
53
+ Metrics
54
+ Main Benchmarks
55
+ Benchmark Score
56
+ HellaSwag (0-shot) 83.5%
57
+ Winogrande (0-shot) 76.8%
58
+ OpenBookQA (0-shot) 60.6%
59
+ CommonSenseQA (0-shot) 70.4%
60
+ TruthfulQA (0-shot) 50.3%
61
+ MMLU (5-shot) 68.0%
62
+ TriviaQA (5-shot) 73.8%
63
+ NaturalQuestions (5-shot) 31.2%
64
+ Multilingual Benchmarks (MMLU)
65
+ Language Score
66
+ French 62.3%
67
+ German 62.7%
68
+ Spanish 64.6%
69
+ Italian 61.3%
70
+ Portuguese 63.3%
71
+ Russian 59.2%
72
+ Chinese 59.0%
73
+ Japanese 59.0%
74
+ Usage
75
+
76
+ The model can be used with three different frameworks
77
+
78
+ mistral_inference: See here
79
+ transformers: See here
80
+ NeMo: See 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. For HF transformers code snippets, please keep scrolling.
87
+
88
+ pip install mistral_inference
89
+
90
+ Download
91
+ -
92
+ from huggingface_hub import snapshot_download
93
+ from pathlib import Path
94
+
95
+ mistral_models_path = Path.home().joinpath('mistral_models', 'Nemo-Instruct')
96
+ mistral_models_path.mkdir(parents=True, exist_ok=True)
97
+
98
+ snapshot_download(repo_id="mistralai/Mistral-Nemo-Instruct-2407", allow_patterns=["params.json", "consolidated.safetensors", "tekken.json"], local_dir=mistral_models_path)
99
+
100
+ Chat
101
+ -
102
+ After installing mistral_inference, a mistral-chat CLI command should be available in your environment. You can chat with the model using
103
+
104
+ mistral-chat $HOME/mistral_models/Nemo-Instruct --instruct --max_tokens 256 --temperature 0.35
105
+
106
+ E.g. Try out something like:
107
+
108
+ How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar.
109
+
110
+ Instruct following
111
+ -
112
+ from mistral_inference.transformer import Transformer
113
+ from mistral_inference.generate import generate
114
+
115
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
116
+ from mistral_common.protocol.instruct.messages import UserMessage
117
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
118
+
119
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")
120
+ model = Transformer.from_folder(mistral_models_path)
121
+
122
+ prompt = "How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar."
123
+
124
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])
125
+
126
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
127
+
128
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
129
+ result = tokenizer.decode(out_tokens[0])
130
+
131
+ print(result)
132
+
133
+ Function calling
134
+ -
135
+ from mistral_common.protocol.instruct.tool_calls import Function, Tool
136
+ from mistral_inference.transformer import Transformer
137
+ from mistral_inference.generate import generate
138
+
139
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
140
+ from mistral_common.protocol.instruct.messages import UserMessage
141
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
142
+
143
+
144
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")
145
+ model = Transformer.from_folder(mistral_models_path)
146
+
147
+ completion_request = ChatCompletionRequest(
148
+ tools=[
149
+ Tool(
150
+ function=Function(
151
+ name="get_current_weather",
152
+ description="Get the current weather",
153
+ parameters={
154
+ "type": "object",
155
+ "properties": {
156
+ "location": {
157
+ "type": "string",
158
+ "description": "The city and state, e.g. San Francisco, CA",
159
+ },
160
+ "format": {
161
+ "type": "string",
162
+ "enum": ["celsius", "fahrenheit"],
163
+ "description": "The temperature unit to use. Infer this from the users location.",
164
+ },
165
+ },
166
+ "required": ["location", "format"],
167
+ },
168
+ )
169
+ )
170
+ ],
171
+ messages=[
172
+ UserMessage(content="What's the weather like today in Paris?"),
173
+ ],
174
+ )
175
+
176
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
177
+
178
+ out_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
179
+ result = tokenizer.decode(out_tokens[0])
180
+
181
+ print(result)
182
+
183
+ Transformers
184
+ -
185
+ NOTE: Until a new release has been made, you need to install transformers from source:
186
+
187
+ pip install git+https://github.com/huggingface/transformers.git
188
+
189
+ If you want to use Hugging Face transformers to generate text, you can do something like this.
190
+
191
+ from transformers import pipeline
192
+
193
+ messages = [
194
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
195
+ {"role": "user", "content": "Who are you?"},
196
+ ]
197
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-Nemo-Instruct-2407",max_new_tokens=128)
198
+ chatbot(messages)
199
+
200
+ Function calling with transformers
201
+ -
202
+ 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.
203
+
204
+ from transformers import AutoModelForCausalLM, AutoTokenizer
205
+ import torch
206
+
207
+ model_id = "mistralai/Mistral-Nemo-Instruct-2407"
208
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
209
+
210
+ def get_current_weather(location: str, format: str):
211
+ """
212
+ Get the current weather
213
+
214
+ Args:
215
+ location: The city and state, e.g. San Francisco, CA
216
+ format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
217
+ """
218
+ pass
219
+
220
+ conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
221
+ tools = [get_current_weather]
222
+
223
+ # format and tokenize the tool use prompt
224
+ inputs = tokenizer.apply_chat_template(
225
+ conversation,
226
+ tools=tools,
227
+ add_generation_prompt=True,
228
+ return_dict=True,
229
+ return_tensors="pt",
230
+ )
231
+
232
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
233
+
234
+ inputs.to(model.device)
235
+ outputs = model.generate(**inputs, max_new_tokens=1000)
236
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
237
+
238
+ 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.
239
+
240
+ Unlike previous Mistral models, Mistral Nemo requires smaller temperatures. We recommend to use a temperature of 0.3.
241
+
242
+ Limitations
243
+ -
244
+ 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.
245
+ The Mistral AI Team
246
+
247
+ 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
248
+
249
+ ---
250
  ## Use with llama.cpp
251
  Install llama.cpp through brew (works on Mac and Linux)
252