-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
… split_byref_op
- Loading branch information
Showing
63 changed files
with
2,075 additions
and
100 deletions.
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 |
---|---|---|
|
@@ -179,6 +179,7 @@ set(EXTERNAL_LIBS | |
|
||
if(WITH_GPU) | ||
include(cuda) | ||
include(tensorrt) | ||
endif(WITH_GPU) | ||
|
||
if(WITH_AMD_GPU) | ||
|
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
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
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
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
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,33 @@ | ||
if(NOT WITH_GPU) | ||
return() | ||
endif() | ||
|
||
set(TENSORRT_ROOT "/usr" CACHE PATH "TENSORRT ROOT") | ||
find_path(TENSORRT_INCLUDE_DIR NvInfer.h | ||
PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/include | ||
$ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/include | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
find_library(TENSORRT_LIBRARY NAMES libnvinfer.so libnvinfer.a | ||
PATHS ${TENSORRT_ROOT} ${TENSORRT_ROOT}/lib | ||
$ENV{TENSORRT_ROOT} $ENV{TENSORRT_ROOT}/lib | ||
NO_DEFAULT_PATH | ||
DOC "Path to TensorRT library.") | ||
|
||
if(TENSORRT_INCLUDE_DIR AND TENSORRT_LIBRARY) | ||
set(TENSORRT_FOUND ON) | ||
else() | ||
set(TENSORRT_FOUND OFF) | ||
endif() | ||
|
||
if(TENSORRT_FOUND) | ||
file(READ ${TENSORRT_INCLUDE_DIR}/NvInfer.h TENSORRT_VERSION_FILE_CONTENTS) | ||
string(REGEX MATCH "define NV_TENSORRT_MAJOR +([0-9]+)" TENSORRT_MAJOR_VERSION | ||
"${TENSORRT_VERSION_FILE_CONTENTS}") | ||
string(REGEX REPLACE "define NV_TENSORRT_MAJOR +([0-9]+)" "\\1" | ||
TENSORRT_MAJOR_VERSION "${TENSORRT_MAJOR_VERSION}") | ||
|
||
message(STATUS "Current TensorRT header is ${TENSORRT_INCLUDE_DIR}/NvInfer.h. " | ||
"Current TensorRT version is v${TENSORRT_MAJOR_VERSION}. ") | ||
endif() |
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
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
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
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,57 @@ | ||
## Distributed training overview doc | ||
|
||
Currently Paddle Fluid use parameter server architecture to support distributed training. | ||
|
||
For synchronous and asynchronous training, the differences are mostly in the logic of parameter server. Now we have already support synchronous training. | ||
|
||
### Synchronous training | ||
|
||
The training process of synchronous training is: | ||
|
||
![synchronous distributed training](./src/sync_distributed_training.png) | ||
|
||
1. Pserver | ||
1. set `barrier_condition_` to 0 and waits for trainers to send gradient. | ||
1. Trainer | ||
1. Trainer read minibatch of data, run forward-backward with local parameter copy and get the gradients for parameters. | ||
1. Trainer use split op to split all the gradient into blocks. The split method is determined at compile time. | ||
1. Trainer use send_op to send all the split gradients to corresponding parameter server. | ||
1. After trainer send all the gradients, it will send a `BATCH_BARRIER_MESSAGE` to all pservers. | ||
1. Trainer call GetVariable to pserver and wait for `barrier_condition_` on pserver to be 1. | ||
1. Pserver | ||
1. Pserver will count the number of `BATCH_BARRIER_MESSAGE`. | ||
1. When the count of `BATCH_BARRIER_MESSAGE` is equal to the number of Trainer. Pserver thinks it received all gradient from all trainers. | ||
1. Pserver will run the optimization block to optimize the parameters. | ||
1. After optimization, pserver set `barrier_condition_` to 1. | ||
1. Pserver wait for `FETCH_BARRIER_MESSAGE`. | ||
1. Trainer. | ||
1. The trainer uses GetVariable to get all the parameters from pserver. | ||
1. Trainer sends a `FETCH_BARRIER_MESSAGE` to each pserver. | ||
1. Pserver. | ||
1. when the number of `FETCH_BARRIER_MESSAGE` reach the number of all trainers. Pserver think all the parameters have been got. it will go back to 1. to set `barrier_condition_` to 0. | ||
|
||
### Asynchronous training | ||
In the above process. There are two barriers for all trainers to synchronize with each other. In asynchronous training, these two barriers are not needed. The trainer can just send gradients to pserver and then get parameters back. | ||
|
||
The training process of asynchronous training can be: | ||
|
||
![asynchronous distributed training](./src/async_distributed_training.png) | ||
|
||
1. Pserver: | ||
1. Each parameter has a queue to receive its gradient from trainers. | ||
1. Each parameter has a thread to read data from the queue and run optimize block, using the gradient to optimize the parameter. | ||
1. Using an independent thread to handle RPC call `GetVariable` for trainers to get parameters back.(Maybe here we should use a thread pool to speed up fetching the parameters.) | ||
|
||
1. Trainer: | ||
1. Trainer read a batch of data. Run forward and backward with local parameter copy and get the gradients for parameters. | ||
1. Trainer split all gradients to blocks and then send these gradient blocks to pservers(pserver will put them into the queue). | ||
2. Trainer gets all parameters back from pserver. | ||
|
||
### Note: | ||
There are also some conditions that need to consider. For exmaple: | ||
|
||
1. If trainer needs to wait for the pserver to apply it's gradient and then get back the parameters back. | ||
1. If we need a lock between parameter update and parameter fetch. | ||
1. If one parameter must be on one server, or it can also be split and send to multiple parameter servers. | ||
|
||
The above architecture of asynchronous training can support different mode, we can have a detailed test in the future for these problems. |
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 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. |
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.
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.
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
api_doc_std_cn.md | ||
new_op_cn.md | ||
new_op_kernel.md | ||
use_eigen_cn.md | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ Development | |
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
api_doc_std_en.md | ||
new_op_en.md | ||
new_op_kernel.md | ||
use_eigen_en.md | ||
|
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,53 @@ | ||
if(NOT DEFINED SPHINX_THEME) | ||
set(SPHINX_THEME default) | ||
endif() | ||
|
||
if(NOT DEFINED SPHINX_THEME_DIR) | ||
set(SPHINX_THEME_DIR) | ||
endif() | ||
|
||
# configured documentation tools and intermediate build results | ||
set(BINARY_BUILD_DIR_EN "${CMAKE_CURRENT_BINARY_DIR}/en/_build") | ||
|
||
# Sphinx cache with pickled ReST documents | ||
set(SPHINX_CACHE_DIR_EN "${CMAKE_CURRENT_BINARY_DIR}/en/_doctrees") | ||
|
||
# HTML output director | ||
set(SPHINX_HTML_DIR_EN "${CMAKE_CURRENT_BINARY_DIR}/en/html") | ||
|
||
configure_file( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../templates/conf.py.en.in" | ||
"${BINARY_BUILD_DIR_EN}/conf.py" | ||
@ONLY) | ||
|
||
sphinx_add_target(paddle_mobile_docs | ||
html | ||
${BINARY_BUILD_DIR_EN} | ||
${SPHINX_CACHE_DIR_EN} | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${SPHINX_HTML_DIR_EN}) | ||
|
||
add_dependencies(paddle_mobile_docs gen_proto_py paddle_python) | ||
|
||
# configured documentation tools and intermediate build results | ||
set(BINARY_BUILD_DIR_CN "${CMAKE_CURRENT_BINARY_DIR}/cn/_build") | ||
|
||
# Sphinx cache with pickled ReST documents | ||
set(SPHINX_CACHE_DIR_CN "${CMAKE_CURRENT_BINARY_DIR}/cn/_doctrees") | ||
|
||
# HTML output director | ||
set(SPHINX_HTML_DIR_CN "${CMAKE_CURRENT_BINARY_DIR}/cn/html") | ||
|
||
configure_file( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../templates/conf.py.cn.in" | ||
"${BINARY_BUILD_DIR_CN}/conf.py" | ||
@ONLY) | ||
|
||
sphinx_add_target(paddle_mobile_docs_cn | ||
html | ||
${BINARY_BUILD_DIR_CN} | ||
${SPHINX_CACHE_DIR_CN} | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${SPHINX_HTML_DIR_CN}) | ||
|
||
add_dependencies(paddle_mobile_docs_cn gen_proto_py paddle_python) |
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,9 @@ | ||
移动端 | ||
===== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
cross_compiling_for_android_cn.md | ||
cross_compiling_for_ios_cn.md | ||
cross_compiling_for_raspberry_cn.md |
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,9 @@ | ||
Mobile | ||
====== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
cross_compiling_for_android_en.md | ||
cross_compiling_for_ios_en.md | ||
cross_compiling_for_raspberry_en.md |
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
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
Oops, something went wrong.