class_docstr: Combines multiple KeyedOptimizers into one.
  
  Meant to combine different optimizers for different submodules
class_docstr_tok: ["Combines","multiple","KeyedOptimizers","into","one",".","Meant","to","combine","different","optimizers","for","different","submodules"]
code: def __init__(
      self,
      optims: List[Union[KeyedOptimizer, Tuple[str, KeyedOptimizer]]],
  ) -> None:
      self.defaults: Dict[str, Any] = {}
      # Append empty optimizer key if not passed.
      self._optims: List[Tuple[str, KeyedOptimizer]] = []
      for key_value in optims:
          if isinstance(key_value, KeyedOptimizer):
              key_value = ("", key_value)
          self._optims.append(key_value)
  
      all_keys: Set[str] = set()
      self.defaults["_save_param_groups"] = (
          False
          if len(self._optims) == 0
          else self._optims[0][1].defaults["_save_param_groups"]
      )
      for opt_key, opt in self._optims:
          assert (
              self.defaults["_save_param_groups"]
              == opt.defaults["_save_param_groups"]
          )
  
          for param_key in opt.params.keys():
              new_param = CombinedOptimizer.prepend_opt_key(
                  param_key, opt_key
              )
              if new_param in all_keys:
                  raise ValueError(f"Duplicate param key {new_param}")
              all_keys.add(new_param)
  
      # pyre-ignore
      self._optimizer_step_pre_hooks: Dict[
          int, Callable
      ] = OrderedDict()
      # pyre-ignore
      self._optimizer_step_post_hooks: Dict[
          int, Callable
      ] = OrderedDict()
  
      self._patch_step_function()
  
imports: import json
  from copy import deepcopy
  from typing import Any, Callable, Collection, Dict, List, Mapping, Optional, OrderedDict, Set, Tuple, Union
  import torch
  from torch import optim
  from torchrec.distributed.types import ShardedTensor
label_desc: Use image node_id 1 to create a new CombinedOptimizer object from inherited base classes: KeyedOptimizer with example: obj = CombinedOptimizer(optims)