normalize_program

paddle.static. normalize_program ( program, feed_vars, fetch_vars, **kwargs ) [source]

Normalize/Optimize a program according to feed_vars and fetch_vars.

Parameters
  • program (Program) – Specify a program you want to optimize.

  • feed_vars (Tensor | list[Tensor]) – Variables needed by inference.

  • fetch_vars (Tensor | list[Tensor]) – Variables returned by inference.

  • kwargs – Supported keys including skip_prune_program. - skip_prune_program(bool): whether to skip pruning program. Defaults to False.

Returns

Normalized/Optimized program.

Return type

Program

Examples

>>> import paddle

>>> paddle.enable_static()

>>> path_prefix = "./infer_model"

# User defined network, here a softmax regression example
>>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32')
>>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
>>> predict = paddle.static.nn.fc(image, 10, activation='softmax')

>>> loss = paddle.nn.functional.cross_entropy(predict, label)

>>> exe = paddle.static.Executor(paddle.CPUPlace())
>>> exe.run(paddle.static.default_startup_program())

# normalize main program.
>>> program = paddle.static.default_main_program()
>>> normalized_program = paddle.static.normalize_program(program, [image], [predict])