docstr: Initialize the optimizer with the state of an existing optimizer.
  
  Args:
      other: an existing optimizer instance.
      reference_params: an iterable over the parameters of the original
          model.
      fmodel (optional): a patched stateless module with a view on
          weights.
      device (optional): the device to cast state tensors to.
      override (optional): a dictionary mapping optimizer settings (i.e.
          those which would be passed to the optimizer constructor or
          provided within parameter groups) to either singleton lists of
          override values, or to a list of override values of length equal
          to the number of parameter groups. If a single override is
          provided for a keyword, it is used for all parameter groups. If
          a list is provided, the ``i``\ th element of the list overrides the
          corresponding setting in the ``i``\ th parameter group. This permits
          the passing of tensors requiring gradient to differentiable
          optimizers for use as optimizer settings.
      grad_callback: (optional) a single argument function which will be
          applied to a list of gradients of parameters, which respects the
          order specified by ``reference_params``. This can be used to
          apply a function, such as gradient clipping, to all (or a
          subset) of these gradients every time the step function is
          called. If this keyword argument is provided when calling the
          step method, its value will override the default specified here.
      track_higher_grads: if True, during unrolled optimization the graph
          be retained, and the fast weights will bear grad funcs, so as to
          permit backpropagation through the optimization process. Setting
          this to False allows the differentiable optimizer to be used in
          "test mode", without potentially tracking higher order
          gradients. This can be useful when running the training loop at
          test time, e.g. in k-shot learning experiments, without
          incurring a significant memory overhead.
code: def __init__(
      self,
      other: _torch.optim.Optimizer,
      reference_params: _typing.Iterable[_torch.Tensor],
      fmodel: _typing.Optional[_patch._MonkeyPatchBase] = None,
      device: _typing.Optional[_torch.device] = None,
      override: _typing.Optional[_OverrideType] = None,
      grad_callback: _typing.Optional[_GradCallbackType] = None,
      track_higher_grads: bool = True,
      **kwargs,
  ) -> None:
      r"""Initialize the optimizer with the state of an existing optimizer.
  
      Args:
          other: an existing optimizer instance.
          reference_params: an iterable over the parameters of the original
              model.
          fmodel (optional): a patched stateless module with a view on
              weights.
          device (optional): the device to cast state tensors to.
          override (optional): a dictionary mapping optimizer settings (i.e.
              those which would be passed to the optimizer constructor or
              provided within parameter groups) to either singleton lists of
              override values, or to a list of override values of length equal
              to the number of parameter groups. If a single override is
              provided for a keyword, it is used for all parameter groups. If
              a list is provided, the ``i``\ th element of the list overrides the
              corresponding setting in the ``i``\ th parameter group. This permits
              the passing of tensors requiring gradient to differentiable
              optimizers for use as optimizer settings.
          grad_callback: (optional) a single argument function which will be
              applied to a list of gradients of parameters, which respects the
              order specified by ``reference_params``. This can be used to
              apply a function, such as gradient clipping, to all (or a
              subset) of these gradients every time the step function is
              called. If this keyword argument is provided when calling the
              step method, its value will override the default specified here.
          track_higher_grads: if True, during unrolled optimization the graph
              be retained, and the fast weights will bear grad funcs, so as to
              permit backpropagation through the optimization process. Setting
              this to False allows the differentiable optimizer to be used in
              "test mode", without potentially tracking higher order
              gradients. This can be useful when running the training loop at
              test time, e.g. in k-shot learning experiments, without
              incurring a significant memory overhead.
      """
      reference_params = list(reference_params)
  
      # Copy param groups and set up structures for copy state
      self.param_groups = _copy.deepcopy(other.param_groups)
      self._group_to_param_list: _typing.List[_typing.List[int]] = []
      self.state: _StateType = [
          _collections.defaultdict(dict)
          for _ in range(len(self.param_groups))
      ]
  
      # Deal with override
      if override is not None:
          self._apply_override(override)
  
      self._grad_callback = grad_callback
  
      # Copy and cast state
      zipped = zip(self.param_groups, other.param_groups)
      for group_idx, (group, orig_group) in enumerate(zipped):
          local_list = []
          for p_idx, p in enumerate(orig_group["params"]):
              if p in other.state:
                  self.state[group_idx][p_idx] = {
                      k: _utils._recursive_copy_and_cast(v, device)
                      for k, v in other.state[p].items()
                  }
              index = _utils._find_param_in_list(p, reference_params)
              if index is None:
                  raise ValueError(
                      "Could not find parameter {} in reference parameters.".format(
                          str(p)
                      )
                  )
              local_list.append(index)
          group["params"] = [None] * len(group["params"])
          self._group_to_param_list.append(local_list)
  
      self._fmodel = fmodel
      self._track_higher_grads = track_higher_grads
  
imports: import abc
  import collections
  import copy
  import math
  import typing
  import warnings
  import torch
  from .None import patch
  from .None import utils
label_desc: Use image node_id 1 to create a new DifferentiableOptimizer object from inherited base classes: _abc with example: obj = DifferentiableOptimizer(other, reference_params, fmodel, device, override, grad_callback, track_higher_grads)