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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
|
10 |
|
11 |
-
- PEFT 0.6.3.dev0
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
library_name: peft
|
4 |
+
tags:
|
5 |
+
- mistral
|
6 |
+
datasets:
|
7 |
+
- jondurbin/airoboros-2.2.1
|
8 |
+
- Open-Orca/SlimOrca
|
9 |
+
- garage-bAInd/Open-Platypus
|
10 |
+
inference: false
|
11 |
+
pipeline_tag: text-generation
|
12 |
base_model: mistralai/Mistral-7B-v0.1
|
|
|
13 |
---
|
14 |
|
15 |
+
<div align="center">
|
16 |
+
|
17 |
+
<img src="./logo.png" width="150px">
|
18 |
+
|
19 |
+
</div>
|
20 |
+
|
21 |
+
# Mistral-7B-Instruct-v0.2
|
22 |
+
|
23 |
+
A pretrained generative language model with 7 billion parameters geared towards instruction-following capabilities.
|
24 |
+
|
25 |
+
## Model Details
|
26 |
+
|
27 |
+
This model was built via parameter-efficient finetuning of the [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) base model on the first 20k rows in each of the [jondurbin/airoboros-2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-2.2.1), [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca), and [garage-bAInd/Open-Platypus](https://huggingface.co/datasets/garage-bAInd/Open-Platypus) datasets.
|
28 |
+
|
29 |
+
- **Developed by:** Daniel Furman
|
30 |
+
- **Model type:** Decoder-only
|
31 |
+
- **Language(s) (NLP):** English
|
32 |
+
- **License:** Apache 2.0
|
33 |
+
- **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
|
34 |
+
|
35 |
+
## Model Sources
|
36 |
+
|
37 |
+
- **Repository:** [here](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/mistral/sft_Mistral_7B_Instruct_v0_1_peft.ipynb)
|
38 |
+
|
39 |
+
## Evaluation Results
|
40 |
+
|
41 |
+
| Metric | Value |
|
42 |
+
|-----------------------|-------|
|
43 |
+
| MMLU (5-shot) | Coming |
|
44 |
+
| ARC (25-shot) | Coming |
|
45 |
+
| HellaSwag (10-shot) | Coming |
|
46 |
+
| TruthfulQA (0-shot) | Coming |
|
47 |
+
| Avg. | Coming |
|
48 |
+
|
49 |
+
We use Eleuther.AI's [Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness) to run the benchmark tests above, the same version as Hugging Face's [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard).
|
50 |
+
|
51 |
+
## Basic Usage
|
52 |
+
|
53 |
+
<details>
|
54 |
+
|
55 |
+
<summary>Setup</summary>
|
56 |
+
|
57 |
+
```python
|
58 |
+
!pip install -q -U transformers peft torch accelerate einops sentencepiece
|
59 |
+
```
|
60 |
+
|
61 |
+
```python
|
62 |
+
import torch
|
63 |
+
from peft import PeftModel, PeftConfig
|
64 |
+
from transformers import (
|
65 |
+
AutoModelForCausalLM,
|
66 |
+
AutoTokenizer,
|
67 |
+
)
|
68 |
+
```
|
69 |
+
|
70 |
+
```python
|
71 |
+
peft_model_id = "dfurman/Mistral-7B-Instruct-v0.1"
|
72 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
73 |
+
|
74 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
75 |
+
peft_model_id,
|
76 |
+
use_fast=True,
|
77 |
+
trust_remote_code=True,
|
78 |
+
)
|
79 |
+
|
80 |
+
model = AutoModelForCausalLM.from_pretrained(
|
81 |
+
config.base_model_name_or_path,
|
82 |
+
torch_dtype=torch.float16,
|
83 |
+
device_map="auto",
|
84 |
+
trust_remote_code=True,
|
85 |
+
)
|
86 |
+
|
87 |
+
model = PeftModel.from_pretrained(
|
88 |
+
model,
|
89 |
+
peft_model_id
|
90 |
+
)
|
91 |
+
```
|
92 |
+
|
93 |
+
</details>
|
94 |
+
|
95 |
+
|
96 |
+
```python
|
97 |
+
messages = [
|
98 |
+
{"role": "user", "content": "Tell me a recipe for a mai tai."},
|
99 |
+
]
|
100 |
+
|
101 |
+
print("\n\n*** Prompt:")
|
102 |
+
input_ids = tokenizer.apply_chat_template(
|
103 |
+
messages,
|
104 |
+
tokenize=True,
|
105 |
+
return_tensors="pt",
|
106 |
+
)
|
107 |
+
print(tokenizer.decode(input_ids[0]))
|
108 |
+
```
|
109 |
+
|
110 |
+
<details>
|
111 |
+
|
112 |
+
<summary>Prompt</summary>
|
113 |
+
|
114 |
+
```python
|
115 |
+
"<s> [INST] Tell me a recipe for a mai tai. [/INST]"
|
116 |
+
```
|
117 |
+
|
118 |
+
</details>
|
119 |
+
|
120 |
+
|
121 |
+
```python
|
122 |
+
print("\n\n*** Generate:")
|
123 |
+
with torch.autocast("cuda", dtype=torch.bfloat16):
|
124 |
+
output = model.generate(
|
125 |
+
input_ids=input_ids.cuda(),
|
126 |
+
max_new_tokens=1024,
|
127 |
+
do_sample=True,
|
128 |
+
temperature=0.7,
|
129 |
+
return_dict_in_generate=True,
|
130 |
+
eos_token_id=tokenizer.eos_token_id,
|
131 |
+
pad_token_id=tokenizer.pad_token_id,
|
132 |
+
repetition_penalty=1.2,
|
133 |
+
no_repeat_ngram_size=5,
|
134 |
+
)
|
135 |
+
|
136 |
+
response = tokenizer.decode(
|
137 |
+
output["sequences"][0][len(input_ids[0]):],
|
138 |
+
skip_special_tokens=True
|
139 |
+
)
|
140 |
+
print(response)
|
141 |
+
|
142 |
+
```
|
143 |
+
|
144 |
+
<details>
|
145 |
+
|
146 |
+
<summary>Generation</summary>
|
147 |
+
|
148 |
+
```python
|
149 |
+
"""1. Combine the following ingredients in a cocktail shaker:
|
150 |
+
2 oz light rum (or white rum)
|
151 |
+
1 oz dark rum
|
152 |
+
0.5 oz orange curacao or triple sec
|
153 |
+
0.75 oz lime juice, freshly squeezed
|
154 |
+
0.5 tbsp simple syrup (optional; if you like your drinks sweet)
|
155 |
+
Few drops of bitters (Angostura is traditional but any will do)
|
156 |
+
Ice cubes to fill the shaker
|
157 |
+
|
158 |
+
2. Shake vigorously until well-chilled and combined.
|
159 |
+
3. Strain into an ice-filled glass.
|
160 |
+
4. Garnish with a slice of lime or an orange wedge, if desired."""
|
161 |
+
```
|
162 |
+
|
163 |
+
</details>
|
164 |
+
|
165 |
+
|
166 |
+
## Speeds, Sizes, Times
|
167 |
+
|
168 |
+
| runtime / 50 tokens (sec) | GPU | dtype | VRAM (GB) |
|
169 |
+
|:-----------------------------:|:---------------------:|:-------------:|:-----------------------:|
|
170 |
+
| 3.21 | 1x A100 (40 GB SXM) | torch.bfloat16 | 16 |
|
171 |
+
|
172 |
+
## Training
|
173 |
+
|
174 |
+
It took ~2 hours to train 2 epochs on 1x A100 (40 GB SXM).
|
175 |
+
|
176 |
+
### Prompt Format
|
177 |
+
|
178 |
+
This model was finetuned with the following format:
|
179 |
+
|
180 |
+
```python
|
181 |
+
tokenizer.chat_template = "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST] ' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token + ' ' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
|
182 |
+
```
|
183 |
+
|
184 |
+
This format is available as a [chat template](https://huggingface.co/docs/transformers/main/chat_templating) via the `apply_chat_template()` method. Here's an illustrative example:
|
185 |
+
|
186 |
+
```python
|
187 |
+
messages = [
|
188 |
+
{"role": "user", "content": "Tell me a recipe for a mai tai."},
|
189 |
+
{"role": "assistant", "content": "1 oz light rum\n½ oz dark rum\n¼ oz orange curaçao\n2 oz pineapple juice\n¾ oz lime juice\nDash of orgeat syrup (optional)\nSplash of grenadine (for garnish, optional)\nLime wheel and cherry garnishes (optional)\n\nShake all ingredients except the splash of grenadine in a cocktail shaker over ice. Strain into an old-fashioned glass filled with fresh ice cubes. Gently pour the splash of grenadine down the side of the glass so that it sinks to the bottom. Add garnishes as desired."},
|
190 |
+
{"role": "user", "content": "How can I make it more upscale and luxurious?"},
|
191 |
+
]
|
192 |
+
|
193 |
+
print("\n\n*** Prompt:")
|
194 |
+
input_ids = tokenizer.apply_chat_template(
|
195 |
+
messages,
|
196 |
+
tokenize=True,
|
197 |
+
return_tensors="pt",
|
198 |
+
)
|
199 |
+
print(tokenizer.decode(input_ids[0]))
|
200 |
+
```
|
201 |
+
|
202 |
+
<details>
|
203 |
+
|
204 |
+
<summary>Output</summary>
|
205 |
+
|
206 |
+
```python
|
207 |
+
"""<s> [INST] Tell me a recipe for a mai tai. [/INST] 1 oz light rum\n½ oz dark rum\n (...) Add garnishes as desired.</s> [INST] How can I make it more upscale and luxurious? [/INST]"""
|
208 |
+
```
|
209 |
+
</details>
|
210 |
+
|
211 |
+
### Training Hyperparameters
|
212 |
+
|
213 |
+
|
214 |
+
We use the [SFTTrainer](https://huggingface.co/docs/trl/main/en/sft_trainer) from `trl` to fine-tune LLMs on instruction-following datasets.
|
215 |
+
|
216 |
+
See [here](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/mistral/sft_Mistral_7B_Instruct_v0_1_peft.ipynb) for the finetuning code, which contains an exhaustive view of the hyperparameters employed.
|
217 |
+
|
218 |
+
The following `TrainingArguments` config was used:
|
219 |
+
|
220 |
+
- output_dir = "./results"
|
221 |
+
- num_train_epochs = 3
|
222 |
+
- auto_find_batch_size = True
|
223 |
+
- gradient_accumulation_steps = 1
|
224 |
+
- optim = "paged_adamw_32bit"
|
225 |
+
- save_strategy = "epoch"
|
226 |
+
- learning_rate = 3e-4
|
227 |
+
- lr_scheduler_type = "cosine"
|
228 |
+
- warmup_ratio = 0.03
|
229 |
+
- logging_strategy = "steps"
|
230 |
+
- logging_steps = 25
|
231 |
+
- evaluation_strategy = "epoch"
|
232 |
+
- prediction_loss_only = True
|
233 |
+
- bf16 = True
|
234 |
+
|
235 |
+
The following `bitsandbytes` quantization config was used:
|
236 |
+
|
237 |
+
- quant_method: bitsandbytes
|
238 |
+
- load_in_8bit: False
|
239 |
+
- load_in_4bit: True
|
240 |
+
- llm_int8_threshold: 6.0
|
241 |
+
- llm_int8_skip_modules: None
|
242 |
+
- llm_int8_enable_fp32_cpu_offload: False
|
243 |
+
- llm_int8_has_fp16_weight: False
|
244 |
+
- bnb_4bit_quant_type: nf4
|
245 |
+
- bnb_4bit_use_double_quant: False
|
246 |
+
- bnb_4bit_compute_dtype: bfloat16
|
247 |
+
|
248 |
+
|
249 |
+
## Model Card Contact
|
250 |
+
|
251 |
+
dryanfurman at gmail
|
252 |
+
|
253 |
+
## Mistral Research Citation
|
254 |
+
|
255 |
+
```
|
256 |
+
@misc{jiang2023mistral,
|
257 |
+
title={Mistral 7B},
|
258 |
+
author={Albert Q. Jiang and Alexandre Sablayrolles and Arthur Mensch and Chris Bamford and Devendra Singh Chaplot and Diego de las Casas and Florian Bressand and Gianna Lengyel and Guillaume Lample and Lucile Saulnier and Lélio Renard Lavaud and Marie-Anne Lachaux and Pierre Stock and Teven Le Scao and Thibaut Lavril and Thomas Wang and Timothée Lacroix and William El Sayed},
|
259 |
+
year={2023},
|
260 |
+
eprint={2310.06825},
|
261 |
+
archivePrefix={arXiv},
|
262 |
+
primaryClass={cs.CL}
|
263 |
+
}
|
264 |
+
```
|
265 |
|
266 |
+
## Framework versions
|
267 |
|
268 |
|
269 |
+
- PEFT 0.6.3.dev0
|