class_docstr: Base class for all optimizers.
  
  .. warning::
      Parameters need to be specified as collections that have a deterministic
      ordering that is consistent between runs. Examples of objects that don't
      satisfy those properties are sets and iterators over values of dictionaries.
  
  Args:
      params (iterable): an iterable of :class:`torch.Tensor` s or
          :class:`dict` s. Specifies what Tensors should be optimized.
      defaults: (dict): a dict containing default values of optimization
          options (used when a parameter group doesn't specify them).
class_docstr_tok: ["Base","class","for","all","optimizers",".","..","warning",":",":","Parameters","need","to","be","specified","as","collections","that","have","a","deterministic","ordering","that","is","consistent","between","runs",".","Examples","of","objects","that","don't","satisfy","those","properties","are","sets","and","iterators","over","values","of","dictionaries",".","Args",":","params","(","iterable",")",":","an","iterable","of",":","class",":","`","torch.Tensor","`","s","or",":","class",":","`","dict","`","s.","Specifies","what","Tensors","should","be","optimized",".","defaults",":","(","dict",")",":","a","dict","containing","default","values","of","optimization","options","(","used","when","a","parameter","group","does","n't","specify","them",")","."]
docstr: Loads the optimizer state.
  
  Args:
      state_dict (dict): optimizer state. Should be an object returned
          from a call to :meth:`state_dict`.
docstr_tok: ["Loads","the","optimizer","state",".","Args",":","state_dict","(","dict",")",":","optimizer","state",".","Should","be","an","object","returned","from","a","call","to",":","meth",":","`","state_dict","`","."]
code: def load_state_dict(self, state_dict: StateDict) -> None:
      r"""Loads the optimizer state.
  
      Args:
          state_dict (dict): optimizer state. Should be an object returned
              from a call to :meth:`state_dict`.
      """
      # shallow copy, to be consistent with module API
      state_dict = state_dict.copy()
  
      for (
          pre_hook
      ) in self._optimizer_load_state_dict_pre_hooks.values():
          hook_result = pre_hook(self, state_dict)
          if hook_result is not None:
              state_dict = hook_result
  
      # Validate the state_dict
      groups = self.param_groups
  
      # Deepcopy as we write into saved_groups later to update state
      saved_groups = deepcopy(state_dict["param_groups"])
  
      if len(groups) != len(saved_groups):
          raise ValueError(
              "loaded state dict has a different number of "
              "parameter groups"
          )
      param_lens = (len(g["params"]) for g in groups)
      saved_lens = (len(g["params"]) for g in saved_groups)
      if any(
          p_len != s_len for p_len, s_len in zip(param_lens, saved_lens)
      ):
          raise ValueError(
              "loaded state dict contains a parameter group "
              "that doesn't match the size of optimizer's group"
          )
  
      # Update the state
      id_map = dict(
          zip(
              chain.from_iterable(g["params"] for g in saved_groups),
              chain.from_iterable(g["params"] for g in groups),
          )
      )
  
      def _cast(
          param, value, param_id=None, param_groups=None, key=None
      ):
          r"""Make a deep copy of value, casting all tensors to device of param."""
          if isinstance(value, torch.Tensor):
              return Optimizer._process_value_according_to_param_policy(
                  param, value, param_id, param_groups, key
              )
          elif isinstance(value, dict):
              return {
                  k: _cast(
                      param,
                      v,
                      param_id=param_id,
                      param_groups=param_groups,
                      key=k,
                  )
                  for k, v in value.items()
              }
          elif isinstance(value, Iterable):
              return type(value)(_cast(param, v, param_id=param_id, param_groups=param_groups) for v in value)  # type: ignore[call-arg]
          else:
              return value
  
      # Copy state assigned to params (and cast tensors to appropriate types).
      # State that is not assigned to params is copied as is (needed for
      # backward compatibility).
      state: DefaultDict[torch.Tensor, Dict[Any, Any]] = defaultdict(
          dict
      )
      for k, v in state_dict["state"].items():
          if k in id_map:
              param = id_map[k]
              state[param] = _cast(
                  param,
                  v,
                  param_id=k,
                  param_groups=state_dict["param_groups"],
              )
          else:
              state[k] = v
  
      # Update parameter groups, setting their 'params' value
      def update_group(
          group: Dict[str, Any], new_group: Dict[str, Any]
      ) -> Dict[str, Any]:
          new_group["params"] = group["params"]
          return new_group
  
      param_groups = [
          update_group(g, ng) for g, ng in zip(groups, saved_groups)
      ]
      self.__setstate__({"state": state, "param_groups": param_groups})
  
      for (
          post_hook
      ) in self._optimizer_load_state_dict_post_hooks.values():
          post_hook(self)
  
imports: import math
  import functools
  import warnings
  from collections import OrderedDict, defaultdict
  from copy import deepcopy
  from itertools import chain
  from typing import Any, Callable, DefaultDict, Dict, Hashable, Iterable, List, Optional, Set, Tuple, TypeVar, Union, cast, overload
  from typing_extensions import ParamSpec, Self, TypeAlias
  import torch
  import torch.utils.hooks
  from torch.utils.hooks import RemovableHandle
  from torch.utils._foreach_utils import Indices, TensorListList, _get_foreach_kernels_supported_devices, _get_fused_kernels_supported_devices
  from torch._utils import is_compiling
  from torch.utils._foreach_utils import _group_tensors_by_device_and_dtype
label_desc: Use image node_id 18 for calling the Optimizer obj's underlying member method code with example usage: obj.load_state_dict(state_dict) and returns: new_group, Optimizer, unknown, type, value