Update README.md
Browse files
README.md
CHANGED
@@ -22,7 +22,7 @@ The Mistral-7B-Instruct-v0.1 LLM is a pretrained generative text model with 7 bi
|
|
22 |
|
23 |
## Model Details
|
24 |
|
25 |
-
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 [jondurbin/airoboros-2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-2.2.1) dataset.
|
26 |
|
27 |
- **Developed by:** Daniel Furman
|
28 |
- **Model type:** Decoder-only
|
@@ -53,14 +53,15 @@ We use Eleuther.AI's [Language Model Evaluation Harness](https://github.com/Eleu
|
|
53 |
<summary>Setup</summary>
|
54 |
|
55 |
```python
|
56 |
-
!pip install -q -U transformers peft torch accelerate
|
|
|
57 |
|
|
|
58 |
import torch
|
59 |
from peft import PeftModel, PeftConfig
|
60 |
from transformers import (
|
61 |
AutoModelForCausalLM,
|
62 |
AutoTokenizer,
|
63 |
-
BitsAndBytesConfig,
|
64 |
)
|
65 |
```
|
66 |
|
@@ -73,17 +74,14 @@ tokenizer = AutoTokenizer.from_pretrained(
|
|
73 |
use_fast=True,
|
74 |
trust_remote_code=True,
|
75 |
)
|
76 |
-
|
77 |
-
load_in_4bit=True,
|
78 |
-
bnb_4bit_quant_type="nf4",
|
79 |
-
bnb_4bit_compute_dtype=torch.bfloat16,
|
80 |
-
)
|
81 |
model = AutoModelForCausalLM.from_pretrained(
|
82 |
config.base_model_name_or_path,
|
83 |
-
|
84 |
device_map="auto",
|
85 |
trust_remote_code=True,
|
86 |
)
|
|
|
87 |
model = PeftModel.from_pretrained(
|
88 |
model,
|
89 |
peft_model_id
|
@@ -99,18 +97,31 @@ messages = [
|
|
99 |
]
|
100 |
|
101 |
print("\n\n*** Prompt:")
|
102 |
-
|
103 |
messages,
|
104 |
-
tokenize=
|
105 |
-
add_generation_prompt=True
|
|
|
106 |
)
|
107 |
-
print(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
|
|
109 |
print("\n\n*** Generate:")
|
110 |
-
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
|
111 |
with torch.autocast("cuda", dtype=torch.bfloat16):
|
112 |
output = model.generate(
|
113 |
-
input_ids=input_ids,
|
114 |
max_new_tokens=1024,
|
115 |
do_sample=True,
|
116 |
temperature=0.7,
|
@@ -126,20 +137,21 @@ response = tokenizer.decode(
|
|
126 |
skip_special_tokens=True
|
127 |
)
|
128 |
print(response)
|
129 |
-
```
|
130 |
-
|
131 |
-
<details>
|
132 |
|
133 |
-
<summary>Output</summary>
|
134 |
-
|
135 |
-
**Prompt**:
|
136 |
-
```python
|
137 |
-
coming
|
138 |
```
|
139 |
|
140 |
**Generation**:
|
141 |
```python
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
```
|
144 |
|
145 |
</details>
|
@@ -153,7 +165,7 @@ coming
|
|
153 |
|
154 |
## Training
|
155 |
|
156 |
-
It took ~
|
157 |
|
158 |
### Prompt Format
|
159 |
|
@@ -168,12 +180,20 @@ This format is available as a [chat template](https://huggingface.co/docs/transf
|
|
168 |
|
169 |
```python
|
170 |
messages = [
|
171 |
-
{"role": "user", "content": "
|
172 |
-
{"role": "assistant", "content": "
|
173 |
-
{"role": "user", "content": "
|
|
|
174 |
]
|
175 |
-
|
176 |
-
print(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
```
|
178 |
|
179 |
<details>
|
@@ -181,7 +201,7 @@ print(prompt)
|
|
181 |
<summary>Output</summary>
|
182 |
|
183 |
```python
|
184 |
-
|
185 |
```
|
186 |
</details>
|
187 |
|
|
|
22 |
|
23 |
## Model Details
|
24 |
|
25 |
+
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 [jondurbin/airoboros-2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-2.2.1) dataset.
|
26 |
|
27 |
- **Developed by:** Daniel Furman
|
28 |
- **Model type:** Decoder-only
|
|
|
53 |
<summary>Setup</summary>
|
54 |
|
55 |
```python
|
56 |
+
!pip install -q -U transformers peft torch accelerate einops sentencepiece
|
57 |
+
```
|
58 |
|
59 |
+
```python
|
60 |
import torch
|
61 |
from peft import PeftModel, PeftConfig
|
62 |
from transformers import (
|
63 |
AutoModelForCausalLM,
|
64 |
AutoTokenizer,
|
|
|
65 |
)
|
66 |
```
|
67 |
|
|
|
74 |
use_fast=True,
|
75 |
trust_remote_code=True,
|
76 |
)
|
77 |
+
|
|
|
|
|
|
|
|
|
78 |
model = AutoModelForCausalLM.from_pretrained(
|
79 |
config.base_model_name_or_path,
|
80 |
+
torch_dtype=torch.float16,
|
81 |
device_map="auto",
|
82 |
trust_remote_code=True,
|
83 |
)
|
84 |
+
|
85 |
model = PeftModel.from_pretrained(
|
86 |
model,
|
87 |
peft_model_id
|
|
|
97 |
]
|
98 |
|
99 |
print("\n\n*** Prompt:")
|
100 |
+
input_ids = tokenizer.apply_chat_template(
|
101 |
messages,
|
102 |
+
tokenize=True,
|
103 |
+
add_generation_prompt=True,
|
104 |
+
return_tensors="pt",
|
105 |
)
|
106 |
+
print(tokenizer.decode(input_ids[0]))
|
107 |
+
```
|
108 |
+
|
109 |
+
<details>
|
110 |
+
|
111 |
+
<summary>Output</summary>
|
112 |
+
|
113 |
+
**Prompt**:
|
114 |
+
```python
|
115 |
+
"""
|
116 |
+
<s> [INST] Tell me a recipe for a mai tai. [/INST]
|
117 |
+
"""
|
118 |
+
```
|
119 |
|
120 |
+
```python
|
121 |
print("\n\n*** Generate:")
|
|
|
122 |
with torch.autocast("cuda", dtype=torch.bfloat16):
|
123 |
output = model.generate(
|
124 |
+
input_ids=input_ids.cuda(),
|
125 |
max_new_tokens=1024,
|
126 |
do_sample=True,
|
127 |
temperature=0.7,
|
|
|
137 |
skip_special_tokens=True
|
138 |
)
|
139 |
print(response)
|
|
|
|
|
|
|
140 |
|
|
|
|
|
|
|
|
|
|
|
141 |
```
|
142 |
|
143 |
**Generation**:
|
144 |
```python
|
145 |
+
"""1 oz light rum
|
146 |
+
½ oz dark rum
|
147 |
+
¼ oz orange curaçao
|
148 |
+
2 oz pineapple juice
|
149 |
+
¾ oz lime juice
|
150 |
+
Dash of orgeat syrup (optional)
|
151 |
+
Splash of grenadine (for garnish, optional)
|
152 |
+
Lime wheel and cherry garnishes (optional)
|
153 |
+
|
154 |
+
Shake 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."""
|
155 |
```
|
156 |
|
157 |
</details>
|
|
|
165 |
|
166 |
## Training
|
167 |
|
168 |
+
It took ~2 hours to train 2 epochs on 1x A100 (40 GB SXM).
|
169 |
|
170 |
### Prompt Format
|
171 |
|
|
|
180 |
|
181 |
```python
|
182 |
messages = [
|
183 |
+
{"role": "user", "content": "Tell me a recipe for a mai tai."},
|
184 |
+
{"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."},
|
185 |
+
{"role": "user", "content": "How can I make it more upscale and luxurious?"},
|
186 |
+
|
187 |
]
|
188 |
+
|
189 |
+
print("\n\n*** Prompt:")
|
190 |
+
input_ids = tokenizer.apply_chat_template(
|
191 |
+
messages,
|
192 |
+
tokenize=True,
|
193 |
+
add_generation_prompt=True,
|
194 |
+
return_tensors="pt",
|
195 |
+
)
|
196 |
+
print(tokenizer.decode(input_ids[0]))
|
197 |
```
|
198 |
|
199 |
<details>
|
|
|
201 |
<summary>Output</summary>
|
202 |
|
203 |
```python
|
204 |
+
<s> [INST] Tell me a recipe for a mai tai. [/INST] 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.</s> [INST] How can I make it more upscale and luxurious? [/INST]
|
205 |
```
|
206 |
</details>
|
207 |
|