professorf commited on
Commit
4b0cc90
1 Parent(s): d2f4454

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +313 -0
README.md ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - allenai/dolma
5
+ pipeline_tag: text-generation
6
+ ---
7
+ <hr>
8
+ <center>GGUF Quantized AMD-OLMo Models<br>
9
+ by Professor Nick V. Flor<br>
10
+ For research reproducibility purposes</center>
11
+ <hr>
12
+
13
+ # AMD-OLMo
14
+
15
+ 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).
16
+ We release the pre-trained model, supervised fine-tuned model, and DPO aligned model as follows:
17
+
18
+ - [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.
19
+ - [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).
20
+ - [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.
21
+
22
+ Description:
23
+
24
+ - **Hardware**: Each compute node consists of 4 AMD Instinct™ MI250 GPUs. We use 16 nodes for pretraining AMD-OLMo-1B
25
+
26
+ - **Training throughput**: 12,200 tokens/sec/gpu
27
+
28
+ - **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:
29
+
30
+ | Parameter size | Number of layers | Number of heads | Hidden size | Context length | Vocabulary Size |
31
+ |-----------------:|:------------------:|:-----------------:|:-------------:|:----------------:|:----------------:|
32
+ | 1.2B | 16 | 16 | 2048 | 2048 | 50,280 |
33
+
34
+ - **Hyper-parameters**:
35
+ |Stage | LR schedule | Peak LR | Warmup steps |Epochs| Batch size (tokens) |
36
+ |------------:|:--------------:|:---------:|:--------------:|:------:|:---------------------:|
37
+ |Pretraining | Cosine | 4.0e-4 | 2000 | 1 | 4M |
38
+ |SFT Phase 1 | Linear | 2.0e-5 | 200 | 3 | 262K |
39
+ |SFT Phase 2 | Linear | 2.0e-5 | 200 | 3 | 1024K |
40
+ |DPO | Cosine | 4.0e-6 | 47 | 1 | 64K |
41
+
42
+ For more details, please refer to our [blog](https://www.amd.com/en/developer/resources/technical-articles/introducing-the-first-amd-1b-language-model.html).
43
+
44
+ ## Usage
45
+
46
+ ### PyTorch on AMD GPUs
47
+ For running pytorch on AMD GPUs you can use the following rocm docker as in [docker hub](https://hub.docker.com/r/rocm/pytorch)
48
+
49
+ ```bash
50
+ docker pull rocm/pytorch:latest
51
+ # Inside docker
52
+ pip install transformers
53
+ ```
54
+
55
+ ### Use Example
56
+
57
+ ```python
58
+ from transformers import AutoModelForCausalLM, AutoTokenizer
59
+
60
+ model = AutoModelForCausalLM.from_pretrained("amd/AMD-OLMo-1B-SFT").to("cuda") # remove .to("cuda") to load on cpu
61
+ tokenizer = AutoTokenizer.from_pretrained("amd/AMD-OLMo-1B-SFT")
62
+
63
+ prompt = "What is large language model?"
64
+ bos = tokenizer.eos_token
65
+ template = bos + "<|user|>\n{prompt}\n<|assistant|>\n"
66
+
67
+ input_text = template.format(prompt=prompt)
68
+ inputs = tokenizer([input_text], return_tensors='pt', return_token_type_ids=False).to("cuda")
69
+ outputs = model.generate(**inputs, max_new_tokens=1000, do_sample=True, top_k=50, top_p=0.95)
70
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
71
+ ```
72
+
73
+
74
+ ## Main Results
75
+
76
+ ### Pretraining Results
77
+
78
+ | **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) |
79
+ |---------------------:|:-----------------:|:-----------:|:-----------:|:---------------:|:---------------:|:-----------:|
80
+ | **arc_easy** | 55.47 | 56.65 | 57.28 | 55.43 | 56.65 | **63.64** |
81
+ | **arc_challenge** | 32.68 | 32.00 | 31.06 | 32.34 | 32.34 | **33.70** |
82
+ | **hellaswag** | 61.47 | 61.80 | 62.92 | 64.81 | **66.12** | 63.61 |
83
+ | **piqa** | 73.56 | 75.30 | 75.14 | **75.57** | 75.08 | **75.57** |
84
+ | **boolq** | 55.99 | 60.83 | 61.74 | 63.58 | **66.18** | 60.58 |
85
+ | **sciq** | 89.30 | 88.20 | 87.00 | 90.60 | 92.70 | **93.20** |
86
+ | **winogrande** | 59.43 | 59.27 | 59.98 | **61.72** | **61.72** | 61.64 |
87
+ | **openbookqa** | **36.80** | 35.40 | 36.20 | 36.20 | 35.60 | 35.80 |
88
+ | **mmlu (0-shot)** | 25.02 | 24.81 | 24.23 | 25.26 | **25.45** | 24.88 |
89
+ | **gsm8k (8-shot)** | 1.82 | 0.00 | 2.50 | 2.81 | **8.95** | 2.88 |
90
+ | **bbh (3-shot)** | **25.63** | 0.00 | **25.63** | 16.77 | 21.67 | 20.95 |
91
+ | **Average** | 47.02 | 44.93 | 47.61 | 47.73 | **49.31** | 48.77 |
92
+
93
+
94
+ ### Instruction Tuning Results
95
+
96
+ | **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)|
97
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
98
+ | **arc_easy** | 54.42 | 57.41 | 52.44 | 63.68 | **64.31** |
99
+ | **arc_challenge** | 32.85 | 34.56 | **37.80** | 37.12 | 37.37 |
100
+ | **hellaswag** | 60.40 | 62.51 | **71.29** | 61.63 | 61.91 |
101
+ | **piqa** | 74.48 | **75.73** | 75.03 | 74.43 | 74.16 |
102
+ | **boolq** | 61.04 | 55.66 | **70.28** | 68.53 | 70.24 |
103
+ | **sciq** | 88.40 | 87.10 | 89.50 | 91.20 | **92.10** |
104
+ | **winogrande** | 60.54 | 60.77 | **62.19** | 60.22 | 60.62 |
105
+ | **openbookqa** | 37.20 | 36.80 | 39.20 | 37.40 | **40.20** |
106
+ | **mmlu** | 24.61 | 25.25 | 25.54 | 29.97 | **30.52** |
107
+ | **gsm8k (8-shot)**| 2.81 | 0.23 | 1.82 | **18.20** | 15.77 |
108
+ | **bbh (3-shot)** | **26.83** | 0.00 | 13.40 | 25.17 | 25.45 |
109
+ | **Average** | 47.60 | 45.09 | 48.95 | 51.60 | **52.06** |
110
+
111
+ |**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)|
112
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
113
+ | **AlpacaEval 1 (Win Rate)** | 50.81 | 34.90 | 37.72 | 50.12 | **54.22** |
114
+ | **AlpacaEval 2 (LC Win Rate)**| 1.54 | 1.59 | 0.49 | **3.88** | 2.37 |
115
+ | **MTBench** | 3.38 | 2.89 | - | **4.35** | 4.10 |
116
+
117
+ |**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)|
118
+ |------------------:|:---------:|:---------:|:---------:|:---------:|:---------:|
119
+ | **ToxiGen** | 41.70 | **37.23** | 42.34 | 39.04 | 39.68 |
120
+ | **crows_pairs** | 60.35 | 58.50 | 59.93 | 60.29 | **61.00** |
121
+ | **TruthfulQA-mc2**| 37.92 | 38.46 | **45.84** | 37.45 | 40.06 |
122
+
123
+ *In generating tokens for chat benchmark evaluations, we use `max_length=2048` for AlpacaEval and `max_new_tokens=2048` for MTBench.
124
+
125
+ *All numbers in above tables were obtained from our evaluations.
126
+
127
+
128
+ ## Evaluation
129
+ We use the following open source evaluation frameworks for evaluating our models:
130
+ - [Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness): For evaluating on commonsense reasoning, multi-task understanding & responsible AI benchmarks
131
+ - [AlpacaEval](https://github.com/tatsu-lab/alpaca_eval): For evaluating instruction-following capabilities of chat models.
132
+ - [MT-Bench](https://github.com/lm-sys/FastChat/tree/main/fastchat/llm_judge): For evaluating multi-turn capabilities of chat models.
133
+
134
+ ### Setup
135
+ ```bash
136
+ # lm-eval-harness
137
+ git clone https://github.com/EleutherAI/lm-evaluation-harness
138
+ cd lm-evaluation-harness
139
+ pip install -e .
140
+
141
+ # AlpacaEval
142
+ pip install git+https://github.com/tatsu-lab/alpaca_eval
143
+ cd alpaca_eval
144
+ pip install -e .
145
+
146
+ # MT-Bench
147
+ git clone https://github.com/lm-sys/FastChat.git
148
+ cd FastChat
149
+ pip install -e ".[model_worker,llm_judge]"
150
+ ```
151
+
152
+ ### Run evaluation
153
+ ```bash
154
+ # lm-eval-harness
155
+ HF_MODEL=amd/AMD-OLMo-1B-SFT-DPO
156
+ accelerate launch -m lm_eval --model hf \
157
+ --model_args pretrained=$HF_MODEL,trust_remote_code=True \
158
+ --tasks arc_easy,arc_challenge,hellaswag,piqa,boolq,sciq,winogrande,openbookqa,mmlu,gsm8k_cot,bbh_cot_fewshot,toxigen,truthfulqa,crows_pairs \
159
+ --device cuda \
160
+ --batch_size 32 \
161
+ --output_path ./lm-eval-results/$HF_MODEL
162
+ ```
163
+
164
+ ## Training
165
+
166
+ ### Setup
167
+ ```bash
168
+ WORK_DIR="<path_to_your_working_directory>"
169
+ cd $WORK_DIR
170
+ # Clone OLMo codebase:
171
+ git clone https://github.com/allenai/OLMo.git --branch v0.3.0
172
+ cd OLMo
173
+ # Clone AMD-OLMo that contains files to reproduce our model training
174
+ git clone https://huggingface.co/amd/AMD-OLMo
175
+
176
+ docker pull rocm/pytorch:latest
177
+ 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
178
+
179
+ # Remove Line 17 as the docker already has ROCm PyTorch installed
180
+ sed -i '17d' pyproject.toml
181
+ pip install -e .[all]
182
+ ```
183
+
184
+ ### Download and prepare pretraining datasets
185
+ ```bash
186
+ # Download
187
+ DATA_DIR=./datasets/dolma
188
+ mkdir -p $DATA_DIR
189
+
190
+ PARALLEL_DOWNLOADS="<number_of_parallel_downloads>"
191
+ cat "AMD-OLMo/dolma_v1_7_subset.txt" | xargs -n 1 -P $PARALLEL_DOWNLOADS wget -q -P $DATA_DIR
192
+
193
+ # Prepare
194
+ NUM_WORKERS="<number_of_workers>"
195
+ python scripts/prepare_memmap_dataset.py $DATA_DIR/*.json.gz -o $DATA_DIR/memmap_dataset --workers $NUM_WORKERS
196
+ ```
197
+
198
+ ### Download and prepare SFT datasets
199
+ ```bash
200
+ # 1st phase SFT dataset
201
+ python AMD-OLMo/prepare_sft_data.py --output_dir ./datasets/tulu --tokenizer tokenizers/allenai_eleuther-ai-gpt-neox-20b-pii-special.json --dataset tulu
202
+
203
+ # 2nd phase SFT dataset
204
+ 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
205
+ ```
206
+
207
+ ### Run Training
208
+ Pretrainig config: [AMD-OLMo-1B.yaml](AMD-OLMo-1B.yaml)
209
+
210
+ 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)
211
+ ```bash
212
+ # Single node
213
+ 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
214
+
215
+ # Multiple nodes
216
+ 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
217
+ ```
218
+
219
+ ### Run DPO Training
220
+
221
+ DPO recipe: [AMD-OLMo-1B-dpo.yaml](AMD-OLMo-1B-dpo.yaml).
222
+ ```bash
223
+ # install trl library
224
+ git clone https://github.com/huggingface/trl.git -b v0.8.6
225
+
226
+ # replace dpo_trainer.py
227
+ cp AMD-OLMo/dpo_trainer.py trl/trl/trainer
228
+
229
+ pip install -e ./trl
230
+
231
+ # install alignment-handbook
232
+ git clone https://github.com/huggingface/alignment-handbook.git hf-align
233
+ # 70769f9 is the main branch on 2024-04-11.
234
+ cd hf-align && git checkout 70769f9 && cd ..
235
+
236
+ pip install -e ./hf-align
237
+
238
+ # Copy AMD OLMo DPO recipe to hf-align/recipes.
239
+ cp AMD-OLMo/AMD-OLMo-1B-dpo.yaml hf-align/recipes/
240
+
241
+ # Prepare the converted AMD-OLMo SFT Huggingface model to ckpt_dir.
242
+ ckpt_dir=amd/AMD-OLMo-1B-SFT
243
+ local_tokenizer_dir=${ckpt_dir}
244
+
245
+ # Set output checkpoint dir.
246
+ dpo_ckpt_dir=<your_output_checkpoint_dir>
247
+
248
+ accelerate launch --config_file hf-align/recipes/accelerate_configs/deepspeed_zero3.yaml \
249
+ hf-align/scripts/run_dpo.py hf-align/recipes/AMD-OLMo-1B-dpo.yaml \
250
+ --trust_remote_code=true \
251
+ --model_name_or_path=${ckpt_dir} \
252
+ --tokenizer_name_or_path=${local_tokenizer_dir} \
253
+ --output_dir=${dpo_ckpt_dir} \
254
+ --num_train_epochs=1 \
255
+ --learning_rate=4e-6 \
256
+ --beta=0.3 \
257
+ --loss_type=sigmoid
258
+ ```
259
+
260
+ ## Bias, Risks, and Limitations
261
+
262
+ - 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.
263
+ - 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.
264
+ - 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.
265
+ - Multi-lingual abilities of the models have not been tested and thus may misunderstand and generate erroneous responses across different languages.
266
+
267
+ ## Appendix
268
+ ### Evaluation Metrics
269
+ | **Benchmark** | Metric |
270
+ |---------------------:|:-----------------:|
271
+ | **arc_easy** | Normalized Accuracy |
272
+ | **arc_challenge** | Normalized Accuracy |
273
+ | **hellaswag** | Normalized Accuracy |
274
+ | **piqa** | Accuracy |
275
+ | **boolq** | Accuracy |
276
+ | **sciq** | Accuracy |
277
+ | **winogrande** | Accuracy |
278
+ | **openbookqa** | Normalized Accuracy |
279
+ | **mmlu** | Accuracy |
280
+ | **gsm8k (8-shot)** | Exact Match (Flexible Extract) |
281
+ | **bbh (3-shot)** | Exact Match |
282
+ | **ToxiGen** | Accuracy |
283
+ | **crows_pairs** | PCT Stereotype |
284
+ | **TruthfulQA-mc2** | Accuracy |
285
+ | **AlpacaEval 1 (Win Rate)** | Win Rate (chatgpt_fn) |
286
+ | **AlpacaEval 2 (LC Win Rate)** | Length Control Win Rate (weighted_alpaca_eval_gpt4_turbo) |
287
+ | **MTBench** | Average score for single-answer grading (2 turns) |
288
+
289
+ Feel free to cite our AMD-OLMo models:
290
+ ```bash
291
+ @misc{AMD-OLMo,
292
+ title = {AMD-OLMo: A series of 1B language models trained from scratch by AMD on AMD Instinct™ MI250 GPUs.},
293
+ url = {https://huggingface.co/amd/AMD-OLMo},
294
+ author = {Jiang Liu, Jialian Wu, Prakamya Mishra, Zicheng Liu, Sudhanshu Ranjan, Pratik Prabhanjan Brahma, Yusheng Su, Gowtham Ramesh, Peng Sun, Zhe Li, Dong Li, Lu Tian, Emad Barsoum},
295
+ month = {October},
296
+ year = {2024}
297
+ }
298
+ ```
299
+
300
+ #### License
301
+ Copyright (c) 2018-2024 Advanced Micro Devices, Inc. All Rights Reserved.
302
+
303
+ Licensed under the Apache License, Version 2.0 (the "License");
304
+ you may not use this file except in compliance with the License.
305
+ You may obtain a copy of the License at
306
+
307
+ http://www.apache.org/licenses/LICENSE-2.0
308
+
309
+ Unless required by applicable law or agreed to in writing, software
310
+ distributed under the License is distributed on an "AS IS" BASIS,
311
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
312
+ See the License for the specific language governing permissions and
313
+ limitations under the License.