munish0838 commited on
Commit
f30a86a
1 Parent(s): 46a92b1

Upload README.md with huggingface_hub

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