-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable SNIP on multiple cards using DeepSpeed ZeRO-3 (#1492)
Signed-off-by: yiliu30 <yi4.liu@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
061884d
commit 49ab28d
Showing
17 changed files
with
447 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
...p/huggingface_models/language-modeling/pruning/multi_cards/config/zero_stage3_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"train_batch_size": 64, | ||
"train_micro_batch_size_per_gpu": 8, | ||
"gradient_accumulation_steps": 4, | ||
"fp16": { | ||
"enabled": true, | ||
"min_loss_scale": 1, | ||
"opt_level": "O2" | ||
}, | ||
"zero_optimization": { | ||
"stage": 3, | ||
"allgather_partitions": true, | ||
"allgather_bucket_size": 5e8, | ||
"contiguous_gradients": true | ||
}, | ||
"optimizer": { | ||
"type": "AdamW", | ||
"params": { | ||
"lr": "auto", | ||
"torch_adam": true, | ||
"adam_w_mode": true | ||
} | ||
}, | ||
"scheduler": { | ||
"type": "WarmupDecayLR", | ||
"params": { | ||
"warmup_min_lr": 0.0, | ||
"warmup_max_lr": "auto", | ||
"warmup_num_steps": "auto", | ||
"total_num_steps": "auto", | ||
"warmup_type": "cosine" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
94 changes: 94 additions & 0 deletions
94
examples/pytorch/nlp/huggingface_models/language-modeling/pruning/multi_cards/run_ds_z3.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
function main { | ||
|
||
init_params "$@" | ||
run_pruning | ||
|
||
} | ||
|
||
# init params | ||
function init_params { | ||
dataset_name="NeelNanda/pile-10k" | ||
model_name_or_path="facebook/opt-125m" | ||
output_dir="./test-clm" | ||
per_device_train_batch_size=8 | ||
block_size=128 | ||
gradient_accumulation_steps=4 | ||
num_train_epochs=3 | ||
target_sparsity=0.8 | ||
pruning_type="snip_momentum" | ||
pruning_scope="local" | ||
pruning_pattern="4x1" | ||
pruning_frequency=1000 | ||
for var in "$@" | ||
do | ||
case $var in | ||
--dataset_name=*) | ||
dataset_name=$(echo $var |cut -f2 -d=) | ||
;; | ||
--model_name_or_path=*) | ||
model_name_or_path=$(echo $var |cut -f2 -d=) | ||
;; | ||
--output_dir=*) | ||
output_dir=$(echo $var |cut -f2 -d=) | ||
;; | ||
--per_device_train_batch_size=*) | ||
per_device_train_batch_size=$(echo $var |cut -f2 -d=) | ||
;; | ||
--block_size=*) | ||
block_size=$(echo $var |cut -f2 -d=) | ||
;; | ||
--gradient_accumulation_steps=*) | ||
gradient_accumulation_steps=$(echo $var |cut -f2 -d=) | ||
;; | ||
--num_train_epochs=*) | ||
num_train_epochs=$(echo $var |cut -f2 -d=) | ||
;; | ||
--target_sparsity=*) | ||
target_sparsity=$(echo $var |cut -f2 -d=) | ||
;; | ||
--pruning_type=*) | ||
pruning_type=$(echo $var |cut -f2 -d=) | ||
;; | ||
--pruning_scope=*) | ||
pruning_scope=$(echo $var |cut -f2 -d=) | ||
;; | ||
--pruning_pattern=*) | ||
pruning_pattern=$(echo $var |cut -f2 -d=) | ||
;; | ||
--pruning_frequency=*) | ||
pruning_frequency=$(echo $var |cut -f2 -d=) | ||
;; | ||
*) | ||
echo "Error: No such parameter: ${var}" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
} | ||
|
||
# run_tuning | ||
function run_pruning { | ||
accelerate launch --deepspeed_config_file config/ds_config.json --mixed_precision fp16 \ | ||
run_clm_no_trainer_deepspeed.py \ | ||
--dataset_name $dataset_name \ | ||
--model_name_or_path $model_name_or_path \ | ||
--block_size $block_size \ | ||
--per_device_train_batch_size $per_device_train_batch_size \ | ||
--gradient_accumulation_steps $gradient_accumulation_steps \ | ||
--output_dir $output_dir \ | ||
--do_prune \ | ||
--num_train_epochs $num_train_epochs \ | ||
--target_sparsity $target_sparsity \ | ||
--pruning_type $pruning_type \ | ||
--pruning_scope $pruning_scope \ | ||
--pruning_pattern $pruning_pattern \ | ||
--pruning_frequency $pruning_frequency | ||
|
||
} | ||
|
||
main "$@" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.