Update README.md
Browse files
README.md
CHANGED
|
@@ -12,7 +12,6 @@ language:
|
|
| 12 |
This is a DPO finetune of Mistral 7b-instruct0.2 following the article: https://towardsdatascience.com/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac
|
| 13 |
|
| 14 |
|
| 15 |
-
|
| 16 |
## Model Details
|
| 17 |
|
| 18 |
### Model Description
|
|
@@ -25,39 +24,48 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 25 |
- **Finetuned from model: mistralai/Mistral-7B-Instruct-v0.2
|
| 26 |
|
| 27 |
|
| 28 |
-
##
|
| 29 |
-
|
| 30 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 31 |
-
|
| 32 |
-
### Direct Use
|
| 33 |
-
|
| 34 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 35 |
|
| 36 |
-
[
|
| 37 |
-
|
| 38 |
-
### Downstream Use [optional]
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
[
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
## How to Get Started with the Model
|
| 63 |
|
|
@@ -69,28 +77,54 @@ Use the code below to get started with the model.
|
|
| 69 |
|
| 70 |
### Training Data
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
|
| 76 |
### Training Procedure
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
#### Preprocessing [optional]
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
#
|
|
|
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
#### Speeds, Sizes, Times [optional]
|
| 90 |
|
| 91 |
-
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
## Evaluation
|
| 96 |
|
|
|
|
| 12 |
This is a DPO finetune of Mistral 7b-instruct0.2 following the article: https://towardsdatascience.com/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac
|
| 13 |
|
| 14 |
|
|
|
|
| 15 |
## Model Details
|
| 16 |
|
| 17 |
### Model Description
|
|
|
|
| 24 |
- **Finetuned from model: mistralai/Mistral-7B-Instruct-v0.2
|
| 25 |
|
| 26 |
|
| 27 |
+
## Instruction format
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
In order to leverage instruction fine-tuning, your prompt should be surrounded by `[INST]` and `[/INST]` tokens. The very first instruction should begin with a begin of sentence id. The next instructions should not. The assistant generation will be ended by the end-of-sentence token id.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
E.g.
|
| 32 |
+
```
|
| 33 |
+
text = "<s>[INST] What is your favourite condiment? [/INST]"
|
| 34 |
+
"Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> "
|
| 35 |
+
"[INST] Do you have mayonnaise recipes? [/INST]"
|
| 36 |
+
```
|
| 37 |
|
| 38 |
+
This format is available as a [chat template](https://huggingface.co/docs/transformers/main/chat_templating) via the `apply_chat_template()` method:
|
| 39 |
|
| 40 |
+
```python
|
| 41 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 42 |
|
| 43 |
+
device = "cuda" # the device to load the model onto
|
| 44 |
|
| 45 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")
|
| 47 |
|
| 48 |
+
messages = [
|
| 49 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
| 50 |
+
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
|
| 51 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
| 52 |
+
]
|
| 53 |
|
| 54 |
+
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
| 55 |
|
| 56 |
+
model_inputs = encodeds.to(device)
|
| 57 |
+
model.to(device)
|
| 58 |
|
| 59 |
+
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
|
| 60 |
+
decoded = tokenizer.batch_decode(generated_ids)
|
| 61 |
+
print(decoded[0])
|
| 62 |
+
```
|
| 63 |
|
| 64 |
+
## Model Architecture
|
| 65 |
+
This instruction model is based on Mistral-7B-v0.1, a transformer model with the following architecture choices:
|
| 66 |
+
- Grouped-Query Attention
|
| 67 |
+
- Sliding-Window Attention
|
| 68 |
+
- Byte-fallback BPE tokenizer
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
|
|
|
| 77 |
|
| 78 |
### Training Data
|
| 79 |
|
| 80 |
+
Intel/orca_dpo_pairs
|
|
|
|
|
|
|
| 81 |
|
| 82 |
### Training Procedure
|
| 83 |
|
| 84 |
+
https://medium.com/towards-data-science/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac
|
| 85 |
|
| 86 |
#### Preprocessing [optional]
|
| 87 |
|
| 88 |
+
def chatml_format(example):
|
| 89 |
+
# Format system
|
| 90 |
+
if len(example['system']) > 0:
|
| 91 |
+
message = {"role": "user", "content": f"{example['system']}\n{example['question']}"}
|
| 92 |
+
prompt = tokenizer.apply_chat_template([message], tokenize=False)
|
| 93 |
+
else:
|
| 94 |
+
# Format instruction
|
| 95 |
+
message = {"role": "user", "content": example['question']}
|
| 96 |
+
prompt = tokenizer.apply_chat_template([message], tokenize=False, add_generation_prompt=True)
|
| 97 |
|
| 98 |
+
# Format chosen answer
|
| 99 |
+
chosen = example['chosen'] + tokenizer.eos_token
|
| 100 |
|
| 101 |
+
# Format rejected answer
|
| 102 |
+
rejected = example['rejected'] + tokenizer.eos_token
|
| 103 |
|
| 104 |
+
return {
|
| 105 |
+
"prompt": prompt,
|
| 106 |
+
"chosen": chosen,
|
| 107 |
+
"rejected": rejected,
|
| 108 |
+
}
|
| 109 |
|
|
|
|
| 110 |
|
| 111 |
+
#### Training Hyperparameters
|
| 112 |
|
| 113 |
+
training_args = TrainingArguments(
|
| 114 |
+
per_device_train_batch_size=4,
|
| 115 |
+
gradient_accumulation_steps=4,
|
| 116 |
+
gradient_checkpointing=True,
|
| 117 |
+
learning_rate=5e-5,
|
| 118 |
+
lr_scheduler_type="cosine",
|
| 119 |
+
max_steps=200,
|
| 120 |
+
save_strategy="no",
|
| 121 |
+
logging_steps=1,
|
| 122 |
+
output_dir=new_model,
|
| 123 |
+
optim="paged_adamw_32bit",
|
| 124 |
+
warmup_steps=100,
|
| 125 |
+
bf16=True,
|
| 126 |
+
report_to="wandb",
|
| 127 |
+
)
|
| 128 |
|
| 129 |
## Evaluation
|
| 130 |
|