-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Auto Parallel] Update Gradient Synchronization in Static Mode #59057
Merged
JZ-LIANG
merged 13 commits into
PaddlePaddle:develop
from
JZ-LIANG:semi-auto/unify-grad-sync
Dec 4, 2023
Merged
[Auto Parallel] Update Gradient Synchronization in Static Mode #59057
JZ-LIANG
merged 13 commits into
PaddlePaddle:develop
from
JZ-LIANG:semi-auto/unify-grad-sync
Dec 4, 2023
Conversation
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
Sorry to inform you that 9535157's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
wanghuancoder
approved these changes
Dec 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
heavyrain-lzy
approved these changes
Dec 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for SP
SigureMo
pushed a commit
to gouzil/Paddle
that referenced
this pull request
Dec 5, 2023
…ePaddle#59057) * completion bw partial * debug * bugfix * insert param grad allreduce by partial * reorder allreduce for opt * fix typoes * add grad sync unitest * sp unitest * fixed unitest
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Function optimization
PR changes
Others
Description
Pcard-76459
Many Frameworks handle the gradient synchronization using different mechnism: DDP, FSDP, Dtensor, Extra_sync_hook_for_sp , etc.
Before this PR, the gradient synchronization mechanism in AutoParallel static mode is problematic.
It only take into account the "Batch Dimension" (hard coded as the first dimension) of input tensor and uses a hard rule to conduct the synchronization:
If the "Batch" dimension of input activation is "sharded" on rank_groupA, the gradient of parameter need to be synchronized across rank_groupA in backward phase.
The above mechanism works OK when "Batch Dimension" is the only broadcast dimension that would be sharded (narrow-sense Data Parallel).
BUT it would fail for Sequence Parallel(SP)/Context Parallel(CP) and other more general cases of "Data Parallel" where other broadcast dimensions of input tensor are "sharded". The parameter gradient synchronization need in those cases would be missing, since the framework only considers the "batch" axis but ingores other "broadcast" axes.
This PR fixed the problem using "Partial --> Replicated" mechnism.
In any case, a broadcast dimension of input tensor is sharded, the gradient of parameter generated would be in Partial status, indicates that each value of that gradient is "partial" in term to the actual value in logic view.
And before the gradient is feed to optimizer, a Reshard operation (Allreduce) would be performed to convert the status gradient tensor from Partial to Replicated.
No synchronization would be missing.