code: def parse_optimizer_args(
      optimizer_name: str,
      optimizer_kwargs: Union[DictConfig, Dict[str, Any]],
  ) -> Union[Dict[str, Any], DictConfig]:
      """
      Parses a list of strings, of the format "key=value" or "key2=val1,val2,..."
      into a dictionary of type {key=value, key2=[val1, val2], ...}
  
      This dictionary is then used to instantiate the chosen Optimizer.
  
      Args:
          optimizer_name: string name of the optimizer, used for auto resolution of params
          optimizer_kwargs: Either a list of strings in a specified format,
              or a dictionary. If a dictionary is provided, it is assumed the dictionary
              is the final parsed value, and simply returned.
              If a list of strings is provided, each item in the list is parsed into a
              new dictionary.
  
      Returns:
          A dictionary
      """
      kwargs = {}
  
      if optimizer_kwargs is None:
          return kwargs
  
      optimizer_kwargs = copy.deepcopy(optimizer_kwargs)
      optimizer_kwargs = maybe_update_config_version(optimizer_kwargs)
  
      if isinstance(optimizer_kwargs, DictConfig):
          optimizer_kwargs = OmegaConf.to_container(
              optimizer_kwargs, resolve=True
          )
  
      # If it is a dictionary, perform stepwise resolution
      if hasattr(optimizer_kwargs, "keys"):
          # Attempt class path resolution
          if (
              "_target_" in optimizer_kwargs
          ):  # captures (target, _target_)
              optimizer_kwargs_config = OmegaConf.create(
                  optimizer_kwargs
              )
              optimizer_instance = hydra.utils.instantiate(
                  optimizer_kwargs_config
              )  # type: DictConfig
              optimizer_instance = vars(optimizer_instance)
              return optimizer_instance
  
          # If class path was not provided, perhaps `name` is provided for resolution
          if "name" in optimizer_kwargs:
              # If `auto` is passed as name for resolution of optimizer name,
              # then lookup optimizer name and resolve its parameter config
              if optimizer_kwargs["name"] == "auto":
                  optimizer_params_name = "{}_params".format(
                      optimizer_name
                  )
                  optimizer_kwargs.pop("name")
              else:
                  optimizer_params_name = optimizer_kwargs.pop("name")
  
              # Override arguments provided in the config yaml file
              if "params" in optimizer_kwargs:
                  # If optimizer kwarg overrides are wrapped in yaml `params`
                  optimizer_params_override = optimizer_kwargs.get(
                      "params"
                  )
              else:
                  # If the kwargs themselves are a DictConfig
                  optimizer_params_override = optimizer_kwargs
  
              if isinstance(optimizer_params_override, DictConfig):
                  optimizer_params_override = OmegaConf.to_container(
                      optimizer_params_override, resolve=True
                  )
  
              optimizer_params_cls = get_optimizer_config(
                  optimizer_params_name, **optimizer_params_override
              )
  
              # If we are provided just a Config object, simply return the dictionary of that object
              if optimizer_params_name is None:
                  optimizer_params = vars(optimizer_params_cls)
                  return optimizer_params
  
              else:
                  # If we are provided a partial class instantiation of a Config,
                  # Instantiate it and retrieve its vars as a dictionary
                  optimizer_params = (
                      optimizer_params_cls()
                  )  # instantiate the parameters object
                  optimizer_params = vars(optimizer_params)
                  return optimizer_params
  
          # simply return the dictionary that was provided
          return optimizer_kwargs
  
      return kwargs
  
file_path: NeMo/nemo/core/optim/optimizers.py
imports: import copy
  from functools import partial
  from typing import Any, Dict, Optional, Union
  import hydra
  import torch
  import torch.optim
  from omegaconf import DictConfig, OmegaConf
  from torch.optim import adadelta, adagrad, adamax, rmsprop, rprop
  from torch.optim.optimizer import Optimizer
  from nemo.core.config import OptimizerParams, get_optimizer_config, register_optimizer_params
  from nemo.core.optim.adafactor import Adafactor
  from nemo.core.optim.adan import Adan
  from nemo.core.optim.novograd import Novograd
  from nemo.utils import logging
  from nemo.utils.model_utils import maybe_update_config_version
label_desc: Use image node_id 1 for calling a global function with example usage: parse_optimizer_args(optimizer_name, optimizer_kwargs) and returns: kwargs, kwargs, optimizer_kwargs, optimizer_instance, optimizer_params, optimizer_params