You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PaddlePaddle v0.10.0 uses the "trainer-parameter server"
6
-
architecture. We run multiple replicated instances of trainers (runs
7
-
the same code written by the user) and parameter servers for
8
-
distributed training. This architecture served us well, but has some
9
-
limitations:
5
+
PaddlePaddle version 0.10.0 uses the "trainer-parameter server" architecture. We run multiple instances of trainers (where each trainer runs the same model) and parameter servers for distributed training. This architecture serves well, but has few limitations:
10
6
11
-
1. Need to write special code to handle tasks which should only be run
12
-
by a single trainer. E.g., initializing model and saving model.
7
+
1. There is a need to write special code that handles tasks which should only be run on a single trainer. E.g., initializing the model, saving the model etc.
13
8
14
-
2. Model parallelism is hard: need to write if-else branches conditioned
15
-
on the trainer ID to partition model onto each trainer, and manually
16
-
write the inter-model-shard communication code.
9
+
2. Model parallelism is hard: It would need all the if-else branches conditioned on the trainer ID to partition the model onto the trainers, and eventually manually writing out the inter-model-shard communication code to communicate between different trainers.
17
10
18
-
3. The user can not directly specify the parameter update rule: need
19
-
to modify the parameter server C++ code and compile a new
20
-
binary. This adds complication for researchers: A lot of extra
21
-
effort is required. Besides, the training job submission program
22
-
may not allow running arbitrary binaries.
11
+
3. The user can not directly specify the parameter update rule: This would need to modify the parameter server code and compile a new binary. This makes things more complicated for researchers: A lot of extra effort is required to make this work. Besides, the training job submission program may not allow running arbitrary binaries.
23
12
24
-
This design doc discusses PaddlePaddle's new distributed training
25
-
architecture that addresses the above limitations.
13
+
This design doc discusses PaddlePaddle's new distributed training architecture that addresses the above mentioned limitations.
26
14
27
15
## Analysis
28
16
29
-
We will assume the user writes the trainer program by Python, the same
30
-
analysis holds if the trainer program is written in C++.
17
+
The assumption is that the user writes the trainer program in either Python or C++.
31
18
32
19
### Limitation 1
33
20
34
-
If we look at the Python code that the user writes, there are two
35
-
kinds of functionalities:
21
+
There are two basic functionalities in the trainer program:
36
22
37
-
- The training logic such as load / save model and print log.
38
-
- The neural network definition such as the definition of the data
39
-
layer, the fully connected layer, the cost function and the
23
+
1. The training logic such as loading / saving the model and printing out the logs.
24
+
2. The neural network definition such as the definition of the data layer, the fully connected layer, the cost function and the
40
25
optimizer.
41
26
42
-
When we training with PaddlePaddle v0.10.0 distributedly, multiple
43
-
replicated Python instances are running on different nodes: both the
44
-
training logic and the neural network computation is replicated.
27
+
When we train using PaddlePaddle v0.10.0 in a distributed fashion, multiple instances of the same Python code are run on different nodes, hence both: the
28
+
training logic as well as the neural network computation logic, is replicated.
45
29
46
-
The tasks that should only run once all belong to the training logic,
47
-
if we only replicate the neural network computation, but do **not**
48
-
replicate the training logic, the limitation could be solved.
30
+
The tasks that only need to be run once belong to the training logic. Hence if we only replicate the neural network computation part, and do **not**
31
+
replicate the training logic, the limitation mentioned above can be avoided.
49
32
50
33
### Limitation 2
51
34
52
-
Model parallelism means running a single model on multiple nodes by
53
-
partitioning the model onto different nodes and managing the
54
-
inter-model-shard communications.
35
+
Model parallelism means that a single model is partitioned into different components and each node runs one of the component separately. This comes at the extra cost of managing the
36
+
inter-model-shard communication between nodes.
55
37
56
-
PaddlePaddle should be able to modify the nerual network computation
57
-
definition to support model parallelism automatically. However, the
58
-
computation is only specified in Python code, and PaddlePaddle can not
59
-
modify Python code.
38
+
PaddlePaddle should ideally be able to modify the neural network computation and figure out the support for model parallelism automatically. However, the
39
+
computation is only specified in Python code which sits outside of PaddlePaddle, hence PaddlePaddle can not support the feature in this setup.
60
40
61
-
Just like compiler uses a intermediate representation (IR) so that
62
-
programmer does not need to manually optimize their code in most of
63
-
the cases - the compiler will optimize the IR:
41
+
Similar to how a compiler uses an intermediate representation (IR) so that the programmer does not need to manually optimize their code for most of the cases, we can have an intermediate representation in PaddlePaddle as well. The compiler optimizes the IR as follows:
64
42
65
43
<imgsrc="src/compiler.png"/>
66
44
67
-
We can have our own IR too: PaddlePaddle can support model parallel by
68
-
converting the IR so the user no longer need to manually do it in
69
-
Python:
45
+
PaddlePaddle can support model parallelism by converting the IR so that the user no longer needs to manually perform the computation and operations in the Python component:
70
46
71
47
<imgsrc="src/paddle-compile.png"/>
72
48
73
-
The IR for PaddlePaddle after refactor is called `Block`, it specifies
74
-
the computation dependency graph and the variables used in the
75
-
computation.
49
+
The IR for PaddlePaddle after refactoring is called a `Block`, it specifies the computation dependency graph and the variables used in the computation.
76
50
77
51
### Limitation 3
78
52
79
-
The user can not directly specify the parameter update rule for the
80
-
parameter server because the parameter server does not use the same
81
-
computation definition as the trainer. Instead, the update rule is
82
-
baked in the parameter server. The user can not specify the update
83
-
rule in the same way of specifying the trainer computation.
53
+
The user can not directly specify the parameter update rule for the parameter server in the Python module, since the parameter server does not use the same computation definition as the trainer. Instead, the update rule is baked inside the parameter server. The user can not specify the update rule explicitly.
84
54
85
-
This could be fixed by making the parameter server run the same
86
-
computation definition as the trainer. For a detailed explanation,
87
-
please
88
-
see
55
+
This could be fixed by making the parameter server run the same computation definition as the trainer (the user's Python module). For a detailed explanation, refer to this document -
89
56
[Design Doc: Operation Graph Based Parameter Server](./dist_train.md)
90
57
91
58
## Distributed Training Architecture
92
59
93
-
The new distributed training architecture can address the above
94
-
limitations. Below is the illustration:
60
+
The revamped distributed training architecture can address the above discussed limitations. Below is the illustration of how it does so:
95
61
96
62
<imgsrc="src/distributed_architecture.png"/>
97
63
98
-
The architecture includes major components: *PaddlePaddle Python*,
99
-
*PaddlePaddle converter* and *PaddlePaddle runtime*:
64
+
The major components in the architecture are: *PaddlePaddle Python*, *PaddlePaddle converter* and *PaddlePaddle runtime*.
100
65
101
66
### PaddlePaddle Python
102
67
103
-
PaddlePaddle Python is the Python library that user's Python trainer
104
-
invoke to build the neural network topology, start training, etc.
68
+
PaddlePaddle Python is the Python library that user's Python code invokes, to read the data. build the neural network topology, start training, etc.
105
69
106
70
```Python
107
71
paddle.init()
@@ -117,102 +81,60 @@ for i in range(1000):
117
81
print cost_val
118
82
```
119
83
120
-
The code above is a typical Python trainer code, the neural network
121
-
topology is built using helper functions such as
122
-
`paddle.layer.fc`. The training is done by calling `session.eval`
123
-
iteratively.
84
+
The above code is what a typical Python trainer code is, the neural network topology is built using the helper functions such as `paddle.layer.fc`. Training is done by calling `session.eval` iteratively.
124
85
125
86
#### session.eval
126
87
127
-
As shown in the graph, `session.eval` sends the IR and the evaluation
128
-
inputs/targets to the PaddlePaddle cluster for evaluation. The
129
-
targets can be any variable in the computation graph. When the target
130
-
is the `optimizer` variable, the neural network will be optimized
131
-
once. When the target is the `cost` variable, `session.eval` returns
132
-
the cost value.
88
+
As shown in the graph, `session.eval` sends the IR and the evaluation inputs or targets to the PaddlePaddle cluster for evaluation.
89
+
The targets can be any variable in the computation graph. When the target is say, the `optimizer` variable, the neural network will be optimized once. When the target is the `cost` variable, `session.eval` returns the cost value. Based on what the target is, an appropriate action is taken.
133
90
134
-
The Python `session` is a wrapper of the C++ `Session` class. For more
135
-
information about `Session`, please
136
-
see [Design Doc: Session](./session.md).
91
+
The Python `session` is a wrapper of the C++ `Session` class. For more information about `Session`, refer to this document - [Design Doc: Session](./session.md).
137
92
138
93
### PaddlePaddle Converter
139
94
140
-
PaddlePaddle converter automatically converts the IR in the request
141
-
(IR and evaluation inputs/targets) from PaddlePaddle Python to new
142
-
partitioned IRs and dispatch the new IRs and evaluation inputs/targets
143
-
to different PaddlePaddle runtimes. Below are the steps:
95
+
The PaddlePaddle converter automatically converts the IR in the request (IR and evaluation inputs/targets) from PaddlePaddle Python to partitioned IRs and dispatches the new IRs and evaluation inputs/targets to different PaddlePaddle runtimes. Below are the steps that are followed :
144
96
145
-
1. Add `feed` OP that feeds the eval inputs, and `fetch` OP that
146
-
fetches the eval targets to the IR.
97
+
1. Add a `feed` OP that feeds the eval inputs, and a `fetch` OP that fetches the eval targets to the IR.
147
98
148
-
1. Extract a new computation (sub)graph with `feed` and `fetch` OP as
149
-
the boundary. The runtime does not need to run the OP that is not
150
-
dependent by the `fetch` OP.
99
+
2. Extract a new computation (sub)graph with the `feed` and `fetch` OPs as the boundary. The runtime does not need to run the OP that is not dependent on the `fetch` OP.
151
100
152
-
1. Optimizes the computation graph.
101
+
3. Optimize the computation graph.
153
102
154
-
1. Place the OPs in the graph onto different devices on different
155
-
PaddlePaddle runtime according to a placement algorithm and device
156
-
constraint specified by the user.
103
+
4. Place the OPs in the graph onto different devices on different PaddlePaddle runtime according to a placement algorithm and the device constraints specified by the user.
157
104
158
-
1. Partition the graph according to runtime boundaries and add `send` /
159
-
`recv` OP pair on the runtime boundaries.
105
+
5. Partition the graph according to runtime boundaries and add `send` / `recv` OP pair on the runtime boundaries.
160
106
161
-
1. Dispatch the partitioned graph to different PaddlePaddle runtimes.
107
+
6. Dispatch the partitioned graph to different PaddlePaddle runtimes.
108
+
109
+
7. PaddlePaddle runtimes with the `fetch` OP reports evaluation results back to the converter, the converter reports the evaluation results back to the PaddlePaddle Python.
162
110
163
-
1. PaddlePaddle runtimes with the `fetch` OP reports evaluation
164
-
results back to the converter, the convert reports the evaluation
165
-
results back to the PaddlePaddle Python.
166
-
167
111
The output IRs will be cached to optimize the conversion latency.
168
112
169
113
170
114
#### Placement Algorithm
171
115
172
-
Our first implementation will only support "trainer-parameter server"
173
-
placement: the parameters, initializers, and optimizers are placed on
174
-
the PaddlePaddle runtimes with the parameter server role. And
175
-
everything else will be placed on the PaddlePaddle runtimes with the
176
-
trainer role. This has the same functionality of our
177
-
"trainer-parameter server" architecture of PaddlePaddle v0.10.0, but
178
-
is more general and flexible.
116
+
Our first implementation will only support "trainer-parameter server" placement: the parameters, initializers, and optimizers are all placed on the PaddlePaddle runtimes with the parameter server role. Everything else will be placed on the PaddlePaddle runtimes with the trainer role. This has the same functionality as the "trainer-parameter server" architecture of PaddlePaddle v0.10.0, but is more generic and flexible.
179
117
180
-
In the future, we will implement the general placement algorithm,
181
-
which makes placements according to the input IR, and a model of
182
-
device computation time and device communication time. Model
183
-
parallelism requires the general placement algorithm.
118
+
In the future, a more general placement algorithm should be implemented, which makes placements according to the input IR, and a model of device computation time and device communication time. Model parallelism requires the generic placement algorithm.
184
119
185
120
186
121
### PaddlePaddle Runtime
187
122
188
-
The PaddlePaddle runtime owns multiple devices (e.g., CPUs, GPUs) and
189
-
runs the IR. The runtime does not need to do OP placement since it's
190
-
already done by the converter.
123
+
The PaddlePaddle runtime owns multiple devices (e.g., CPUs, GPUs) and runs the IR. The runtime does not need to do OP placement since it is already done by the converter.
191
124
192
125
193
126
### Local Training Architecture
194
127
195
-
The local training architecture will be the same as the distributed
196
-
training architecture, the differences are everything runs locally,
197
-
and there is just one PaddlePaddle runtime:
128
+
The local training architecture will be the same as the distributed training architecture, the difference is that everything runs locally, and there is just one PaddlePaddle runtime:
198
129
199
130
<imgsrc="src/local_architecture.png"/>
200
131
201
132
202
133
### Training Data
203
134
204
-
In PaddlePaddle v0.10.0, training data is typically read
205
-
with [data reader](../reader/README.md) from Python. This approach is
206
-
no longer efficient when training distributedly since the Python
207
-
process no longer runs on the same node with the trainer processes,
208
-
the Python reader will need to read from the distributed filesystem
209
-
(assuming it has the access) and send to the trainers, doubling the
210
-
network traffic.
211
-
212
-
When doing distributed training, the user can still use Python data
213
-
reader: the training data are sent with `session.eval`. However should
214
-
be used for debugging purpose only. The users are encouraged to use
215
-
the read data OPs.
135
+
In PaddlePaddle v0.10.0, training data is typically read with a [data reader](../reader/README.md) from Python. This approach is no longer efficient when training in a distributed fashion since the Python process no longer runs on the same node with the trainer processes. The Python reader will need to read from the distributed filesystem (assuming it has the required access) and send to the trainers, doubling the network traffic.
136
+
137
+
When doing distributed training, the user can still use Python data reader: the training data are sent with `session.eval`. However this should be used for debugging purpose only. The users are encouraged to use the read data OPs.
0 commit comments