|
| 1 | +# Pretraining LLaMA-1/2/3: best practices for building LLaMA-1/2/3-like base models |
| 2 | +### LLaMA3 |
| 3 | +<p align="center"> |
| 4 | +<img src="https://raw.githubusercontent.com/hpcaitech/public_assets/main/examples/images/LLaMA3-70B-H100.png" width=600/> |
| 5 | +</p> |
| 6 | + |
| 7 | +- 70 billion parameter LLaMA3 model training accelerated by 18% |
| 8 | + |
| 9 | +### LLaMA2 |
| 10 | +<p align="center"> |
| 11 | +<img src="https://raw.githubusercontent.com/hpcaitech/public_assets/main/colossalai/img/llama2_pretraining.png" width=600/> |
| 12 | +</p> |
| 13 | + |
| 14 | +- 70 billion parameter LLaMA2 model training accelerated by 195% |
| 15 | +[[blog]](https://www.hpc-ai.tech/blog/70b-llama2-training) |
| 16 | + |
| 17 | +### LLaMA1 |
| 18 | +<p align="center"> |
| 19 | +<img src="https://raw.githubusercontent.com/hpcaitech/public_assets/main/examples/images/LLaMA_pretraining.png" width=600/> |
| 20 | +</p> |
| 21 | + |
| 22 | +- 65-billion-parameter large model pretraining accelerated by 38% |
| 23 | +[[blog]](https://www.hpc-ai.tech/blog/large-model-pretraining) |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +> ⚠ This example only has benchmarking script. For training/finetuning, please refer to the [applications/Colossal-LLaMA](https://github.com/hpcaitech/ColossalAI/tree/main/applications/Colossal-LLaMA). |
| 28 | +
|
| 29 | +### 1. Installation |
| 30 | + |
| 31 | +Please install the latest ColossalAI from source. |
| 32 | + |
| 33 | +```bash |
| 34 | +BUILD_EXT=1 pip install -U git+https://github.com/hpcaitech/ColossalAI |
| 35 | +``` |
| 36 | + |
| 37 | +Then install other dependencies. |
| 38 | + |
| 39 | +```bash |
| 40 | +pip install -r requirements.txt |
| 41 | +``` |
| 42 | + |
| 43 | +### 4. Shell Script Examples |
| 44 | + |
| 45 | +For your convenience, we provide some shell scripts to run benchmark with various configurations. |
| 46 | + |
| 47 | +You can find them in `scripts/benchmark_7B` and `scripts/benchmark_70B` directory. The main command should be in the format of: |
| 48 | +```bash |
| 49 | +colossalai run --nproc_per_node YOUR_GPU_PER_NODE --hostfile YOUR_HOST_FILE \ |
| 50 | +benchmark.py --OTHER_CONFIGURATIONS |
| 51 | +``` |
| 52 | +Here we will show an example of how to run training |
| 53 | +llama pretraining with `gemini, batch_size=16, sequence_length=4096, gradient_checkpoint=True, flash_attn=True`. |
| 54 | + |
| 55 | +#### a. Running environment |
| 56 | +This experiment was performed on 4 computing nodes with 32 A800/H800 80GB GPUs in total for LLaMA-1 65B or LLaMA-2 70B. The nodes are |
| 57 | +connected with RDMA and GPUs within one node are fully connected with NVLink. |
| 58 | + |
| 59 | +#### b. Running command |
| 60 | + |
| 61 | +```bash |
| 62 | +cd scripts/benchmark_7B |
| 63 | +``` |
| 64 | + |
| 65 | +First, put your host file (`hosts.txt`) in this directory with your real host ip or host name. |
| 66 | + |
| 67 | +Here is a sample `hosts.txt`: |
| 68 | +```text |
| 69 | +hostname1 |
| 70 | +hostname2 |
| 71 | +hostname3 |
| 72 | +hostname4 |
| 73 | +``` |
| 74 | + |
| 75 | +Then add environment variables to script if needed. |
| 76 | + |
| 77 | +Finally, run the following command to start training: |
| 78 | + |
| 79 | +```bash |
| 80 | +bash gemini.sh |
| 81 | +``` |
| 82 | + |
| 83 | +If you encounter out-of-memory(OOM) error during training with script `gemini.sh`, changing to script `gemini_auto.sh` might be a solution, since gemini_auto will set a upper limit on GPU memory usage through offloading part of the model parameters and optimizer states back to CPU memory. But there's a trade-off: `gemini_auto.sh` will be a bit slower, since more data are transmitted between CPU and GPU. |
| 84 | + |
| 85 | +#### c. Results |
| 86 | +If you run the above command successfully, you will get the following results: |
| 87 | +`max memory usage: 55491.10 MB, throughput: 24.26 samples/s, TFLOPS/GPU: 167.43`. |
| 88 | + |
| 89 | + |
| 90 | +## Reference |
| 91 | +``` |
| 92 | +@article{bian2021colossal, |
| 93 | + title={Colossal-AI: A Unified Deep Learning System For Large-Scale Parallel Training}, |
| 94 | + author={Bian, Zhengda and Liu, Hongxin and Wang, Boxiang and Huang, Haichen and Li, Yongbin and Wang, Chuanrui and Cui, Fan and You, Yang}, |
| 95 | + journal={arXiv preprint arXiv:2110.14883}, |
| 96 | + year={2021} |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +```bibtex |
| 101 | +@software{openlm2023openllama, |
| 102 | + author = {Geng, Xinyang and Liu, Hao}, |
| 103 | + title = {OpenLLaMA: An Open Reproduction of LLaMA}, |
| 104 | + month = May, |
| 105 | + year = 2023, |
| 106 | + url = {https://github.com/openlm-research/open_llama} |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +```bibtex |
| 111 | +@software{together2023redpajama, |
| 112 | + author = {Together Computer}, |
| 113 | + title = {RedPajama-Data: An Open Source Recipe to Reproduce LLaMA training dataset}, |
| 114 | + month = April, |
| 115 | + year = 2023, |
| 116 | + url = {https://github.com/togethercomputer/RedPajama-Data} |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +```bibtex |
| 121 | +@article{touvron2023llama, |
| 122 | + title={Llama: Open and efficient foundation language models}, |
| 123 | + author={Touvron, Hugo and Lavril, Thibaut and Izacard, Gautier and Martinet, Xavier and Lachaux, Marie-Anne and Lacroix, Timoth{\'e}e and Rozi{\`e}re, Baptiste and Goyal, Naman and Hambro, Eric and Azhar, Faisal and others}, |
| 124 | + journal={arXiv preprint arXiv:2302.13971}, |
| 125 | + year={2023} |
| 126 | +} |
| 127 | +``` |
0 commit comments