-
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
Add async update design doc #9932
Merged
Yancey1989
merged 5 commits into
PaddlePaddle:develop
from
Yancey1989:async_update_design
Apr 17, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Design Doc: Asynchronous Update With Distributed Training | ||
|
||
## Background | ||
|
||
For the typical synchronous distributed training, some significant steps are as follows: | ||
|
||
1. A Trainer will compute the gradients and SEND them to the Parameter Server(PServer) nodes. | ||
1. After the PServer node received gradients came from all the Trainers, It will aggregate the | ||
gradient variables for the same parameter into one gradient variable and then apply the aggregated | ||
gradient to the respective parameter, finally using an optimize algorithms(SGD, Monument...) | ||
to update the parameters. | ||
1. The Trainer would wait for the PServers finished the optimize stage, and GET the parameters from PServer, | ||
so all the Trainers would get the same parameters. | ||
|
||
In the synchronously distributed training, there should be a `Barrier` to synchronise the | ||
parameters after the optimizing stage. The performance of a distributed training job would | ||
depend on the slowest node if there were hundreds or thousands of training nodes in a | ||
Job, the performance of synchronously distributed training might be very poor because of | ||
the slow node. So this design doc would introduce an approach to implement | ||
*asynchronously* distributed training in PaddlePaddle Fluid. | ||
|
||
## Design | ||
|
||
<img src="./src/async_update.png" width="600"/> | ||
|
||
As the figure above, we describe a global view of asynchronously update process and use | ||
the parameter `w1` as an example to introduce the steps: | ||
1. For each gradient variables, they may distribute on different GPU card and aggregate | ||
them while they are all calculated. | ||
1. Split the gradient variable into multiple blocks according to the number of PServer | ||
instances and then send them. | ||
1. PServer would run an `Optimize Block` using a specified optimize algorithm to update | ||
the specified parameter. | ||
1. The trainer will fetch latest parameter from PServer before running forward Op which depends | ||
on the specified parameter. | ||
1. Broadcast the received variable into multiple GPU cards and continue to run the next | ||
mini-batch. | ||
|
||
### Trainer | ||
|
||
- For the multiple devices distributed training, we need to aggregate the gradient | ||
variables which placed on different devices firstly and then schedule a `SendVars` Operator to | ||
send the gradient variables to the multiple PServer instances. | ||
- Schedule `FetchVars` operator to fetch the latest parameter from PServer before running | ||
the forward ops. | ||
- There could be a large number of gradient variables to be sent, so we need to use another | ||
thread pool(IO Threadpool) whose a number of the schedulable threads is larger than the | ||
computing thread pool to avoid competitive the thread resources with computing. | ||
|
||
### Parameter Server | ||
|
||
<img src="./src/async_pserver.png" width="750"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "No Pserver" -> "On Pserver" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
- There should be multiple trainer instances want to optimize the same parameter at | ||
the same time, to avoid the racing, we need one `BlockingQueue` for each gradient | ||
variable to process them one by one. | ||
- We need a `Map` structure to map a gradient variable name to the `OptimizeBlock` which | ||
can optimize the respective parameter. |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
I think we do not need an aggregation stage and can just read a variable from the queue and update it to the parameter.
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.
Yes, you're right, don't aggregation the received gradients, will update it.
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.
Done.