Triangle104 commited on
Commit
c6cc32e
1 Parent(s): 68bde77

Update README.md

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