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: Register a state dict post-hook which will be called after
  :meth:`~torch.optim.Optimizer.state_dict` is called. It should have the
  following signature::
  
      hook(optimizer, state_dict) -> state_dict or None
  
  The hook will be called with arguments ``self`` and ``state_dict`` after generating
  a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
  return a new one. The registered hook can be used to perform post-processing
  on the ``state_dict`` before it is returned.
  
  Args:
      hook (Callable): The user defined hook to be registered.
      prepend (bool): If True, the provided post ``hook`` will be fired before
          all the already registered post-hooks on ``state_dict``. Otherwise,
          the provided ``hook`` will be fired after all the already registered
          post-hooks. (default: False)
  
  Returns:
      :class:`torch.utils.hooks.RemoveableHandle`:
          a handle that can be used to remove the added hook by calling
          ``handle.remove()``
docstr_tok: ["Register","a","state","dict","post-hook","which","will","be","called","after",":","meth",":","`","~torch.optim.Optimizer.state_dict","`","is","called",".","It","should","have","the","following","signature",":",":","hook","(","optimizer",",","state_dict",")","-",">","state_dict","or","None","The","hook","will","be","called","with","arguments","``","self","``","and","``","state_dict","``","after","generating","a","``","state_dict","``","on","``","self","``",".","The","hook","may","modify","the","state_dict","inplace","or","optionally","return","a","new","one",".","The","registered","hook","can","be","used","to","perform","post-processing","on","the","``","state_dict","``","before","it","is","returned",".","Args",":","hook","(","Callable",")",":","The","user","defined","hook","to","be","registered",".","prepend","(","bool",")",":","If","True",",","the","provided","post","``","hook","``","will","be","fired","before","all","the","already","registered","post-hooks","on","``","state_dict","``",".","Otherwise",",","the","provided","``","hook","``","will","be","fired","after","all","the","already","registered","post-hooks",".","(","default",":","False",")","Returns",":",":","class",":","`","torch.utils.hooks.RemoveableHandle","`",":","a","handle","that","can","be","used","to","remove","the","added","hook","by","calling","``","handle.remove","(",")","``"]
code: def register_state_dict_post_hook(
      self,
      hook: Callable[["Optimizer", StateDict], Optional[StateDict]],
      prepend: bool = False,
  ) -> RemovableHandle:
      r"""Register a state dict post-hook which will be called after
      :meth:`~torch.optim.Optimizer.state_dict` is called. It should have the
      following signature::
  
          hook(optimizer, state_dict) -> state_dict or None
  
      The hook will be called with arguments ``self`` and ``state_dict`` after generating
      a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
      return a new one. The registered hook can be used to perform post-processing
      on the ``state_dict`` before it is returned.
  
      Args:
          hook (Callable): The user defined hook to be registered.
          prepend (bool): If True, the provided post ``hook`` will be fired before
              all the already registered post-hooks on ``state_dict``. Otherwise,
              the provided ``hook`` will be fired after all the already registered
              post-hooks. (default: False)
  
      Returns:
          :class:`torch.utils.hooks.RemoveableHandle`:
              a handle that can be used to remove the added hook by calling
              ``handle.remove()``
      """
      handle = hooks.RemovableHandle(
          self._optimizer_state_dict_post_hooks
      )
      self._optimizer_state_dict_post_hooks[handle.id] = hook
      if prepend:
          self._optimizer_state_dict_post_hooks.move_to_end(
              handle.id, last=False
          )
      return handle
  
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 13 for calling the Optimizer obj's underlying member method code with example usage: obj.register_state_dict_post_hook(hook, prepend) and returns: handle