CompiledProgram

class paddle.static. CompiledProgram ( program_or_graph, build_strategy=None ) [source]
Api_attr

Static Graph

The CompiledProgram is used to transform a program or graph for various optimizations according to the configuration of build_strategy, for example, the operators’ fusion in the computation graph, memory optimization during the execution of the computation graph, etc. For more information about build_strategy, please refer to paddle.static.BuildStrategy.

Parameters
  • program_or_graph (Graph|Program) – This argument is the Program or Graph being executed.

  • build_strategy (BuildStrategy) – This argument is used to compile the program or graph with the specified options, such as operators’ fusion in the computational graph and memory optimization during the execution of the computational graph. For more information about build_strategy, please refer to paddle.static.BuildStrategy. The default is None.

Returns

CompiledProgram

Example

>>> import numpy
>>> import paddle
>>> import paddle.static as static

>>> paddle.enable_static()

>>> place = paddle.CPUPlace()
>>> exe = static.Executor(place)

>>> data = static.data(name='X', shape=[None, 1], dtype='float32')
>>> hidden = static.nn.fc(x=data, size=10)
>>> loss = paddle.mean(hidden)
>>> paddle.optimizer.SGD(learning_rate=0.01).minimize(loss)

>>> exe.run(static.default_startup_program())
>>> compiled_prog = static.CompiledProgram(
...     static.default_main_program())

>>> x = numpy.random.random(size=(10, 1)).astype('float32')
>>> loss_data, = exe.run(compiled_prog,
...                     feed={"X": x},
...                     fetch_list=[loss.name])