code: def create_diff_optim(
      opt_type: _typing.Type[_torch.optim.Optimizer],
      opt_kwargs: _typing.Optional[
          _typing.Dict[str, _typing.Any]
      ] = None,
      params: _typing.Optional[_typing.List[_torch.Tensor]] = None,
      fmodel: _typing.Optional[_patch._MonkeyPatchBase] = None,
      device: _typing.Optional[_torch.device] = None,
      override: _typing.Optional[_OverrideType] = None,
      track_higher_grads: bool = True,
      **kwargs,
  ) -> DifferentiableOptimizer:
      r"""Construct a differentiable version of an new optimizer.
  
      Args:
          opt_type: the type (constructor) for a torch.optim.Optimizer subtype
              from amongst the types supported by the library, or registered with
              it a runtime.
          opt_kwargs: a dictionary of keywords to be passed to the optimizer
              constructor.
          params (optional): a list of (fast) weights which the differentiable
              optimizer will update. These must be provided if fmodel is not
              provided. If both, these will be used in lieu. These will only
              be used for shape inference when initializing the optimizer.
              This argument can also take the same format as parameter groups,
              i.e. an iterable over dictionaries which contain the 'params' key
              with fast weights as value, and group-specific hyperparameters.
          fmodel (optional): a patched version of the ``module`` tracked by ``opt``.
              It is assumed this patched instance has a view on its latest fast
              weights through ``fmodel.parameters()``. If provided, it is not
              necessary to pass the fast weights explicitly to the differentiable
              optimizer's ``step`` function via the keyword arg ``params``. If not
              provided, the fast weights to update must be provided to ``step``.
          device (optional): the device to cast the optimizer state to when
              creating the differentiable optimizer. If not provided, the same
              device as used for the parameters tracked by ``opt`` will be used.
          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.
          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 returned 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.
  
      Returns:
          An initialized ``DifferentiableOptimizer`` instance of the right subtype.
      """
  
      if opt_type in _opt_mapping:
          if params is not None:
              params = list(params)
              if isinstance(params[0], dict):
                  dummy = [
                      {
                          k: _torch.zeros_like(v, requires_grad=True)
                          if k == "params"
                          else v
                          for k, v in group.items()
                      }
                      for group in params
                  ]
              else:
                  dummy = [
                      _torch.zeros_like(p, requires_grad=True)
                      for p in params
                  ]
          elif fmodel is not None:
              dummy = [
                  _torch.zeros_like(p, requires_grad=True)
                  for p in fmodel.parameters()
              ]
          else:
              raise ValueError(
                  "Must specify one of fmodel or params in kwargs."
              )
  
          opt_kwargs = {} if opt_kwargs is None else opt_kwargs
          opt = opt_type(dummy, **opt_kwargs)
  
          return _opt_mapping[opt_type](
              opt,
              dummy,
              fmodel=fmodel,
              device=device,
              override=override,
              track_higher_grads=track_higher_grads,
              **kwargs,
          )
      else:
          raise ValueError(
              "Optimizer type {} not supported by higher yet.".format(
                  opt_type
              )
          )
  
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 4 for calling a global function with example usage: create_diff_optim(opt_type, opt_kwargs, params, fmodel, device, override, track_higher_grads) and returns: _opt_mapping