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
@@ -52,77 +52,121 @@ The IR for PaddlePaddle after refactoring is called a `Block`, it specifies the
52
52
53
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.
54
54
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 -
56
-
[Design Doc: Operation Graph Based Parameter Server](./parameter_server.md)
55
+
This could be fixed by making the parameter server also run an IR, which can be different to the trainer side
56
+
For a detailed explanation, refer to this document -
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.
85
-
86
-
#### session.eval
87
-
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.
90
-
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).
92
-
93
-
### PaddlePaddle Converter
94
-
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 :
96
-
97
-
1. Add a `feed` OP that feeds the eval inputs, and a `fetch` OP that fetches the eval targets to the IR.
98
-
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.
100
-
101
-
3. Optimize the computation graph.
102
-
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.
104
-
105
-
5. Partition the graph according to runtime boundaries and add `send` / `recv` OP pair on the runtime boundaries.
96
+
The code above is a typical local training program, the "Training Program" is built using helper functions such as
97
+
`fluid.layer.fc`. The training is done by calling `Executor.run`
98
+
iteratively.
99
+
100
+
For more details, the implementation of IR is [Program](../program.md), and `ProgramDesc` is the protobuf type.
101
+
102
+
[Executor](../executor.md) simply runs the `ProgramDesc`. For local training you generally use
103
+
`Executor` to run the program locally. For any kind of distributed training, you can use
104
+
`RemoteExecutor` to specify desired distributed training method with some optional arguments.
105
+
106
+
### Distributed Transpiler
107
+
108
+
The Distributed Transpiler automatically converts the IR (in protobuf format) to partitioned IRs. Then
109
+
the Remote Executor dispatches the new IRs to Remote Executors across the cluster.
110
+
Below are the steps that are followed :
111
+
112
+
1. User only need to change `Executor` to `RemoteExecutor` to change local program to distributed program.
113
+
1.`RemoteExecutor` calls `Distributed Transpiler` to "transpile" user's program to several IRs representing a
114
+
distributed training program:
115
+
1. Parse configurations from `RemoteExecutor`.
116
+
1. Determine the type of distributed program, can be DataParallelism, ModelParallelism or Streaming.
117
+
1. Partition the `ProgramDesc` according to type and add `send` / `recv` OP pair on the boundaries. Take
118
+
DataParallelism type for example, it removes the optimization operators and add a `send` OP to the
119
+
"trainer" role, then add the optimization operators to the parameter server role within the `recv` OP.
120
+
1. Dispatch the partitioned graph to different `RemoteExecutor` in the cluster.
121
+
1.`RemoteExecutor` on each node run the received `ProgramDesc` utill the end.
122
+
123
+
124
+
### RemoteExecutor
125
+
126
+
As shown in the graph, `RemoteExecutor.run` sends the IR to the cluster for Execution.
127
+
You can also use parameter `fetch_list` to interactively fetch variable back to local for
128
+
log printing.
129
+
130
+
The Python `RemoteExecutor` is derived from `Executor` class.
131
+
132
+
```python
133
+
exe = RemoteExecutor(
134
+
feed=feeder.feed(data),
135
+
fetch_list=[avg_cost],
136
+
job_desc=JobDesc(
137
+
jobname,
138
+
num_trainer,
139
+
num_pserver,
140
+
cpu_per_trainer,
141
+
gpu_per_trainer,
142
+
mem_per_trainer,
143
+
cpu_per_pserver,
144
+
mem_per_pserver
145
+
))
146
+
for data in train_reader():
147
+
loss, acc = exe.run(trainer_prog,
148
+
feed=feeder.feed(data),
149
+
fetch_list=[avg_cost])
150
+
```
106
151
107
-
6. Dispatch the partitioned graph to different PaddlePaddle runtimes.
152
+
`JobDesc` object describe the distributed job resource specification to run on
153
+
Cluster environment.
108
154
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.
155
+
<imgsrc="src/remote_executor.png"/>
110
156
111
-
The output IRs will be cached to optimize the conversion latency.
to a server in the cluster which executes `RemoteExecutor.listen`. This server is responsible
160
+
to start the final Kubernetes Jobs to run the different role of `ProgramDesc`.
112
161
113
162
114
-
####Placement Algorithm
163
+
### Placement Algorithm
115
164
116
165
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.
117
166
118
167
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.
119
168
120
169
121
-
### PaddlePaddle Runtime
122
-
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.
124
-
125
-
126
170
### Local Training Architecture
127
171
128
172
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:
@@ -132,9 +176,18 @@ The local training architecture will be the same as the distributed training arc
132
176
133
177
### Training Data
134
178
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.
179
+
In PaddlePaddle v0.10.0, training data is typically read
180
+
with [data reader](../reader/README.md) from Python. This approach is
181
+
no longer efficient when training distributedly since the Python
182
+
process no longer runs on the same node with the trainer processes,
183
+
the Python reader will need to read from the distributed filesystem
184
+
(assuming it has the access) and send to the trainers, doubling the
185
+
network traffic.
186
+
187
+
When doing distributed training, the user can still use Python data
188
+
reader: the training data are sent with `Executor.run`. However, should
189
+
be used for debugging purpose only. The users are encouraged to use
0 commit comments