set_program_state

paddle.static. set_program_state ( program, state_dict ) [source]

Set program parameter from state_dict

An exception will throw if shape or dtype of the parameters is not match.

NOTICE: This function MUST called after run start_up_program

Parameters
  • program (Program) – The program to be set

  • state_dict (dict) – the dict store Parameter and optimizer information

Returns

None

Examples

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

>>> paddle.enable_static()

>>> x = static.data(name="x", shape=[10, 10], dtype='float32')
>>> y = static.nn.fc(x, 10)
>>> z = static.nn.fc(y, 10)

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

>>> static.save(prog, "./temp")
>>> program_state = static.load_program_state("./temp")

>>> static.set_program_state(prog, program_state)