code: def get_trainable_opt_params(
      opt: _torch.optim.Optimizer,
      device: _typing.Optional[_torch.device] = None,
  ) -> _OverrideType:
      r"""Get an override dictionary from an optimizer instance.
  
      Args:
          opt: the optimizer to obtain an override dictionary from.
          device (optional): the device to cast the learnable tensors to.
  
      Returns:
          A dictionary of the format expected for the override kwarg of
          differentiable optimizers. It is initialized with trainable tensors
          with as values those float and int hyperparameters found in the
          optimizer's parameter groups (or stuctures containing these).
          Heuristically, hyperparameters containing mixtures of differentiable
          and non-differentiable types will be ignored (and must be manually
          specified when constructing an override dict).
      """
      override: _OverrideType = _collections.defaultdict(list)
  
      def map_fn(
          x: _typing.Union[_torch.Tensor, int, float]
      ) -> _torch.Tensor:
          if isinstance(x, _torch.Tensor):
              return x.clone().detach().requires_grad_()
          else:
              return _torch.tensor(
                  float(x), device=device, requires_grad=True
              )
  
      for group in opt.param_groups:
          for k, v in group.items():
              if k == "params":
                  # Ignore actual model parameters tracked by optim
                  continue
  
              # Ignore hyperparameters that aren't structures containing ints
              # or floats
              if all(
                  isinstance(x, int) or isinstance(x, float)
                  for x in _utils.flatten(v)
              ):
                  override[k].append(_utils._recursive_map(v, map_fn))
  
      return override
  
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 6 for calling a global function with example usage: get_trainable_opt_params(opt, device) and returns: override, x, _torch