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

[hybrid enhance] add flag to control the avg position for grad merge under pipeline mode #36384

Merged
merged 13 commits into from
Oct 14, 2021

Conversation

FeixLiu
Copy link
Contributor

@FeixLiu FeixLiu commented Oct 13, 2021

PR types

New features

PR changes

Others

Describe

Support pure dp kind 'average for gradient merge after merging' operation for pp mode.
Add a new flag inside gradient_scale_configs: scale_gradient, which default value is False, to control where to do the average operation for gradient merge.
If gradient_scale_configs['scale_gradient'] = False, the pipeline will scale the loss@Grad (divide by number of micro steps) for each micro step, then do the gradient merge. It does the gradient merge avg op before sum.
Otherwise, if gradient_scale_configs['scale_gradient'] = True, the pipeline will do the gradient merge firstly. Then, during the optimize stage, the merged gradient will be divided by the number of micro steps. It does the gradient merge avg op after sum.

Hot to use:

strategy = paddle.distributed.fleet.DistributedStrategy()
strategy.gradient_scale_configs = {
    'scale_strategy': 'avg',
    'scale_gradient': True
}

Loss compared under fp16_allreduce
image

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@FeixLiu FeixLiu requested a review from wangxicoding October 13, 2021 02:49
@FeixLiu FeixLiu requested a review from wangxicoding October 13, 2021 07:13
@FeixLiu FeixLiu requested a review from wangxicoding October 13, 2021 09:27
Copy link
Contributor

@wangxicoding wangxicoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# the gradient to meet the logic for gradient merge under pure dp.
tmp_first_opt_idx = None
for idx, op in enumerate(main_block.ops):
if is_optimizer_op(op) and op.type != 'c_sync_comm_stream':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个插在c_sync_comm_stream前也没有关系

@wangxicoding wangxicoding merged commit 03d8304 into PaddlePaddle:develop Oct 14, 2021
@FeixLiu FeixLiu deleted the pp_grad_merge_more_option branch October 14, 2021 02:39
@sljlp sljlp mentioned this pull request Oct 16, 2021
FeixLiu added a commit to FeixLiu/Paddle that referenced this pull request Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants