RichardErkhov commited on
Commit
d2e281b
1 Parent(s): 44af55e

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +195 -0
README.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ phi-2-upscaled-4B-instruct-v0.1 - bnb 4bits
11
+ - Model creator: https://huggingface.co/daekeun-ml/
12
+ - Original model: https://huggingface.co/daekeun-ml/phi-2-upscaled-4B-instruct-v0.1/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ language:
20
+ - en
21
+ license: apache-2.0
22
+ library_name: transformers
23
+ datasets:
24
+ - Intel/orca_dpo_pairs
25
+ - wikipedia
26
+ - Open-Orca/OpenOrca
27
+ inference: false
28
+ ---
29
+
30
+ # phi-2-upscaled-4B-instruct-v0.1
31
+
32
+ ## Model Details
33
+ This model is a model that performed continued pre-training and fine-tuning (instruction tuning) using the depth up-scaling (DUS) technique disclosed by Upstage.
34
+
35
+ ### DUS(Depth Up-Scaling) and continued pre-training
36
+ Similar to the methodology disclosed in the paper, we expanded from 32 transformer blocks to 48 blocks and then continued pre-training with the public dataset. Pre-training was performed for 3 days using 4 `ml.g5.48xlarge` instances from AWS (NVIDIA A10G GPU x 32ea). For pre-training, we used a sample set from Wikipedia.
37
+ Note that performance is not guaranteed since only a small number of datasets were used for the experiment. The number of samples for training set is just around 1.5 million after tokenization.
38
+ For distributed training, all weights were trained without adapter techniques, and sharding parallelization was performed with ZeRO-2. The presets are as follows.
39
+
40
+ ```json
41
+ {
42
+ "fp16": {
43
+ "enabled": "auto",
44
+ "loss_scale": 0,
45
+ "loss_scale_window": 1000,
46
+ "initial_scale_power": 16,
47
+ "hysteresis": 2,
48
+ "min_loss_scale": 1
49
+ },
50
+
51
+ "bf16": {
52
+ "enabled": "auto"
53
+ },
54
+
55
+ "optimizer": {
56
+ "type": "AdamW",
57
+ "params": {
58
+ "lr": "auto",
59
+ "betas": "auto",
60
+ "eps": "auto",
61
+ "weight_decay": "auto"
62
+ }
63
+ },
64
+
65
+ "scheduler": {
66
+ "type": "WarmupLR",
67
+ "params": {
68
+ "warmup_min_lr": "auto",
69
+ "warmup_max_lr": "auto",
70
+ "warmup_num_steps": "auto"
71
+ }
72
+ },
73
+
74
+ "zero_optimization": {
75
+ "stage": 2,
76
+ "allgather_partitions": true,
77
+ "allgather_bucket_size": 2e8,
78
+ "overlap_comm": true,
79
+ "reduce_scatter": true,
80
+ "reduce_bucket_size": 2e8,
81
+ "contiguous_gradients": true,
82
+ "cpu_offload": true
83
+ },
84
+
85
+ "gradient_accumulation_steps": "auto",
86
+ "gradient_clipping": "auto",
87
+ "train_batch_size": "auto",
88
+ "train_micro_batch_size_per_gpu": "auto"
89
+ }
90
+ ```
91
+
92
+ Some hyperparameters are listed below.
93
+ ```
94
+ batch_size: 2
95
+ num_epochs: 1
96
+ learning_rate: 3e-4
97
+ gradient_accumulation_steps: 8
98
+ lr_scheduler_type: "linear"
99
+ group_by_length: False
100
+ ```
101
+
102
+ ### Fine-tuning
103
+ After performing pre-training, instruction tuning and alignment tuning were performed sequentially. This process only took about 10 hours using AWS `ml.g5.24xlarge` (NVIDIA A10G GPU x 4ea). The dataset used for instruction tuning is a sample set of the OpenOrca dataset, and the dataset used for alignment tuning is Intel's orca_dpo_pairs dataset.
104
+ All fine-tuning was learned using QLoRA, and the batch sizes were set to 3 and 1, respectively. We used 1,024 for the context length. 2,048 is also possible, but applying DPO often runs out of memory on 24GB GPU memory, so we settled on 1,024.
105
+ Please see below for relevant code snippets.
106
+
107
+ ```python
108
+ peft_config = LoraConfig(
109
+ r=8,
110
+ lora_alpha=16,
111
+ target_modules=["q_proj", "k_proj", "v_proj", "fc1", "fc2"],
112
+ lora_dropout=0.05,
113
+ bias="none",
114
+ task_type="CAUSAL_LM",
115
+ )
116
+ training_arguments = TrainingArguments(
117
+ output_dir="logs",
118
+ num_train_epochs=1,
119
+ per_device_train_batch_size=batch_size,
120
+ gradient_accumulation_steps=4,
121
+ optim="paged_adamw_8bit",
122
+ learning_rate=3e-4,
123
+ weight_decay=0.001,
124
+ bf16=True,
125
+ max_grad_norm=0.3,
126
+ max_steps=-1,
127
+ warmup_ratio=0.03,
128
+ group_by_length=True,
129
+ lr_scheduler_type="cosine",
130
+ report_to="wandb", ...
131
+ )
132
+ ```
133
+
134
+ ### References
135
+ - Base model: [microsoft/phi-2](https://huggingface.co/microsoft/phi-2)
136
+ - Paper: [SOLAR 10.7B](https://arxiv.org/abs/2312.15166)
137
+
138
+ ## How to Get Started with the Model
139
+
140
+ Since this model used ChatGPT's ChatML template, <im_start> and <im_end> tokens were added.
141
+ You can use Hugging Face's chat template to create the prompt, but you can also create the prompt yourself with the code snippet below.
142
+
143
+ ```python
144
+ def create_inference_prompt(text):
145
+ string = f"""<|im_start|>system
146
+ You are a helpful AI assistant.<|im_end|>
147
+ <|im_start|>user
148
+ {text}<|im_end|>
149
+ <|im_start|>assistant
150
+ """
151
+ return string
152
+ ```
153
+
154
+ If you want to simply see the inference results, please use the code snippet below.
155
+
156
+ ```python
157
+ from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
158
+ import torch
159
+ torch.set_default_device("cuda")
160
+ model_path = "daekeun-ml/phi-2-upscaled-4B-instruct-v0.1"
161
+
162
+ model = AutoModelForCausalLM.from_pretrained(
163
+ model_path,
164
+ torch_dtype="auto",
165
+ trust_remote_code=True)
166
+
167
+ tokenizer = AutoTokenizer.from_pretrained(
168
+ model_path,
169
+ use_fast=True,
170
+ trust_remote_code=True
171
+ )
172
+
173
+ # Format prompt
174
+ message = [
175
+ {"role": "system", "content": "You are a helpful AI assistant. Generate appropriate answers to given questions."},
176
+ {"role": "user", "content": "What is a Large Language Model?"}
177
+ ]
178
+
179
+ prompt = tokenizer.apply_chat_template(message, add_generation_prompt=True, tokenize=False)
180
+ inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)
181
+
182
+ outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, top_p=0.9, temperature=0.5, repetition_penalty=1.2)
183
+ text = tokenizer.batch_decode(outputs)[0]
184
+ print(text)
185
+ ```
186
+
187
+ ## Notes
188
+
189
+ ### License
190
+
191
+ Apache 2.0; The license of phi-2 is MIT, but the license of the orca dataset used for training is apache 2.0.
192
+
193
+ ### Caution
194
+ This model was created as a personal experiment, unrelated to the organization I work for. The model may not operate correctly because separate verification was not performed. Please be careful unless it is for personal experimentation or PoC (Proof of Concept)!
195
+