Commit
·
2f3694a
1
Parent(s):
f8e0493
Update README.md
Browse files
README.md
CHANGED
|
@@ -9,4 +9,32 @@ tags:
|
|
| 9 |
- 'transformers '
|
| 10 |
- peft
|
| 11 |
- qlora
|
| 12 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- 'transformers '
|
| 10 |
- peft
|
| 11 |
- qlora
|
| 12 |
+
---
|
| 13 |
+
```
|
| 14 |
+
import torch
|
| 15 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 16 |
+
|
| 17 |
+
base_model_id = "mistralai/Mistral-7B-v0.1"
|
| 18 |
+
bnb_config = BitsAndBytesConfig(
|
| 19 |
+
load_in_4bit=True,
|
| 20 |
+
bnb_4bit_use_double_quant=True,
|
| 21 |
+
bnb_4bit_quant_type="nf4",
|
| 22 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 26 |
+
base_model_id, # Mistral, same as before
|
| 27 |
+
quantization_config=bnb_config, # Same quantization config as before
|
| 28 |
+
device_map="auto",
|
| 29 |
+
trust_remote_code=True,
|
| 30 |
+
use_auth_token=True
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
eval_tokenizer = AutoTokenizer.from_pretrained(
|
| 34 |
+
base_model_id,
|
| 35 |
+
add_bos_token=True,
|
| 36 |
+
trust_remote_code=True,
|
| 37 |
+
)
|
| 38 |
+
```
|
| 39 |
+
Now load the QLoRA adapter from the appropriate checkpoint directory
|
| 40 |
+
```
|