Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training with Deepspeed ZeRO-3 #97

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ python -m ochat.data.generate_dataset --model-type MODEL_TYPE --model-path BASE_
You can now launch the OpenChat trainer using the command below.
- 13B model requires eight `A/H100s` with 80GB VRAM
- 7B model can be trained with four `A/H100s` with 80GB VRAM or eight `A/H100s` with 40GB VRAM.
- [NEW] With Deepspeed ZeRO-3, 7B model can be trained with eight `A10G` with 24GB VRAM.

For hyperparameters, we recommend first setting the batch size to the recommended batch size. If OOM occurs, try setting it to the exact maximum that VRAM can hold and as a multiple of `2048`.
Other hyperparameters have been carefully selected as the default. Furthermore, the learning rate is automatically determined based on the [inverse square-root rule](https://arxiv.org/abs/2006.09092).
Expand All @@ -347,6 +348,26 @@ deepspeed --num_gpus=$NUM_GPUS --module ochat.training_deepspeed.train \

</details>

<details>

<summary>Training Commands with Deepspeed ZeRO-3 (click to expand)</summary>

```bash
NUM_GPUS=8

deepspeed --num_gpus=$NUM_GPUS --module ochat.training_deepspeed.train_zero3 \
--model_path BASE_REPO \
--data_prefix PRETOKENIZED_DATA_OUTPUT_PATH \
--save_path PATH_TO_SAVE_MODEL \
--batch_max_len BATCH_SIZE \
--epochs 5 \
--save_every 1 \
--deepspeed \
--deepspeed_config ochat/training_deepspeed/deepspeed_config_zero3.json
```

</details>

You can find checkpoints of all epochs in `PATH_TO_SAVE_MODEL`. Then you may evaluate each epoch and choose the best one.

# Limitations
Expand Down
23 changes: 23 additions & 0 deletions ochat/training_deepspeed/deepspeed_config_zero3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"bf16": {
"enabled": true
},

"zero_optimization": {
"stage": 3,
"offload_param": {
"device": "cpu"
},
"offload_optimizer": {
"device": "cpu"
},
"stage3_gather_fp16_weights_on_model_save": true
},

"gradient_clipping": 1.0,
"gradient_accumulation_steps": 8,
"train_micro_batch_size_per_gpu": 1,

"steps_per_print": 100,
"wall_clock_breakdown": false
}
Loading