|
| 1 | +# Benchmarks for DeepCompile |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +This experiment scripts require 4 nodes that has 8 A100/H100 GPUs each. |
| 6 | +We tested the scripts with Python 3.10.12 and CUDA 12.4. |
| 7 | + |
| 8 | +### Libraries |
| 9 | + |
| 10 | +In addition, you need to install the following: |
| 11 | + |
| 12 | +- PyTorch v2.6.0 |
| 13 | +- DeepSpeed (v0.16.6 or newer) |
| 14 | +- transformers |
| 15 | +- accelerate |
| 16 | +- datasets v3.1 |
| 17 | + |
| 18 | +Here are an example of installation commands: |
| 19 | + |
| 20 | +```bash |
| 21 | +pip3 install torch==2.6.0 torchvision torchaudio |
| 22 | +pip3 install transformers datasets==3.1 accelerate |
| 23 | + |
| 24 | +# Install DeepSpeed |
| 25 | +pip install deepspeed |
| 26 | + |
| 27 | +# Clone this repository |
| 28 | +git clone https://github.com/deepspeedai/DeepSpeedExamples |
| 29 | +cd benchmarks/deepcompile |
| 30 | +``` |
| 31 | + |
| 32 | +You need to set up these on all nodes. |
| 33 | + |
| 34 | +### Setup for multiple nodes run |
| 35 | + |
| 36 | +You need to set host names in `hostfile_n${NUM_NODES}`. The file should look like the following: |
| 37 | + |
| 38 | +``` |
| 39 | +node-0 slots=8 |
| 40 | +node-1 slots=8 |
| 41 | +node-2 slots=8 |
| 42 | +node-3 slots=8 |
| 43 | +``` |
| 44 | + |
| 45 | +## Evaluation on throughput |
| 46 | + |
| 47 | +The following script runs the throughput benchmark. This sweeps the following conditions: |
| 48 | + |
| 49 | +- Models: meta-llama/Meta-Llama-3-70B-Instruct, mistralai/Mixtral-8x7B-v0.1 |
| 50 | +- Batch size: 1, 2, 4 |
| 51 | +- Sequence length: 512 1024 2048 |
| 52 | +- Frameworks and settings: |
| 53 | + - DeepSpeed ZeRO3 (ZeRO3) |
| 54 | + - DeepSpeed ZeRO3 +Compiler (ZeRO3 (C)) |
| 55 | + - FSDP (FSDP) |
| 56 | + - FSDP + Compiler (FSDP (C)) |
| 57 | + - DeepCompile + proactive prefetching (DeepCompile (P)) |
| 58 | + - DeepCompile + selective unsharding (DeepCompile (S)) |
| 59 | + - DeepCompile + proactive prefetching + selective unsharding (DeepCompile (P+S)) |
| 60 | + |
| 61 | +The script downloads the models from HuggingFace Model Hub. Please make sure that you have access to the models. |
| 62 | + |
| 63 | +```bash |
| 64 | +export PROFILE_DIR=/path/to/profile |
| 65 | +bash run_bench.sh |
| 66 | +``` |
| 67 | + |
| 68 | +The logs resulting from our experiments are stored in `logs/` directory. The summary of results is output to `profiles/result.txt`. You can copy the file to `results/acc_step_1` and plot the throughput with the following commands. |
| 69 | + |
| 70 | +```bash |
| 71 | +python plot.py --result_dir results/acc_step_1 --metric throughput |
| 72 | +``` |
| 73 | + |
| 74 | +Here are some example charts: |
| 75 | + |
| 76 | +<table> |
| 77 | + <tr> |
| 78 | + <td><img src="results/acc_step_1/throughput/chart_throughput_Llama-3-70B_np32_bs1.png" alt="Llama-3-70B/bs=1" width="300"></td> |
| 79 | + <td><img src="results/acc_step_1/throughput/chart_throughput_Mixtral-8x7B_np32_bs1.png" alt="Mixtral-8x7B/bs=1" width="300"></td> |
| 80 | + </tr> |
| 81 | +</table> |
| 82 | + |
| 83 | +The following script runs the benchmark with different number of gradient accumulation steps (2, 4, 8, 16). |
| 84 | + |
| 85 | +The batch size and sequence length are fixed to 1 and 1024, respectively. (Note that FSDP doesn't work for this experiment) |
| 86 | + |
| 87 | +```bash |
| 88 | +bash run_bench_acc.sh |
| 89 | +``` |
| 90 | + |
| 91 | +You can use the same script with `--acc_step_eval` to plot the results along gradient accumulation steps. |
| 92 | + |
| 93 | +```bash |
| 94 | +ython plot.py --result_dir results/acc_step_1_16 --acc_step_eval --metric throughput |
| 95 | +``` |
| 96 | + |
| 97 | +Here are some example charts: |
| 98 | + |
| 99 | +<table> |
| 100 | + <tr> |
| 101 | + <td><img src="results/acc_step_1_16/throughput/chart_throughput_Llama-3-70B_np32_bs1.png" alt="Llama-3-70B/bs=1" width="300"></td> |
| 102 | + <td><img src="results/acc_step_1_16/throughput/chart_throughput_Mixtral-8x7B_np32_bs1.png" alt="Mixtral-8x7B/bs=1" width="300"></td> |
| 103 | + </tr> |
| 104 | +</table> |
| 105 | + |
| 106 | +## APIs and custom optimization passes |
| 107 | + |
| 108 | +To enable DeepCompile, simply set "deepcompile": true in the compile section of your DeepSpeed configuration JSON: |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | +… |
| 113 | + "zero_optimization": { |
| 114 | + "stage": 3, |
| 115 | + }, |
| 116 | + "compile": { |
| 117 | + "deepcompile": true, |
| 118 | + }, |
| 119 | +… |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +In your training script, call the compile() API to invoke DeepCompile. The function signature is: |
| 124 | + |
| 125 | +```python |
| 126 | +def compile(self, backend=get_accelerator().get_compile_backend(), compile_kwargs={}, schedule=None) -> None: |
| 127 | +``` |
| 128 | + |
| 129 | +You can pass a custom optimization schedule using the schedule argument. For example, to apply ZeRO-3-style partitioning and the optimizations described above, you can define the schedule as follows: |
| 130 | + |
| 131 | +```python |
| 132 | +schedule = [] |
| 133 | +schedule.append((0, [zero3_compile.add_z3_gather_release])) |
| 134 | +schedule.append( |
| 135 | + (WARMUP, |
| 136 | + [zero3_compile.add_z3_gather_release, prefetch.schedule_prefetch, selective_gather.selective_gather])) |
| 137 | +``` |
| 138 | + |
| 139 | +A schedule is defined as a list of tuples, where each tuple consists of: |
| 140 | + |
| 141 | +- A step index (e.g., 0 or "WARMUP"), indicating when to apply the passes |
| 142 | +- A list of optimization functions to apply at that step |
| 143 | + |
| 144 | +In the example above, `add_z3_gather_release` is applied at step 0 to minimize memory usage. After a warmup phase (e.g., after the first few training iterations), additional optimizations such as prefetching and selective unsharding are applied based on profiled memory usage. |
| 145 | +Each optimization pass takes a standardized set of arguments provided by DeepCompile. For details, please refer to the implementation of each pass: |
| 146 | + |
| 147 | +- [ZeRO3 (All-gather and reduce-scatter insertion)](https://github.com/deepspeedai/DeepSpeed/blob/tohtana/deepcompile/deepspeed/compile/passes/zero3_compile.py) |
| 148 | +- [Proactive prefetching](https://github.com/deepspeedai/DeepSpeed/blob/tohtana/deepcompile/deepspeed/compile/passes/prefetch.py) |
| 149 | +- [Selective unsharding](https://github.com/deepspeedai/DeepSpeed/blob/tohtana/deepcompile/deepspeed/compile/passes/selective_gather.py) |
| 150 | +- [Reduce-scatter insertion (ZeRO1)](https://github.com/deepspeedai/DeepSpeed/blob/tohtana/deepcompile/deepspeed/compile/passes/zero1_compile.py) |
| 151 | +- [Adaptive offloading](https://github.com/deepspeedai/DeepSpeed/blob/tohtana/deepcompile/deepspeed/compile/passes/offload_adam_states.py) |
0 commit comments