AMead10 commited on
Commit
10f9672
1 Parent(s): dc52d01

Upload folder using huggingface_hub

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