enable FP16Optimizer for fp16 deepspeed training.#547
Conversation
|
@JingyaHuang can you please approve the workflows? |
|
The documentation is not available anymore as the PR was closed or merged. |
|
Hi @AdamLouly, Thanks for the PR! Just to have a further understanding of the fp16 optimizer wrapper, it works both for DeepSpeed and Apex right? In Transformers, while using Apex as backend for mixed precision, the optimizer is wrapped in the function optimum/optimum/onnxruntime/trainer.py Line 1488 in eff4c2b will it make sense also to wrap this? And under the hood, what does the wrapper optimize? Is it compatible regardless of the optimizer used? |
Yes I think we have to wrap the apex one as well, thanks for pointing it out, to answer your question:
|
JingyaHuang
left a comment
There was a problem hiding this comment.
Thanks @AdamLouly , let's remove the exceptions, and then we can merge it!
Co-authored-by: Jingya HUANG <[email protected]>
Co-authored-by: Jingya HUANG <[email protected]>
|
Updated the perf results on the description using roberta-large |
|
@JingyaHuang formatter trainer.py |
|
@JingyaHuang do you use black for lint? that's what I used and it still fails, thoughts? |
@AdamLouly, yes we use black and isort. You can use directly ‘make style’ for formatting. |
make style reformat other files that I have not change as well. |
|
@AdamLouly, |
JingyaHuang
left a comment
There was a problem hiding this comment.
LGTM, thanks for iterating, will merge it once the CI pass! @AdamLouly
What does this PR do?
This PR enables FP16 Optimizer when fp16 training is enabled.
Benchmark validation.
This is the logs from both runs with and without fp16 training flag.
The recipe that I ran on this test:
"optimum/examples/onnxruntime/training/text-classification/run_glue.py"
command used to run the recipe:
python -m torch.distributed.launch --nproc_per_node=4 /home/adamlouly/optimum/examples/onnxruntime/training/text-classification/run_glue.py --model_name_or_path roberta-large --task_name MRPC --max_seq_length 128 --learning_rate 3e-6 --do_train --output_dir /dev/optim_al --overwrite_output_dir --max_steps 200 --logging_steps 20 --per_device_train_batch_size 64 --fp16 --deepspeed /home/adamlouly/optimum/aml_ds_config_zero_1.jsonconfig json file:
{ "fp16": { "enabled": true, "loss_scale": 0, "loss_scale_window": 1000, "hysteresis": 2, "min_loss_scale": 1 }, "zero_optimization": { "stage": 1, "allgather_partitions": true, "allgather_bucket_size": 200000000, "overlap_comm": true, "reduce_scatter": true, "reduce_bucket_size": 200000000, "contiguous_gradients": false, "cpu_offload": false }, "zero_allow_untested_optimizer": true, "optimizer": { "type": "AdamW", "params": { "lr": "auto", "betas": "auto", "eps": "auto", "weight_decay": "auto" } }, "scheduler": { "type": "WarmupLR", "params": { "warmup_min_lr": "auto", "warmup_max_lr": "auto", "warmup_num_steps": "auto" } }, "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "gradient_accumulation_steps": "auto", "wall_clock_breakdown": false }