parameters: (self, state: dict)
docstring: r"""Loads the optimizer state.
  
          Args:
              state: optimizer state. Should be an object returned
                  from a call to :meth:`state_dict`.
docstring_summary: r"""Loads the optimizer state.
docstring_tokens: r Loads the optimizer state .
function: def load_state_dict(self, state: dict):
          r"""Loads the optimizer state.
  
          Args:
              state: optimizer state. Should be an object returned
                  from a call to :meth:`state_dict`.
          """
          if len(self.param_groups) != len(state["param_groups"]):
              raise ValueError(
                  "loaded state dict has a different number of parameter groups"
              )
          for group_new, group_saved in zip(self.param_groups, state["param_groups"]):
              if len(group_new["params"]) != len(group_saved["params"]):
                  raise ValueError(
                      "loaded state dict contains a parameter group that "
                      "doesn't match the size of optimizer's group"
                  )
              for param_new, param_saved in zip(
                  group_new["params"], group_saved["params"]
              ):
                  p = param_new
                  self._state[p] = state["state"][param_saved].copy()
                  for k, v in self._state[p].items():
                      if isinstance(v, Tensor):
                          self._state[p][k] = v.detach()
                      else:
                          self._state[p][k] = Tensor(v)
  
              if set(group_new.keys()) != set(group_saved.keys()):
                  raise ValueError(
                      "loaded state dict contains a parameter group that "
                      "doesn't match the keys of optimizer's group"
                  )
              for key in group_new.keys():
                  if key != "params":
                      group_new[key] = group_saved[key]
  
          if len(self._state.keys()) != len(state["state"].keys()):
              raise ValueError(
                  "loaded state dict contains a state that doesn't match "
                  "the size of optimizer's state"
              )
function_tokens: def load_state_dict ( self , state : dict ) : if len ( self . param_groups ) != len ( state [ "param_groups" ] ) : raise ValueError ( "loaded state dict has a different number of parameter groups" ) for group_new , group_saved in zip ( self . param_groups , state [ "param_groups" ] ) : if len ( group_new [ "params" ] ) != len ( group_saved [ "params" ] ) : raise ValueError ( "loaded state dict contains a parameter group that " "doesn't match the size of optimizer's group" ) for param_new , param_saved in zip ( group_new [ "params" ] , group_saved [ "params" ] ) : p = param_new self . _state [ p ] = state [ "state" ] [ param_saved ] . copy ( ) for k , v in self . _state [ p ] . items ( ) : if isinstance ( v , Tensor ) : self . _state [ p ] [ k ] = v . detach ( ) else : self . _state [ p ] [ k ] = Tensor ( v ) if set ( group_new . keys ( ) ) != set ( group_saved . keys ( ) ) : raise ValueError ( "loaded state dict contains a parameter group that " "doesn't match the keys of optimizer's group" ) for key in group_new . keys ( ) : if key != "params" : group_new [ key ] = group_saved [ key ] if len ( self . _state . keys ( ) ) != len ( state [ "state" ] . keys ( ) ) : raise ValueError ( "loaded state dict contains a state that doesn't match " "the size of optimizer's state" )