declarative programming (static graph), dirname, main_program=None, filename=None)[source]

This operator saves all persistable variables from main_program to the folder dirname or file filename. You can refer to Save and Load a Model for more details. And then saves these persistables variables to the folder dirname or file filename.

The dirname is used to specify the folder where persistable variables are going to be saved. If you would like to save variables in separate files, set filename None; if you would like to save all variables in a single file, use filename to specify the file name.

  • executor (Executor) – The executor to run for saving persistable variables. You can refer to Executor for more details.

  • dirname (str, optional) – The saving directory path. When you need to save the parameter to the memory, set it to None.

  • main_program (Program, optional) – The program whose persistbale variables will be saved. You can refer to Basic Concept for more details. If it is None, the default main program will be used. Default: None.

  • filename (str, optional) – The file to save all variables. If you prefer to save variables in different files, set it to None. Default: None.


When saving parameters to a file, returns None.

When saving parameters to memory, returns a binary string containing parameters.

Return type



import paddle.fluid as fluid

dir_path = "./my_paddle_model"
file_name = "persistables"
image ='img', shape=[None, 28, 28], dtype='float32')
label ='label', shape=[None, 1], dtype='int64')
feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace())

predict = fluid.layers.fc(input=image, size=10, act='softmax')
loss = fluid.layers.cross_entropy(input=predict, label=label)
avg_loss = fluid.layers.mean(loss)
exe = fluid.Executor(fluid.CPUPlace()), dirname=dir_path, filename=file_name)
# The persistables variables weights and bias in the fc layer of the network
# are going to be saved in the same file named "persistables" in the path
# "./my_paddle_model"