serialize_persistables serialize_persistables ( feed_vars, fetch_vars, executor, **kwargs ) [source]

Static Graph

Serialize parameters using given executor and default main program according to feed_vars and fetch_vars.

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

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

  • kwargs – Supported keys including ‘program’.Attention please, kwargs is used for backward compatibility mainly. - program(Program): specify a program if you don’t want to use default main program.


serialized program.

Return type


  • ValueError – If feed_vars is not a Variable or a list of Variable, an exception is thrown.

  • ValueError – If fetch_vars is not a Variable or a list of Variable, an exception is thrown.


import paddle


path_prefix = "./infer_model"

# User defined network, here a softmax regession example
image ='img', shape=[None, 28, 28], dtype='float32')
label ='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())

# serialize parameters to bytes.
serialized_params = paddle.static.serialize_persistables([image], [predict], exe)

# deserialize bytes to parameters.
main_program = paddle.static.default_main_program()
deserialized_params = paddle.static.deserialize_persistables(main_program, serialized_params, exe)