The api_fluid_CompiledProgram is used to transform a program for various optimizations. For example, you can use with_data_parallel to transform the program to data parallel program so that it can be run in multiple devices.

# Note:
#   - If you want to specify the GPU cards which are used to run
#     in ParallelExecutor, you should define the CUDA_VISIBLE_DEVICES
#     in environment.
#   - If you want to use multi CPU to run the program in ParallelExecutor,
#     you should define the CPU_NUM in the environment.

# First create the Executor.
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)

# Run the startup program once and only once.

# Run the main program directly without compile.
loss =,

# Or, compiled the program, and then run the model with data parallel.
exec_strategy = fluid.ExecutionStrategy()
exec_strategy.num_threads = dev_count * 4 # the size of thread pool.
build_strategy = fluid.BuildStrategy()
build_strategy.memory_optimize = True if memory_opt else False

compiled_prog = compiler.CompiledProgram(

loss, =,

Note: fluid.Porgram and compiler.CompiledPorgram are completely different Programs. fluid.Porgram is composed of a series of operators. compiler.CompiledPorgram compiles the fluid.Porgram and converts it into a computational graph. compiler.CompiledPorgram cannot be saved at present.

  • Related API :

System Message: WARNING/2 (/FluidDoc/docs/api_guides/low_level/compiled_program_en.rst, line 51)

Bullet list ends without a blank line; unexpected unindent.

  • api_fluid_CompiledProgram