@@ -261,45 +261,42 @@ def _as_lodtensor(data, place):
261
261
262
262
class Executor (object ):
263
263
"""
264
- An Executor in Python, only support the single-GPU running. For multi-cards, please refer to
265
- ParallelExecutor.
266
- Python executor takes a program, add feed operators and fetch operators to this program according
264
+ An Executor in Python, supports single/multiple-GPU running, and single/multiple-CPU running.
265
+ Python executor takes a program, adds feed operators and fetch operators to this program according
267
266
to feed map and fetch_list. Feed map provides input data for the program. fetch_list provides
268
- the variables(or names) that user want to get after program run . Note: the executor will run all
267
+ the variables(or names) that user wants to get after program runs . Note: the executor will run all
269
268
operators in the program but not only the operators dependent by the fetch_list.
270
- It store the global variables into the global scope, and create a local scope for the temporary
271
- variables. The local scope contents will be discarded after every minibatch forward/backward finished.
272
- But the global scope variables will be persistent through different runs.
273
- All of ops in program will be running in sequence.
269
+ It stores the global variables into the global scope, and creates a local scope for the temporary
270
+ variables. The contents in local scope may be discarded after every minibatch forward/backward
271
+ finished. But the global scope variables will be persistent through different runs.
274
272
275
273
276
274
Example:
277
- .. code-block:: python
278
- # First create the Executor.
279
- place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
280
- exe = fluid.Executor(place)
281
-
282
- # Run the startup program once and only once.
283
- # Not need to optimize/compile the startup program.
284
- exe.run(fluid.default_startup_program())
285
-
286
- # Run the main program directly without compile.
287
- loss, = exe.run(fluid.default_main_program(),
288
- feed=feed_dict,
289
- fetch_list=[loss.name])
290
- # Or, compiled the program and run. See `CompiledProgram` for more detail.
291
- compiled_prog = compiler.CompiledProgram(
292
- fluid.default_main_program()).with_data_parallel(
293
- loss_name=loss.name)
294
- loss, = exe.run(compiled_prog,
295
- feed=feed_dict,
296
- fetch_list=[loss.name])
275
+
276
+ .. code-block:: python
277
+
278
+ # First create the Executor.
279
+ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
280
+ exe = fluid.Executor(place)
281
+
282
+ # Run the startup program once and only once.
283
+ # Not need to optimize/compile the startup program.
284
+ exe.run(fluid.default_startup_program())
285
+
286
+ # Run the main program directly without compile.
287
+ loss, = exe.run(fluid.default_main_program(),
288
+ feed=feed_dict,
289
+ fetch_list=[loss.name])
290
+ # Or, compiled the program and run. See `CompiledProgram` for more detail.
291
+ compiled_prog = compiler.CompiledProgram(
292
+ fluid.default_main_program()).with_data_parallel(
293
+ loss_name=loss.name)
294
+ loss, = exe.run(compiled_prog,
295
+ feed=feed_dict,
296
+ fetch_list=[loss.name])
297
297
298
298
Args:
299
299
place(core.CPUPlace|core.CUDAPlace(n)): indicate the executor run on which device
300
-
301
- Note: For debugging complicated network in parallel-GPUs, you can test it on the executor.
302
- They has the exactly same arguments, and expected the same results.
303
300
"""
304
301
305
302
def __init__ (self , place ):
@@ -382,16 +379,19 @@ def _fetch_data(self, fetch_list, fetch_var_name, scope):
382
379
]
383
380
return outs
384
381
382
+ '''
383
+ TODO(typhoonzero): Define "no longer use" meaning? Can user create
384
+ a new Executor for the same program and run?
385
+ TODO(panyx0718): Why ParallelExecutor doesn't have close?
386
+ '''
387
+
385
388
def close (self ):
386
389
"""
387
390
Close this executor.
388
391
389
392
You can no longer use this executor after calling this method.
390
393
For the distributed training, this method would free the resource on PServers related to
391
394
the current Trainer.
392
- TODO(typhoonzero): Define "no longer use" meaning? Can user create
393
- a new Executor for the same program and run?
394
- TODO(panyx0718): Why ParallelExecutor doesn't have close?
395
395
396
396
Example:
397
397
>>> cpu = core.CPUPlace()
0 commit comments