Corianas commited on
Commit
cde6f01
1 Parent(s): 0744af8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +67 -33
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
- ## Uses
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
- [More Information Needed]
37
-
38
- ### Downstream Use [optional]
39
 
40
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
41
-
42
- [More Information Needed]
 
 
 
43
 
44
- ### Out-of-Scope Use
45
 
46
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
47
 
48
- [More Information Needed]
49
 
50
- ## Bias, Risks, and Limitations
 
51
 
52
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
 
53
 
54
- [More Information Needed]
55
 
56
- ### Recommendations
 
57
 
58
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
 
 
59
 
60
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
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
- <!-- 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. -->
73
-
74
- [More Information Needed]
75
 
76
  ### Training Procedure
77
 
78
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
79
 
80
  #### Preprocessing [optional]
81
 
82
- [More Information Needed]
 
 
 
 
 
 
 
 
83
 
 
 
84
 
85
- #### Training Hyperparameters
 
86
 
87
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
88
 
89
- #### Speeds, Sizes, Times [optional]
90
 
91
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
92
 
93
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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