@@ -234,8 +234,56 @@ def __exit__(self, exc_type, exc_val, exc_tb):
234
234
235
235
class ParallelDo (object ):
236
236
"""
237
- ParallelDo class is used to create a ParallelDo.
238
- It will be soon deprecated, please use ParallelExecutor instead.
237
+ ParallelDo is used to represent multi-thread data parallel processing.
238
+
239
+ Its vanilla implementation can be shown as the following (:math:`|` means
240
+ single thread and :math:`||||` means multiple threads)
241
+
242
+ .. code-block:: text
243
+
244
+ In the forward pass
245
+ | Split input onto different devices
246
+ | Copy parameter onto different devices
247
+ |||| Compute forward pass in parallel
248
+ | Merge output from different devices
249
+
250
+ In the backward pass
251
+ | Split output@grad onto different devices
252
+ |||| Compute backward pass in parallel
253
+ | accumulate param@grad from different devices to the first device
254
+ | Merge input@grad from different devices
255
+ | Copy param@grad to the place of parallel_do_op
256
+
257
+ Examples:
258
+
259
+ .. code-block:: python
260
+
261
+ images = fluid.layers.data(name='pixel', shape=[1, 28, 28], dtype=DTYPE)
262
+ label = fluid.layers.data(name='label', shape=[1], dtype='int64')
263
+
264
+ # ParallelDo version & Single-thread version
265
+ if thread_num > 1:
266
+ places = fluid.layers.get_places(thread_num)
267
+ pd = fluid.layers.ParallelDo(places)
268
+ with pd.do():
269
+ images = pd.read_input(images)
270
+ label = pd.read_input(label)
271
+ predict = cnn_model(images)
272
+ cost = fluid.layers.cross_entropy(input=predict, label=label)
273
+
274
+ avg_cost = fluid.layers.mean(x=cost)
275
+ pd.write_output(avg_cost)
276
+
277
+ avg_cost = pd()
278
+ avg_cost = fluid.layers.mean(avg_cost)
279
+ else:
280
+ predict = cnn_model(images)
281
+ cost = fluid.layers.cross_entropy(input=predict, label=label)
282
+ avg_cost = fluid.layers.mean(x=cost)
283
+
284
+ .. warning::
285
+
286
+ It will be soon deprecated, please use ParallelExecutor instead.
239
287
"""
240
288
241
289
def __init__ (self , places , use_nccl = False , name = None ):
0 commit comments