shimmyshimmer
commited on
Commit
•
fe66fd0
1
Parent(s):
b1e302b
Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,292 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
# Model Card for Model ID
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
|
|
11 |
|
12 |
-
##
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
This
|
|
|
|
|
19 |
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
|
32 |
-
-
|
33 |
-
-
|
34 |
-
-
|
|
|
35 |
|
36 |
-
|
|
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
|
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
|
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
|
56 |
-
|
57 |
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
|
62 |
-
|
63 |
|
64 |
-
|
|
|
|
|
65 |
|
66 |
-
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
75 |
|
76 |
-
|
77 |
|
78 |
-
|
79 |
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
|
82 |
-
|
|
|
|
|
83 |
|
84 |
-
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
|
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
|
99 |
-
|
100 |
|
101 |
-
|
102 |
|
103 |
-
|
|
|
|
|
104 |
|
105 |
-
|
106 |
|
107 |
-
|
|
|
|
|
108 |
|
109 |
-
|
|
|
110 |
|
111 |
-
|
|
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
|
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
|
|
|
|
122 |
|
123 |
-
|
|
|
|
|
124 |
|
125 |
-
[More Information Needed]
|
126 |
|
127 |
-
|
|
|
128 |
|
129 |
-
[
|
130 |
|
131 |
-
|
132 |
|
|
|
|
|
133 |
|
|
|
|
|
134 |
|
135 |
-
|
136 |
|
137 |
-
|
|
|
|
|
|
|
138 |
|
139 |
-
|
|
|
|
|
140 |
|
141 |
-
## Environmental Impact
|
142 |
|
143 |
-
|
|
|
144 |
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
###
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
base_model: mistralai/Mistral-Small-Instruct-2409
|
3 |
+
license: other
|
4 |
+
license_name: mrl
|
5 |
+
license_link: https://mistral.ai/licenses/MRL-0.1.md
|
6 |
+
tags:
|
7 |
+
- unsloth
|
8 |
+
- mistral
|
9 |
---
|
10 |
|
|
|
11 |
|
12 |
+
# Finetune Llama 3.1, Gemma 2, Mistral 2-5x faster with 70% less memory via Unsloth!
|
13 |
|
14 |
+
We have a free Google Colab Tesla T4 notebook for Llama 3.1 (8B) here: https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing
|
15 |
|
16 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/Discord%20button.png" width="200"/>](https://discord.gg/unsloth)
|
17 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
18 |
|
19 |
+
## ✨ Finetune for Free
|
20 |
|
21 |
+
All notebooks are **beginner friendly**! Add your dataset, click "Run All", and you'll get a 2x faster finetuned model which can be exported to GGUF, vLLM or uploaded to Hugging Face.
|
22 |
|
23 |
+
| Unsloth supports | Free Notebooks | Performance | Memory use |
|
24 |
+
|-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
|
25 |
+
| **Llama-3.1 8b** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing) | 2.4x faster | 58% less |
|
26 |
+
| **Phi-3.5 (mini)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1lN6hPQveB_mHSnTOYifygFcrO8C1bxq4?usp=sharing) | 2x faster | 50% less |
|
27 |
+
| **Gemma-2 9b** | [▶️ Start on Colab](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing) | 2.4x faster | 58% less |
|
28 |
+
| **Mistral 7b** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Dyauq4kTZoLewQ1cApceUQVNcnnNTzg_?usp=sharing) | 2.2x faster | 62% less |
|
29 |
+
| **TinyLlama** | [▶️ Start on Colab](https://colab.research.google.com/drive/1AZghoNBQaMDgWJpi4RbffGM1h6raLUj9?usp=sharing) | 3.9x faster | 74% less |
|
30 |
+
| **DPO - Zephyr** | [▶️ Start on Colab](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) | 1.9x faster | 19% less |
|
31 |
|
32 |
+
- This [conversational notebook](https://colab.research.google.com/drive/1Aau3lgPzeZKQ-98h69CCu1UJcvIBLmy2?usp=sharing) is useful for ShareGPT ChatML / Vicuna templates.
|
33 |
+
- This [text completion notebook](https://colab.research.google.com/drive/1ef-tab5bhkvWmBOObepl1WgJvfvSzn5Q?usp=sharing) is for raw text. This [DPO notebook](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) replicates Zephyr.
|
34 |
+
- \* Kaggle has 2x T4s, but we use 1. Due to overhead, 1x T4 is 5x faster.
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
# Model Card for Mistral-Small-Instruct-2409
|
38 |
|
39 |
+
Mistral-Small-Instruct-2409 is an instruct fine-tuned version with the following characteristics:
|
40 |
|
41 |
+
- 22B parameters
|
42 |
+
- Vocabulary to 32768
|
43 |
+
- Supports function calling
|
44 |
+
- 128k sequence length
|
45 |
|
46 |
+
|
47 |
+
## Usage Examples
|
48 |
|
49 |
+
### vLLM (recommended)
|
50 |
|
51 |
+
We recommend using this model with the [vLLM library](https://github.com/vllm-project/vllm)
|
52 |
+
to implement production-ready inference pipelines.
|
53 |
|
54 |
+
**_Installation_**
|
55 |
|
56 |
+
Make sure you install `vLLM >= v0.6.1.post1`:
|
57 |
|
58 |
+
```
|
59 |
+
pip install --upgrade vllm
|
60 |
+
```
|
61 |
|
62 |
+
Also make sure you have `mistral_common >= 1.4.1` installed:
|
63 |
|
64 |
+
```
|
65 |
+
pip install --upgrade mistral_common
|
66 |
+
```
|
67 |
|
68 |
+
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).
|
69 |
|
|
|
70 |
|
71 |
+
**_Offline_**
|
72 |
|
73 |
+
```py
|
74 |
+
from vllm import LLM
|
75 |
+
from vllm.sampling_params import SamplingParams
|
76 |
|
77 |
+
model_name = "mistralai/Mistral-Small-Instruct-2409"
|
78 |
|
79 |
+
sampling_params = SamplingParams(max_tokens=8192)
|
80 |
|
81 |
+
# note that running Mistral-Small on a single GPU requires at least 44 GB of GPU RAM
|
82 |
+
# If you want to divide the GPU requirement over multiple devices, please add *e.g.* `tensor_parallel=2`
|
83 |
+
llm = LLM(model=model_name, tokenizer_mode="mistral", config_format="mistral", load_format="mistral")
|
84 |
|
85 |
+
prompt = "How often does the letter r occur in Mistral?"
|
86 |
|
87 |
+
messages = [
|
88 |
+
{
|
89 |
+
"role": "user",
|
90 |
+
"content": prompt
|
91 |
+
},
|
92 |
+
]
|
93 |
|
94 |
+
outputs = llm.chat(messages, sampling_params=sampling_params)
|
95 |
|
96 |
+
print(outputs[0].outputs[0].text)
|
97 |
+
```
|
98 |
|
99 |
+
**_Server_**
|
100 |
|
101 |
+
You can also use Mistral Small in a server/client setting.
|
102 |
|
103 |
+
1. Spin up a server:
|
104 |
|
|
|
105 |
|
106 |
+
```
|
107 |
+
vllm serve mistralai/Mistral-Small-Instruct-2409 --tokenizer_mode mistral --config_format mistral --load_format mistral
|
108 |
+
```
|
109 |
|
110 |
+
**Note:** Running Mistral-Small on a single GPU requires at least 44 GB of GPU RAM.
|
111 |
|
112 |
+
If you want to divide the GPU requirement over multiple devices, please add *e.g.* `--tensor_parallel=2`
|
113 |
|
114 |
+
2. And ping the client:
|
115 |
|
116 |
+
```
|
117 |
+
curl --location 'http://<your-node-url>:8000/v1/chat/completions' \
|
118 |
+
--header 'Content-Type: application/json' \
|
119 |
+
--header 'Authorization: Bearer token' \
|
120 |
+
--data '{
|
121 |
+
"model": "mistralai/Mistral-Small-Instruct-2409",
|
122 |
+
"messages": [
|
123 |
+
{
|
124 |
+
"role": "user",
|
125 |
+
"content": "How often does the letter r occur in Mistral?"
|
126 |
+
}
|
127 |
+
]
|
128 |
+
}'
|
129 |
|
130 |
+
```
|
131 |
|
132 |
+
### Mistral-inference
|
133 |
|
134 |
+
We recommend using [mistral-inference](https://github.com/mistralai/mistral-inference) to quickly try out / "vibe-check" the model.
|
135 |
|
|
|
136 |
|
137 |
+
**_Install_**
|
138 |
|
139 |
+
Make sure to have `mistral_inference >= 1.4.1` installed.
|
140 |
|
141 |
+
```
|
142 |
+
pip install mistral_inference --upgrade
|
143 |
+
```
|
144 |
|
145 |
+
**_Download_**
|
146 |
|
147 |
+
```py
|
148 |
+
from huggingface_hub import snapshot_download
|
149 |
+
from pathlib import Path
|
150 |
|
151 |
+
mistral_models_path = Path.home().joinpath('mistral_models', '22B-Instruct-Small')
|
152 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
153 |
|
154 |
+
snapshot_download(repo_id="mistralai/Mistral-Small-Instruct-2409", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
|
155 |
+
```
|
156 |
|
157 |
+
### Chat
|
158 |
|
159 |
+
After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
|
160 |
|
161 |
+
```
|
162 |
+
mistral-chat $HOME/mistral_models/22B-Instruct-Small --instruct --max_tokens 256
|
163 |
+
```
|
164 |
|
165 |
+
### Instruct following
|
166 |
|
167 |
+
```py
|
168 |
+
from mistral_inference.transformer import Transformer
|
169 |
+
from mistral_inference.generate import generate
|
170 |
|
171 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
172 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
173 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
174 |
|
|
|
175 |
|
176 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
177 |
+
model = Transformer.from_folder(mistral_models_path)
|
178 |
|
179 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="How often does the letter r occur in Mistral?")])
|
180 |
|
181 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
182 |
|
183 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
184 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
185 |
|
186 |
+
print(result)
|
187 |
+
```
|
188 |
|
189 |
+
### Function calling
|
190 |
|
191 |
+
```py
|
192 |
+
from mistral_common.protocol.instruct.tool_calls import Function, Tool
|
193 |
+
from mistral_inference.transformer import Transformer
|
194 |
+
from mistral_inference.generate import generate
|
195 |
|
196 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
197 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
198 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
199 |
|
|
|
200 |
|
201 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
202 |
+
model = Transformer.from_folder(mistral_models_path)
|
203 |
|
204 |
+
completion_request = ChatCompletionRequest(
|
205 |
+
tools=[
|
206 |
+
Tool(
|
207 |
+
function=Function(
|
208 |
+
name="get_current_weather",
|
209 |
+
description="Get the current weather",
|
210 |
+
parameters={
|
211 |
+
"type": "object",
|
212 |
+
"properties": {
|
213 |
+
"location": {
|
214 |
+
"type": "string",
|
215 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
216 |
+
},
|
217 |
+
"format": {
|
218 |
+
"type": "string",
|
219 |
+
"enum": ["celsius", "fahrenheit"],
|
220 |
+
"description": "The temperature unit to use. Infer this from the users location.",
|
221 |
+
},
|
222 |
+
},
|
223 |
+
"required": ["location", "format"],
|
224 |
+
},
|
225 |
+
)
|
226 |
+
)
|
227 |
+
],
|
228 |
+
messages=[
|
229 |
+
UserMessage(content="What's the weather like today in Paris?"),
|
230 |
+
],
|
231 |
+
)
|
232 |
|
233 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
|
|
|
|
|
|
|
|
234 |
|
235 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
236 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
237 |
+
|
238 |
+
print(result)
|
239 |
+
```
|
240 |
+
|
241 |
+
### Usage in Hugging Face Transformers
|
242 |
+
|
243 |
+
You can also use Hugging Face `transformers` library to run inference using various chat templates, or fine-tune the model.
|
244 |
+
Example for inference:
|
245 |
+
|
246 |
+
```python
|
247 |
+
from transformers import LlamaTokenizerFast, MistralForCausalLM
|
248 |
+
import torch
|
249 |
+
|
250 |
+
device = "cuda"
|
251 |
+
tokenizer = LlamaTokenizerFast.from_pretrained('mistralai/Mistral-Small-Instruct-2409')
|
252 |
+
tokenizer.pad_token = tokenizer.eos_token
|
253 |
+
|
254 |
+
model = MistralForCausalLM.from_pretrained('mistralai/Mistral-Small-Instruct-2409', torch_dtype=torch.bfloat16)
|
255 |
+
model = model.to(device)
|
256 |
+
|
257 |
+
prompt = "How often does the letter r occur in Mistral?"
|
258 |
+
|
259 |
+
messages = [
|
260 |
+
{"role": "user", "content": prompt},
|
261 |
+
]
|
262 |
+
|
263 |
+
model_input = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(device)
|
264 |
+
gen = model.generate(model_input, max_new_tokens=150)
|
265 |
+
dec = tokenizer.batch_decode(gen)
|
266 |
+
print(dec)
|
267 |
+
```
|
268 |
+
|
269 |
+
And you should obtain
|
270 |
+
```text
|
271 |
+
<s>
|
272 |
+
[INST]
|
273 |
+
How often does the letter r occur in Mistral?
|
274 |
+
[/INST]
|
275 |
+
To determine how often the letter "r" occurs in the word "Mistral,"
|
276 |
+
we can simply count the instances of "r" in the word.
|
277 |
+
The word "Mistral" is broken down as follows:
|
278 |
+
- M
|
279 |
+
- i
|
280 |
+
- s
|
281 |
+
- t
|
282 |
+
- r
|
283 |
+
- a
|
284 |
+
- l
|
285 |
+
Counting the "r"s, we find that there is only one "r" in "Mistral."
|
286 |
+
Therefore, the letter "r" occurs once in the word "Mistral."
|
287 |
+
</s>
|
288 |
+
```
|
289 |
+
|
290 |
+
## The Mistral AI Team
|
291 |
+
|
292 |
+
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
|