Prakamya commited on
Commit
8384760
1 Parent(s): b905111

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +293 -3
README.md CHANGED
@@ -1,3 +1,293 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - allenai/dolma
5
+ ---
6
+ # AMD-OLMo
7
+
8
+ AMD-OLMo are a series of 1B language models trained from scratch by AMD on AMD Instinct™ MI250 GPUs. The training code used is based on [OLMo](https://github.com/allenai/OLMo).
9
+ We release the pre-trained model, supervised fine-tuned model, and DPO aligned model as follows:
10
+
11
+ - [AMD-OLMo-1B](https://huggingface.co/amd/AMD-OLMo-1B): Pre-trained on a subset of [Dolma v1.7](https://huggingface.co/datasets/allenai/dolma) that consists of 1.3 trillion tokens.
12
+ - [AMD-OLMo-1B-SFT](https://huggingface.co/amd/AMD-OLMo-1B-SFT): Supervised fine-tuned (SFT) on [Tulu V2](https://huggingface.co/datasets/allenai/tulu-v2-sft-mixture) dataset (1st phase) and then [OpenHermes-2.5](https://huggingface.co/datasets/teknium/OpenHermes-2.5), [WebInstructSub](https://huggingface.co/datasets/TIGER-Lab/WebInstructSub), and [Code-Feedback](https://huggingface.co/datasets/m-a-p/Code-Feedback) datasets (2nd phase).
13
+ - [AMD-OLMo-1B-SFT-DPO](https://huggingface.co/amd/AMD-OLMo-1B-SFT-DPO): Aligned with human preferences using Direct Preference Optimization (DPO) on [UltraFeedback](https://huggingface.co/datasets/argilla/ultrafeedback-binarized-preferences-cleaned) dataset.
14
+
15
+ Description:
16
+
17
+ - **Hardware**: Each compute node consists of 4 AMD Instinct™ MI250 GPUs. We use 16 nodes for pretraining AMD-OLMo-1B
18
+
19
+ - **Training throughput**: 12,200 tokens/sec/gpu
20
+
21
+ - **Model architecture**: AMD-OLMo-1B is based on the model architecture and training set up of fully open source 1 billion version of [OLMo-1B](https://github.com/allenai/OLMo) with the details below:
22
+
23
+ | Parameter size | Number of layers | Number of heads | Hidden size | Context length | Vocabulary Size |
24
+ |-----------------:|:------------------:|:-----------------:|:-------------:|:----------------:|:----------------:|
25
+ | 1.2B | 16 | 16 | 2048 | 2048 | 50,280 |
26
+
27
+ - **Hyper-parameters**:
28
+ |Stage | LR schedule | Peak LR | Warmup steps |Epochs| Batch size (tokens) |
29
+ |------------:|:--------------:|:---------:|:--------------:|:------:|:---------------------:|
30
+ |Pretraining | Cosine | 4.0e-4 | 2000 | 1 | 4M |
31
+ |SFT Phase 1 | Linear | 2.0e-5 | 200 | 3 | 262K |
32
+ |SFT Phase 2 | Linear | 2.0e-5 | 200 | 3 | 1024K |
33
+ |DPO | Cosine | 4.0e-6 | 47 | 1 | 64K |
34
+
35
+ ## Usage
36
+
37
+ ### PyTorch on AMD GPUs
38
+ For running pytorch on AMD GPUs you can use the following rocm docker as in [docker hub](https://hub.docker.com/r/rocm/pytorch)
39
+
40
+ ```bash
41
+ docker pull rocm/pytorch:latest
42
+ # Inside docker
43
+ pip install transformers
44
+ ```
45
+
46
+ ### Use Example
47
+
48
+ ```python
49
+ from transformers import AutoModelForCausalLM, AutoTokenizer
50
+
51
+ model = AutoModelForCausalLM.from_pretrained("amd/AMD-OLMo-1B-SFT").to("cuda") # remove .to("cuda") to load on cpu
52
+ tokenizer = AutoTokenizer.from_pretrained("amd/AMD-OLMo-1B-SFT")
53
+
54
+ prompt = "What is large language model?"
55
+ bos = tokenizer.eos_token
56
+ template = bos + "<|user|>\n{prompt}\n<|assistant|>\n"
57
+
58
+ input_text = template.format(prompt=prompt)
59
+ inputs = tokenizer([input_text], return_tensors='pt', return_token_type_ids=False).to("cuda")
60
+ outputs = model.generate(**inputs, max_new_tokens=1000, do_sample=True, top_k=50, top_p=0.95)
61
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
62
+ ```
63
+
64
+
65
+ ## Main Results
66
+
67
+ ### Pretraining Results
68
+
69
+ | **Standard Benchmarks** | [TinyLLaMA-v1.1](https://huggingface.co/TinyLlama/TinyLlama_v1.1) (1.1B) | [MobiLLaMA-1B](https://huggingface.co/MBZUAI/MobiLlama-1B) (1.2B) | [OLMo-1B](https://huggingface.co/allenai/OLMo-1B-hf) (1.2B) | [OpenELM-1_1B](https://huggingface.co/apple/OpenELM-1_1B) (1.1B) | [OLMo-1B-0724-hf](https://huggingface.co/allenai/OLMo-1B-0724-hf) (1.2B) | [AMD-OLMo-1B](https://huggingface.co/amd/AMD-OLMo-1B) (1.2B) |
70
+ |---------------------:|:-----------------:|:-----------:|:-----------:|:---------------:|:---------------:|:-----------:|
71
+ | **arc_easy** | 55.47 | 56.65 | 57.28 | 55.43 | 56.65 | **63.64** |
72
+ | **arc_challenge** | 32.68 | 32.00 | 31.06 | 32.34 | 32.34 | **33.70** |
73
+ | **hellaswag** | 61.47 | 61.80 | 62.92 | 64.81 | **66.12** | 63.61 |
74
+ | **piqa** | 73.56 | 75.30 | 75.14 | **75.57** | 75.08 | **75.57** |
75
+ | **boolq** | 55.99 | 60.83 | 61.74 | 63.58 | **66.18** | 60.58 |
76
+ | **sciq** | 89.30 | 88.20 | 87.00 | 90.60 | 92.70 | **93.20** |
77
+ | **winogrande** | 59.43 | 59.27 | 59.98 | **61.72** | **61.72** | 61.64 |
78
+ | **openbookqa** | **36.80** | 35.40 | 36.20 | 36.20 | 35.60 | 35.80 |
79
+ | **mmlu (0-shot)** | 25.02 | 24.81 | 24.23 | 25.26 | **25.45** | 24.88 |
80
+ | **gsm8k (8-shot)** | 1.82 | 0.00 | 2.50 | 2.81 | **8.95** | 2.88 |
81
+ | **bbh (3-shot)** | **25.63** | 0.00 | **25.63** | 16.77 | 21.67 | 20.95 |
82
+ | **Average** | 47.02 | 44.93 | 47.61 | 47.73 | **49.31** | 48.77 |
83
+
84
+
85
+ ### Instruction Tuning Results
86
+
87
+ | **Standard Benchmarks**|[TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) (1.1B)|[MobiLlama-1B-Chat](https://huggingface.co/MBZUAI/MobiLlama-1B-Chat) (1.2B)|[OpenELM-1_1B-Instruct](https://huggingface.co/apple/OpenELM-1_1B-Instruct) (1.1B)|[AMD-OLMo-1B-SFT](https://huggingface.co/amd/AMD-OLMo-1B-SFT) (1.2B)|[AMD-OLMo-1B-SFT-DPO](https://huggingface.co/amd/AMD-OLMo-1B-SFT-DPO) (1.2B)|
88
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
89
+ | **arc_easy** | 54.42 | 57.41 | 52.44 | 63.68 | **64.31** |
90
+ | **arc_challenge** | 32.85 | 34.56 | **37.80** | 37.12 | 37.37 |
91
+ | **hellaswag** | 60.40 | 62.51 | **71.29** | 61.63 | 61.91 |
92
+ | **piqa** | 74.48 | **75.73** | 75.03 | 74.43 | 74.16 |
93
+ | **boolq** | 61.04 | 55.66 | **70.28** | 68.53 | 70.24 |
94
+ | **sciq** | 88.40 | 87.10 | 89.50 | 91.20 | **92.10** |
95
+ | **winogrande** | 60.54 | 60.77 | **62.19** | 60.22 | 60.62 |
96
+ | **openbookqa** | 37.20 | 36.80 | 39.20 | 37.40 | **40.20** |
97
+ | **mmlu** | 24.61 | 25.25 | 25.54 | 29.97 | **30.52** |
98
+ | **gsm8k (8-shot)**| 2.81 | 0.23 | 1.82 | **18.20** | 15.77 |
99
+ | **bbh (3-shot)** | **26.83** | 0.00 | 13.40 | 25.17 | 25.45 |
100
+ | **Average** | 47.60 | 45.09 | 48.95 | 51.60 | **52.06** |
101
+
102
+ |**Chat Benchmarks**|[TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) (1.1B)|[MobiLlama-1B-Chat](https://huggingface.co/MBZUAI/MobiLlama-1B-Chat) (1.2B)|[OpenELM-1_1B-Instruct](https://huggingface.co/apple/OpenELM-1_1B-Instruct) (1.1B)|[AMD-OLMo-1B-SFT](https://huggingface.co/amd/AMD-OLMo-1B-SFT) (1.2B)|[AMD-OLMo-1B-SFT-DPO](https://huggingface.co/amd/AMD-OLMo-1B-SFT-DPO) (1.2B)|
103
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
104
+ | **AlpacaEval 1 (Win Rate)** | 50.81 | 34.90 | 37.72 | 50.12 | **54.22** |
105
+ | **AlpacaEval 2 (LC Win Rate)**| 1.54 | 1.59 | 0.49 | **3.88** | 2.37 |
106
+ | **MTBench** | 3.38 | 2.89 | - | **4.35** | 4.10 |
107
+
108
+ |**Responsible AI Benchmarks**|[TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) (1.1B)|[MobiLlama-1B-Chat](https://huggingface.co/MBZUAI/MobiLlama-1B-Chat) (1.2B)|[OpenELM-1_1B-Instruct](https://huggingface.co/apple/OpenELM-1_1B-Instruct) (1.1B)|[AMD-OLMo-1B-SFT](https://huggingface.co/amd/AMD-OLMo-1B-SFT) (1.2B)|[AMD-OLMo-1B-SFT-DPO](https://huggingface.co/amd/AMD-OLMo-1B-SFT-DPO) (1.2B)|
109
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
110
+ | **ToxiGen** | 41.70 | **37.23** | 42.34 | 39.04 | 39.68 |
111
+ | **crows_pairs** | 60.35 | 58.50 | 59.93 | 60.29 | **61.00** |
112
+ | **TruthfulQA-mc2**| 37.92 | 38.46 | **45.84** | 37.45 | 40.06 |
113
+
114
+ *In generating tokens for chat benchmark evaluations, we use `max_length=2048` for AlpacaEval and `max_new_tokens=2048` for MTBench.
115
+
116
+ *All numbers in above tables were obtained from our evaluations.
117
+
118
+
119
+ ## Evaluation
120
+ We use the following open source evaluation frameworks for evaluating our models:
121
+ - [Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness): For evaluating on commonsense reasoning, multi-task understanding & responsible AI benchmarks
122
+ - [AlpacaEval](https://github.com/tatsu-lab/alpaca_eval): For evaluating instruction-following capabilities of chat models.
123
+ - [MT-Bench](https://github.com/lm-sys/FastChat/tree/main/fastchat/llm_judge): For evaluating multi-turn capabilities of chat models.
124
+
125
+ ### Setup
126
+ ```bash
127
+ # lm-eval-harness
128
+ git clone https://github.com/EleutherAI/lm-evaluation-harness
129
+ cd lm-evaluation-harness
130
+ pip install -e .
131
+
132
+ # AlpacaEval
133
+ pip install git+https://github.com/tatsu-lab/alpaca_eval
134
+ cd alpaca_eval
135
+ pip install -e .
136
+
137
+ # MT-Bench
138
+ git clone https://github.com/lm-sys/FastChat.git
139
+ cd FastChat
140
+ pip install -e ".[model_worker,llm_judge]"
141
+ ```
142
+
143
+ ### Run evaluation
144
+ ```bash
145
+ # lm-eval-harness
146
+ HF_MODEL=amd/AMD-OLMo-1B-SFT-DPO
147
+ accelerate launch -m lm_eval --model hf \
148
+ --model_args pretrained=$HF_MODEL,trust_remote_code=True \
149
+ --tasks arc_easy,arc_challenge,hellaswag,piqa,boolq,sciq,winogrande,openbookqa,mmlu,gsm8k_cot,bbh_cot_fewshot,toxigen,truthfulqa,crows_pairs \
150
+ --device cuda \
151
+ --batch_size 32 \
152
+ --output_path ./lm-eval-results/$HF_MODEL
153
+ ```
154
+
155
+ ## Training
156
+
157
+ ### Setup
158
+ ```bash
159
+ WORK_DIR="<path_to_your_working_directory>"
160
+ cd $WORK_DIR
161
+ # Clone OLMo codebase:
162
+ git clone https://github.com/allenai/OLMo.git --branch v0.3.0
163
+ cd OLMo
164
+ # Clone AMD-OLMo that contains files to reproduce our model training
165
+ git clone https://huggingface.co/amd/AMD-OLMo
166
+
167
+ docker pull rocm/pytorch:latest
168
+ docker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --shm-size 8G -v $WORK_DIR/OLMo:/OLMo -w /OLMo rocm/pytorch:latest
169
+
170
+ # Remove Line 17 as the docker already has ROCm PyTorch installed
171
+ sed -i '17d' pyproject.toml
172
+ pip install -e .[all]
173
+ ```
174
+
175
+ ### Download and prepare pretraining datasets
176
+ ```bash
177
+ # Download
178
+ DATA_DIR=./datasets/dolma
179
+ mkdir -p $DATA_DIR
180
+
181
+ PARALLEL_DOWNLOADS="<number_of_parallel_downloads>"
182
+ cat "AMD-OLMo/dolma_v1_7_subset.txt" | xargs -n 1 -P $PARALLEL_DOWNLOADS wget -q -P $DATA_DIR
183
+
184
+ # Prepare
185
+ NUM_WORKERS="<number_of_workers>"
186
+ python scripts/prepare_memmap_dataset.py $DATA_DIR/*.json.gz -o $DATA_DIR/memmap_dataset --workers $NUM_WORKERS
187
+ ```
188
+
189
+ ### Download and prepare SFT datasets
190
+ ```bash
191
+ # 1st phase SFT dataset
192
+ python AMD-OLMo/prepare_sft_data.py --output_dir ./datasets/tulu --tokenizer tokenizers/allenai_eleuther-ai-gpt-neox-20b-pii-special.json --dataset tulu
193
+
194
+ # 2nd phase SFT dataset
195
+ python AMD-OLMo/prepare_sft_data.py --output_dir ./datasets/OpenHermes_WebInstructSub_CodeFeedBack --tokenizer tokenizers/allenai_eleuther-ai-gpt-neox-20b-pii-special.json --dataset 2nd-phase
196
+ ```
197
+
198
+ ### Run Training
199
+ Pretrainig config: [AMD-OLMo-1B.yaml](AMD-OLMo-1B.yaml)
200
+
201
+ SFT config: [AMD-OLMo-1B-SFT-1st-phase.yaml](AMD-OLMo-1B-SFT-1st-phase.yaml) and [AMD-OLMo-1B-SFT-2nd-phase.yaml](AMD-OLMo-1B-SFT-2nd-phase.yaml)
202
+ ```bash
203
+ # Single node
204
+ HSA_FORCE_FINE_GRAIN_PCIE=1 OMP_NUM_THREADS=128 NCCL_DEBUG=INFO torchrun --nproc_per_node=8 ./scripts/train.py AMD-OLMo/AMD-OLMo-1B.yaml
205
+
206
+ # Multiple nodes
207
+ HSA_FORCE_FINE_GRAIN_PCIE=1 OMP_NUM_THREADS=128 NCCL_DEBUG=INFO torchrun --nnodes=$nnodes --node-rank=$node_rank --master_addr=$master_addr --master_port=$master_port --nproc_per_node=8 ./scripts/train.py AMD-OLMo/AMD-OLMo-1B.yaml
208
+ ```
209
+
210
+ ### Run DPO Training
211
+
212
+ DPO recipe: [AMD-OLMo-1B-dpo.yaml](AMD-OLMo-1B-dpo.yaml).
213
+ ```bash
214
+ # install trl library
215
+ git clone https://github.com/huggingface/trl.git -b v0.8.6
216
+
217
+ # replace dpo_trainer.py
218
+ cp AMD-OLMo/dpo_trainer.py trl/trl/trainer
219
+
220
+ pip install -e ./trl
221
+
222
+ # install alignment-handbook
223
+ git clone https://github.com/huggingface/alignment-handbook.git hf-align
224
+ # 70769f9 is the main branch on 2024-04-11.
225
+ cd hf-align && git checkout 70769f9 && cd ..
226
+
227
+ pip install -e ./hf-align
228
+
229
+ # Copy AMD OLMo DPO recipe to hf-align/recipes.
230
+ cp AMD-OLMo/AMD-OLMo-1B-dpo.yaml hf-align/recipes/
231
+
232
+ # Prepare the converted AMD-OLMo SFT Huggingface model to ckpt_dir.
233
+ ckpt_dir=amd/AMD-OLMo-1B-SFT
234
+ local_tokenizer_dir=${ckpt_dir}
235
+
236
+ # Set output checkpoint dir.
237
+ dpo_ckpt_dir=<your_output_checkpoint_dir>
238
+
239
+ accelerate launch --config_file hf-align/recipes/accelerate_configs/deepspeed_zero3.yaml \
240
+ hf-align/scripts/run_dpo.py hf-align/recipes/AMD-OLMo-1B-dpo.yaml \
241
+ --trust_remote_code=true \
242
+ --model_name_or_path=${ckpt_dir} \
243
+ --tokenizer_name_or_path=${local_tokenizer_dir} \
244
+ --output_dir=${dpo_ckpt_dir} \
245
+ --num_train_epochs=1 \
246
+ --learning_rate=4e-6 \
247
+ --beta=0.3 \
248
+ --loss_type=sigmoid
249
+ ```
250
+
251
+ ## Bias, Risks, and Limitations
252
+
253
+ - The models are being released for research purposes only and are not intended for use cases that require high levels of factuality, safety critical situations, health or medical applications, generating false information, facilitating toxic conversations.
254
+ - Model checkpoints are made accessible without any safety guarantees. It is crucial for users to conduct comprehensive evaluations and implement safety filtering mechanisms as per their respective use cases.
255
+ - It may be possible to prompt the model to generate content that may be factually inaccurate, harmful, violent, toxic, biased, or otherwise objectionable. Such content may also get generated by prompts that did not intend to produce output as such. Users are thus requested to be aware of this and exercise caution and responsible thinking when using the model.
256
+ - Multi-lingual abilities of the models have not been tested and thus may misunderstand and generate erroneous responses across different languages.
257
+
258
+ ## Appendix
259
+ ### Evaluation Metrics
260
+ | **Benchmark** | Metric |
261
+ |---------------------:|:-----------------:|
262
+ | **arc_easy** | Normalized Accuracy |
263
+ | **arc_challenge** | Normalized Accuracy |
264
+ | **hellaswag** | Normalized Accuracy |
265
+ | **piqa** | Accuracy |
266
+ | **boolq** | Accuracy |
267
+ | **sciq** | Accuracy |
268
+ | **winogrande** | Accuracy |
269
+ | **openbookqa** | Normalized Accuracy |
270
+ | **mmlu** | Accuracy |
271
+ | **gsm8k (8-shot)** | Exact Match (Flexible Extract) |
272
+ | **bbh (3-shot)** | Exact Match |
273
+ | **ToxiGen** | Accuracy |
274
+ | **crows_pairs** | PCT Stereotype |
275
+ | **TruthfulQA-mc2** | Accuracy |
276
+ | **AlpacaEval 1 (Win Rate)** | Win Rate (chatgpt_fn) |
277
+ | **AlpacaEval 2 (LC Win Rate)** | Length Control Win Rate (weighted_alpaca_eval_gpt4_turbo) |
278
+ | **MTBench** | Average score for single-answer grading (2 turns) |
279
+
280
+ #### License
281
+ Copyright (c) 2018-2024 Advanced Micro Devices, Inc. All Rights Reserved.
282
+
283
+ Licensed under the Apache License, Version 2.0 (the "License");
284
+ you may not use this file except in compliance with the License.
285
+ You may obtain a copy of the License at
286
+
287
+ http://www.apache.org/licenses/LICENSE-2.0
288
+
289
+ Unless required by applicable law or agreed to in writing, software
290
+ distributed under the License is distributed on an "AS IS" BASIS,
291
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
292
+ See the License for the specific language governing permissions and
293
+ limitations under the License.