Walmart-the-bag commited on
Commit
3416f2f
1 Parent(s): 323f45e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +275 -0
README.md ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - fr
5
+ - de
6
+ - es
7
+ - it
8
+ - pt
9
+ - zh
10
+ - ja
11
+ - ru
12
+ - ko
13
+ license: other
14
+ license_name: mrl
15
+ license_link: https://mistral.ai/licenses/MRL-0.1.md
16
+ extra_gated_description: If you want to learn more about how we process your personal
17
+ data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
18
+ ---
19
+ # This is quantized using [llm-compressor](https://github.com/vllm-project/llm-compressor) at fp8 dynamic, [read more here](https://github.com/vllm-project/llm-compressor/tree/main/examples/quantization_w8a8_fp8)
20
+ # Model Card for Mistral-Small-Instruct-2409
21
+
22
+ Mistral-Small-Instruct-2409 is an instruct fine-tuned version with the following characteristics:
23
+
24
+ - 22B parameters
25
+ - Vocabulary to 32768
26
+ - Supports function calling
27
+ - 32k sequence length
28
+
29
+
30
+ ## Usage Examples
31
+
32
+ ### vLLM (recommended)
33
+
34
+ We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
35
+ to implement production-ready inference pipelines.
36
+
37
+ **_Installation_**
38
+
39
+ Make sure you install `vLLM >= v0.6.1.post1`:
40
+
41
+ ```
42
+ pip install --upgrade vllm
43
+ ```
44
+
45
+ Also make sure you have `mistral_common >= 1.4.1` installed:
46
+
47
+ ```
48
+ pip install --upgrade mistral_common
49
+ ```
50
+
51
+ You can also make use of a ready-to-go [docker image](https://hub.docker.com/layers/vllm/vllm-openai/latest/images/sha256-de9032a92ffea7b5c007dad80b38fd44aac11eddc31c435f8e52f3b7404bbf39?context=explore).
52
+
53
+
54
+ **_Offline_**
55
+
56
+ ```py
57
+ from vllm import LLM
58
+ from vllm.sampling_params import SamplingParams
59
+
60
+ model_name = "mistralai/Mistral-Small-Instruct-2409"
61
+
62
+ sampling_params = SamplingParams(max_tokens=8192)
63
+
64
+ # note that running Mistral-Small on a single GPU requires at least 44 GB of GPU RAM
65
+ # If you want to divide the GPU requirement over multiple devices, please add *e.g.* `tensor_parallel=2`
66
+ llm = LLM(model=model_name, tokenizer_mode="mistral", config_format="mistral", load_format="mistral")
67
+
68
+ prompt = "How often does the letter r occur in Mistral?"
69
+
70
+ messages = [
71
+ {
72
+ "role": "user",
73
+ "content": prompt
74
+ },
75
+ ]
76
+
77
+ outputs = llm.chat(messages, sampling_params=sampling_params)
78
+
79
+ print(outputs[0].outputs[0].text)
80
+ ```
81
+
82
+ **_Server_**
83
+
84
+ You can also use Mistral Small in a server/client setting.
85
+
86
+ 1. Spin up a server:
87
+
88
+
89
+ ```
90
+ vllm serve mistralai/Mistral-Small-Instruct-2409 --tokenizer_mode mistral --config_format mistral --load_format mistral
91
+ ```
92
+
93
+ **Note:** Running Mistral-Small on a single GPU requires at least 44 GB of GPU RAM.
94
+
95
+ If you want to divide the GPU requirement over multiple devices, please add *e.g.* `--tensor_parallel=2`
96
+
97
+ 2. And ping the client:
98
+
99
+ ```
100
+ curl --location 'http://<your-node-url>:8000/v1/chat/completions' \
101
+ --header 'Content-Type: application/json' \
102
+ --header 'Authorization: Bearer token' \
103
+ --data '{
104
+ "model": "mistralai/Mistral-Small-Instruct-2409",
105
+ "messages": [
106
+ {
107
+ "role": "user",
108
+ "content": "How often does the letter r occur in Mistral?"
109
+ }
110
+ ]
111
+ }'
112
+
113
+ ```
114
+
115
+ ### Mistral-inference
116
+
117
+ We recommend using [mistral-inference](https://github.com/mistralai/mistral-inference) to quickly try out / "vibe-check" the model.
118
+
119
+
120
+ **_Install_**
121
+
122
+ Make sure to have `mistral_inference >= 1.4.1` installed.
123
+
124
+ ```
125
+ pip install mistral_inference --upgrade
126
+ ```
127
+
128
+ **_Download_**
129
+
130
+ ```py
131
+ from huggingface_hub import snapshot_download
132
+ from pathlib import Path
133
+
134
+ mistral_models_path = Path.home().joinpath('mistral_models', '22B-Instruct-Small')
135
+ mistral_models_path.mkdir(parents=True, exist_ok=True)
136
+
137
+ snapshot_download(repo_id="mistralai/Mistral-Small-Instruct-2409", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
138
+ ```
139
+
140
+ ### Chat
141
+
142
+ After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
143
+
144
+ ```
145
+ mistral-chat $HOME/mistral_models/22B-Instruct-Small --instruct --max_tokens 256
146
+ ```
147
+
148
+ ### Instruct following
149
+
150
+ ```py
151
+ from mistral_inference.transformer import Transformer
152
+ from mistral_inference.generate import generate
153
+
154
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
155
+ from mistral_common.protocol.instruct.messages import UserMessage
156
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
157
+
158
+
159
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
160
+ model = Transformer.from_folder(mistral_models_path)
161
+
162
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content="How often does the letter r occur in Mistral?")])
163
+
164
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
165
+
166
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
167
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
168
+
169
+ print(result)
170
+ ```
171
+
172
+ ### Function calling
173
+
174
+ ```py
175
+ from mistral_common.protocol.instruct.tool_calls import Function, Tool
176
+ from mistral_inference.transformer import Transformer
177
+ from mistral_inference.generate import generate
178
+
179
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
180
+ from mistral_common.protocol.instruct.messages import UserMessage
181
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
182
+
183
+
184
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
185
+ model = Transformer.from_folder(mistral_models_path)
186
+
187
+ completion_request = ChatCompletionRequest(
188
+ tools=[
189
+ Tool(
190
+ function=Function(
191
+ name="get_current_weather",
192
+ description="Get the current weather",
193
+ parameters={
194
+ "type": "object",
195
+ "properties": {
196
+ "location": {
197
+ "type": "string",
198
+ "description": "The city and state, e.g. San Francisco, CA",
199
+ },
200
+ "format": {
201
+ "type": "string",
202
+ "enum": ["celsius", "fahrenheit"],
203
+ "description": "The temperature unit to use. Infer this from the users location.",
204
+ },
205
+ },
206
+ "required": ["location", "format"],
207
+ },
208
+ )
209
+ )
210
+ ],
211
+ messages=[
212
+ UserMessage(content="What's the weather like today in Paris?"),
213
+ ],
214
+ )
215
+
216
+ tokens = tokenizer.encode_chat_completion(completion_request).tokens
217
+
218
+ out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
219
+ result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
220
+
221
+ print(result)
222
+ ```
223
+
224
+ ### Usage in Hugging Face Transformers
225
+
226
+ You can also use Hugging Face `transformers` library to run inference using various chat templates, or fine-tune the model.
227
+ Example for inference:
228
+
229
+ ```python
230
+ from transformers import LlamaTokenizerFast, MistralForCausalLM
231
+ import torch
232
+
233
+ device = "cuda"
234
+ tokenizer = LlamaTokenizerFast.from_pretrained('mistralai/Mistral-Small-Instruct-2409')
235
+ tokenizer.pad_token = tokenizer.eos_token
236
+
237
+ model = MistralForCausalLM.from_pretrained('mistralai/Mistral-Small-Instruct-2409', torch_dtype=torch.bfloat16)
238
+ model = model.to(device)
239
+
240
+ prompt = "How often does the letter r occur in Mistral?"
241
+
242
+ messages = [
243
+ {"role": "user", "content": prompt},
244
+ ]
245
+
246
+ model_input = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(device)
247
+ gen = model.generate(model_input, max_new_tokens=150)
248
+ dec = tokenizer.batch_decode(gen)
249
+ print(dec)
250
+ ```
251
+
252
+ And you should obtain
253
+ ```text
254
+ <s>
255
+ [INST]
256
+ How often does the letter r occur in Mistral?
257
+ [/INST]
258
+ To determine how often the letter "r" occurs in the word "Mistral,"
259
+ we can simply count the instances of "r" in the word.
260
+ The word "Mistral" is broken down as follows:
261
+ - M
262
+ - i
263
+ - s
264
+ - t
265
+ - r
266
+ - a
267
+ - l
268
+ Counting the "r"s, we find that there is only one "r" in "Mistral."
269
+ Therefore, the letter "r" occurs once in the word "Mistral."
270
+ </s>
271
+ ```
272
+
273
+ ## The Mistral AI Team
274
+
275
+ 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, Diogo Costa, 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