shimmyshimmer commited on
Commit
fe66fd0
1 Parent(s): b1e302b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +219 -126
README.md CHANGED
@@ -1,199 +1,292 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
 
 
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
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
 
35
 
36
- ## Uses
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
 
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
 
 
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
63
 
64
- ### Recommendations
 
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
 
69
 
70
- ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
 
73
 
74
- [More Information Needed]
75
 
76
- ## Training Details
77
 
78
- ### Training Data
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
- [More Information Needed]
 
 
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
91
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
 
 
108
 
109
- #### Testing Data
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
112
 
113
- [More Information Needed]
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
 
 
124
 
125
- [More Information Needed]
126
 
127
- ### Results
 
128
 
129
- [More Information Needed]
130
 
131
- #### Summary
132
 
 
 
133
 
 
 
134
 
135
- ## Model Examination [optional]
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
 
 
 
138
 
139
- [More Information Needed]
 
 
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
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
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
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