parameters: (program, model_path, protocol=4, **configs)
docstring: :api_attr: Static Graph
  
      This function save parameters, optimizer information and network description to model_path.
  
      The parameters contains all the trainable Tensor, will save to a file with suffix ".pdparams".
      The optimizer information contains all the Tensor used by optimizer. For Adam optimizer, contains beta1, beta2, momentum etc. All the information will save to a file with suffix ".pdopt". (If the optimizer have no Tensor need to save (like SGD), the fill will not generated).
      The network description is the description of the program. It's only used for deployment. The description  will save to a file with a suffix ".pdmodel".
  
      Args:
          program(Program) : The program to saved.
          model_path(str): the file prefix to save the program. The format is "dirname/file_prefix". If file_prefix is empty str. A exception will be raised
          protocol(int, optional): The protocol version of pickle module must be greater than 1 and less than 5.
                                   Default: 4
          configs(dict, optional) : optional keyword arguments.                        
  
      Returns:
          None
  
      Examples:
          .. code-block:: python
  
              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")
docstring_summary: :api_attr: Static Graph
docstring_tokens: : api_attr : Static Graph
function: def save(program, model_path, protocol=4, **configs):
      """
      :api_attr: Static Graph
  
      This function save parameters, optimizer information and network description to model_path.
  
      The parameters contains all the trainable Tensor, will save to a file with suffix ".pdparams".
      The optimizer information contains all the Tensor used by optimizer. For Adam optimizer, contains beta1, beta2, momentum etc. All the information will save to a file with suffix ".pdopt". (If the optimizer have no Tensor need to save (like SGD), the fill will not generated).
      The network description is the description of the program. It's only used for deployment. The description  will save to a file with a suffix ".pdmodel".
  
      Args:
          program(Program) : The program to saved.
          model_path(str): the file prefix to save the program. The format is "dirname/file_prefix". If file_prefix is empty str. A exception will be raised
          protocol(int, optional): The protocol version of pickle module must be greater than 1 and less than 5.
                                   Default: 4
          configs(dict, optional) : optional keyword arguments.                        
  
      Returns:
          None
  
      Examples:
          .. code-block:: python
  
              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")
      """
  
      base_name = os.path.basename(model_path)
      assert base_name != "", \
          "The input model_path MUST be format of dirname/filename [dirname\\filename in Windows system], but received model_path is empty string."
      if 'pickle_protocol' in configs:
          protocol = configs['pickle_protocol']
          warnings.warn(
              "'pickle_protocol' is a deprecated argument. Please use 'protocol' instead."
          )
  
      if not isinstance(protocol, int):
          raise ValueError("The 'protocol' MUST be `int`, but received {}".format(
              type(protocol)))
  
      if protocol < 2 or protocol > 4:
          raise ValueError("Expected 1<'protocol'<5, but received protocol={}".
                           format(protocol))
  
      dir_name = os.path.dirname(model_path)
      if dir_name and not os.path.exists(dir_name):
          os.makedirs(dir_name)
  
      def get_tensor(var):
          t = global_scope().find_var(var.name).get_tensor()
          return np.array(t)
  
      parameter_list = list(filter(is_parameter, program.list_vars()))
      param_dict = {p.name: get_tensor(p) for p in parameter_list}
  
      param_dict = _unpack_saved_dict(param_dict, protocol)
  
      # When value of dict is lager than 4GB ,there is a Bug on 'MAC python3'
      if sys.platform == 'darwin' and sys.version_info.major == 3:
          pickle_bytes = pickle.dumps(param_dict, protocol=protocol)
          with open(model_path + ".pdparams", 'wb') as f:
              max_bytes = 2**30
              for i in range(0, len(pickle_bytes), max_bytes):
                  f.write(pickle_bytes[i:i + max_bytes])
      else:
          with open(model_path + ".pdparams", 'wb') as f:
              pickle.dump(param_dict, f, protocol=protocol)
  
      optimizer_var_list = list(
          filter(is_belong_to_optimizer, program.list_vars()))
  
      opt_dict = {p.name: get_tensor(p) for p in optimizer_var_list}
      with open(model_path + ".pdopt", 'wb') as f:
          pickle.dump(opt_dict, f, protocol=protocol)
  
      main_program = program.clone()
      program.desc.flush()
      main_program.desc._set_version()
      paddle.fluid.core.save_op_version_info(program.desc)
  
      with open(model_path + ".pdmodel", "wb") as f:
          f.write(program.desc.serialize_to_string())
function_tokens: def save ( program , model_path , protocol = 4 , * * configs ) : base_name = os . path . basename ( model_path ) assert base_name != "" , "The input model_path MUST be format of dirname/filename [dirname\\filename in Windows system], but received model_path is empty string." if 'pickle_protocol' in configs : protocol = configs [ 'pickle_protocol' ] warnings . warn ( "'pickle_protocol' is a deprecated argument. Please use 'protocol' instead." ) if not isinstance ( protocol , int ) : raise ValueError ( "The 'protocol' MUST be `int`, but received {}" . format ( type ( protocol ) ) ) if protocol < 2 or protocol > 4 : raise ValueError ( "Expected 1<'protocol'<5, but received protocol={}" . format ( protocol ) ) dir_name = os . path . dirname ( model_path ) if dir_name and not os . path . exists ( dir_name ) : os . makedirs ( dir_name ) def get_tensor ( var ) : t = global_scope ( ) . find_var ( var . name ) . get_tensor ( ) return np . array ( t ) parameter_list = list ( filter ( is_parameter , program . list_vars ( ) ) ) param_dict = { p . name : get_tensor ( p ) for p in parameter_list } param_dict = _unpack_saved_dict ( param_dict , protocol ) # When value of dict is lager than 4GB ,there is a Bug on 'MAC python3' if sys . platform == 'darwin' and sys . version_info . major == 3 : pickle_bytes = pickle . dumps ( param_dict , protocol = protocol ) with open ( model_path + ".pdparams" , 'wb' ) as f : max_bytes = 2 ** 30 for i in range ( 0 , len ( pickle_bytes ) , max_bytes ) : f . write ( pickle_bytes [ i : i + max_bytes ] ) else : with open ( model_path + ".pdparams" , 'wb' ) as f : pickle . dump ( param_dict , f , protocol = protocol ) optimizer_var_list = list ( filter ( is_belong_to_optimizer , program . list_vars ( ) ) ) opt_dict = { p . name : get_tensor ( p ) for p in optimizer_var_list } with open ( model_path + ".pdopt" , 'wb' ) as f : pickle . dump ( opt_dict , f , protocol = protocol ) main_program = program . clone ( ) program . desc . flush ( ) main_program . desc . _set_version ( ) paddle . fluid . core . save_op_version_info ( program . desc ) with open ( model_path + ".pdmodel" , "wb" ) as f : f . write ( program . desc . serialize_to_string ( ) )