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

[sharding] Add arg of disabling sharding reduce_avg for accuracy verification #8168

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
15 changes: 15 additions & 0 deletions paddlenlp/trainer/training_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
enable_stage1_tensor_fusion, fuse small tensors into big tensor chunks to accelerate communications, may increase memory occupation
enable_stage1_overlap, fuse small tensors into big tensor chunks to accelerate communications and do communication overlap with backward computation, may harm the backward speed
enable_stage2_overlap, overlap stage2 NCCL communication with computation. There are some constraints for the overlap, such as the logging_step should be bigger than 1 for broadcast overlap and no other sync could be called during the training for broadcast overlap.
disable_stage1_reduce_avg, replace reduce_avg with original reduce_sum+scale in stage1, which can be used for accuracy verification.
recompute (`bool`, *optional*, defaults to `False`):
Recompute the forward pass to calculate gradients. Used for saving memory.
Only support for networks with transformer blocks.
Expand Down Expand Up @@ -626,6 +627,7 @@
"following config is support: \n"
"enable_stage1_tensor_fusion, fuse small tensors into big tensor chunks to accelerate communications, may increase memory occupation\n"
"enable_stage1_overlap, fuse small tensors into big tensor chunks to accelerate communications and do communication overlap with backward computation, may harm the backward speed\n"
"disable_stage1_reduce_avg, replace reduce_avg with original reduce_sum+scale in stage1, which can be used for accuracy verification.\n"
"enable_stage2_overlap, overlap stage2 NCCL communication with computation. There are some constraints for the overlap, such as the logging_step should be bigger than 1 for broadcast overlap and no other sync could be called during the training for broadcast overlap"
)
},
Expand Down Expand Up @@ -1036,6 +1038,7 @@
"In pipeline model, the evaluation also shares same setting with training. "
"We will enforce that per_device_eval_batch_size=per_device_train_batch_size * gradient_accumulation_steps."
)

self.per_device_eval_batch_size = (
self.per_device_train_batch_size * self.gradient_accumulation_steps
)
Expand Down Expand Up @@ -1136,11 +1139,23 @@
"enable_stage1_overlap",
"enable_stage2_overlap",
"split_param",
"disable_stage1_reduce_avg",
]:
raise ValueError(
f"Found unknown pipeline mode config {x}, "
f"accpet config is enable_stage1_tensor_fusion, enable_stage1_overlap, enable_stage2_overlap."
)
if "disable_stage1_reduce_avg" in sharding_parallel_config:
assert self.sharding == [

Check warning on line 1149 in paddlenlp/trainer/training_args.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/training_args.py#L1148-L1149

Added lines #L1148 - L1149 were not covered by tests
ShardingOption.SHARD_OP
], "Only sharding stage1 supports to disable reduce_avg strategy."
try:
strategy.hybrid_configs["sharding_configs"].use_reduce_avg = False
except:
warnings.warn(

Check warning on line 1155 in paddlenlp/trainer/training_args.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/training_args.py#L1152-L1155

Added lines #L1152 - L1155 were not covered by tests
"The reduce_avg strategy is not supported by current version of Paddle so you don't need to disable it. The nccl comm in sharding still use reduce_sum and scale of gradients."
)

try:
if "split_param" in sharding_parallel_config:
strategy.hybrid_configs["sharding_configs"].split_param = True
Expand Down
Loading