parameters: (self, mode='all', scope=None)
return_statement: return state_dict
docstring: Get parameters and persistable buffers of program as a dict. The key is the name of the parameter or the name of the buffer.
          The value is the tensor of this variable in the given scope.
  
          .. note::
              This function MUST called after run start_up_program
  
          Args:
              mode(str, optional): Source of the obtained parameters and buffers. 
                      'opt' :  The return value only contains the variable in the optimizer. 
                      'param' : The return value only contains the variable in the network, not the variable in the optimizer.  
                      'all' : The return value contains the variable in the network and optimizer.
                      Default: 'all'
              scope(Scope, optional) : If scope is None, state_dict will be set to global scope 
                  obtained through 'paddle.static.global_scope()'. Otherwise, value will be set to scope.
                  Default: None
  
          Retruns:
              dict: a dict contains the parameters and persistable buffers.
  
          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()
  
                  path = "./temp/model.pdparams"
                  paddle.save(prog.state_dict(), path)
docstring_summary: Get parameters and persistable buffers of program as a dict. The key is the name of the parameter or the name of the buffer.
          The value is the tensor of this variable in the given scope.
docstring_tokens: Get parameters and persistable buffers of program as a dict . The key is the name of the parameter or the name of the buffer . The value is the tensor of this variable in the given scope .
function: def state_dict(self, mode='all', scope=None):
          """
          Get parameters and persistable buffers of program as a dict. The key is the name of the parameter or the name of the buffer.
          The value is the tensor of this variable in the given scope.
  
          .. note::
              This function MUST called after run start_up_program
  
          Args:
              mode(str, optional): Source of the obtained parameters and buffers. 
                      'opt' :  The return value only contains the variable in the optimizer. 
                      'param' : The return value only contains the variable in the network, not the variable in the optimizer.  
                      'all' : The return value contains the variable in the network and optimizer.
                      Default: 'all'
              scope(Scope, optional) : If scope is None, state_dict will be set to global scope 
                  obtained through 'paddle.static.global_scope()'. Otherwise, value will be set to scope.
                  Default: None
  
          Retruns:
              dict: a dict contains the parameters and persistable buffers.
  
          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()
  
                  path = "./temp/model.pdparams"
                  paddle.save(prog.state_dict(), path)
          """
          # The 'framework' is a low-level module, and 'executor'
          # can not be imported at the begainning of this file. 
          # Therefore, the above two modules are dynamically imported.
          from .executor import global_scope
          if scope is not None and not isinstance(scope, core._Scope):
              raise TypeError(
                  "`scope` should be None or `paddle.static.Scope'` type, but received {}.".
                  format(type(scope)))
  
          if scope is None:
              scope = global_scope()
  
          if not isinstance(mode, str):
              raise TypeError("Type of `mode` should be string, but received {}.".
                              format(type(mode)))
  
          def is_parameter(var):
              return isinstance(var, Parameter)
  
          def is_persistable(var):
              if var.desc.type() == core.VarDesc.VarType.FEED_MINIBATCH or \
                  var.desc.type() == core.VarDesc.VarType.FETCH_LIST or \
                  var.desc.type() == core.VarDesc.VarType.READER:
                  return False
              return var.persistable
  
          def is_belong_to_optimizer(var):
              if not (isinstance(var, Parameter) or var.desc.need_check_feed()):
                  return is_persistable(var)
              return False
  
          def condition(var):
  
              if mode == 'param':
                  return is_parameter(var)
              elif mode == 'opt':
                  return is_belong_to_optimizer(var)
              elif mode == 'all':
                  return is_parameter(var) or is_belong_to_optimizer(var)
              else:
                  raise ValueError(
                      "`mode` string should be 'param', 'opt' or 'all', but received {}.".
                      format(mode))
  
          var_list = filter(condition, self.list_vars())
  
          state_dict = dict()
          for var in var_list:
              var_temp = scope.find_var(var.name)
              if var_temp is None:
                  raise ValueError(
                      "Can not find Variable '{}' in the scope. Make sure it is initialized".
                      format(var.name))
              state_dict[var.name] = var_temp.get_tensor()
  
          return state_dict
function_tokens: def state_dict ( self , mode = 'all' , scope = None ) : # The 'framework' is a low-level module, and 'executor' # can not be imported at the begainning of this file.  # Therefore, the above two modules are dynamically imported. from . executor import global_scope if scope is not None and not isinstance ( scope , core . _Scope ) : raise TypeError ( "`scope` should be None or `paddle.static.Scope'` type, but received {}." . format ( type ( scope ) ) ) if scope is None : scope = global_scope ( ) if not isinstance ( mode , str ) : raise TypeError ( "Type of `mode` should be string, but received {}." . format ( type ( mode ) ) ) def is_parameter ( var ) : return isinstance ( var , Parameter ) def is_persistable ( var ) : if var . desc . type ( ) == core . VarDesc . VarType . FEED_MINIBATCH or var . desc . type ( ) == core . VarDesc . VarType . FETCH_LIST or var . desc . type ( ) == core . VarDesc . VarType . READER : return False return var . persistable def is_belong_to_optimizer ( var ) : if not ( isinstance ( var , Parameter ) or var . desc . need_check_feed ( ) ) : return is_persistable ( var ) return False def condition ( var ) : if mode == 'param' : return is_parameter ( var ) elif mode == 'opt' : return is_belong_to_optimizer ( var ) elif mode == 'all' : return is_parameter ( var ) or is_belong_to_optimizer ( var ) else : raise ValueError ( "`mode` string should be 'param', 'opt' or 'all', but received {}." . format ( mode ) ) var_list = filter ( condition , self . list_vars ( ) ) state_dict = dict ( ) for var in var_list : var_temp = scope . find_var ( var . name ) if var_temp is None : raise ValueError ( "Can not find Variable '{}' in the scope. Make sure it is initialized" . format ( var . name ) ) state_dict [ var . name ] = var_temp . get_tensor ( ) return state_dict