code: def add_optimizer_args(
      parent_parser: ArgumentParser,
      optimizer: str = "adam",
      default_lr: float = None,
      default_opt_args: Optional[
          Union[Dict[str, Any], List[str]]
      ] = None,
  ) -> ArgumentParser:
      """Extends existing argparse with support for optimizers.
  
      # Example of adding optimizer args to command line :
      python train_script.py ... --optimizer "novograd" --lr 0.01 \
          --opt_args betas=0.95,0.5 weight_decay=0.001
  
      Args:
          parent_parser (ArgumentParser): Custom CLI parser that will be extended.
          optimizer (str): Default optimizer required.
          default_lr (float): Default learning rate that should be overriden during training.
          default_opt_args (list(str)): List of overriding arguments for the instantiated optimizer.
  
      Returns:
          ArgumentParser: Parser extended by Optimizers arguments.
      """
      if default_opt_args is None:
          default_opt_args = []
  
      parser = ArgumentParser(
          parents=[parent_parser],
          add_help=True,
          conflict_handler="resolve",
      )
  
      parser.add_argument(
          "--optimizer",
          type=str,
          default=optimizer,
          help="Name of the optimizer. Defaults to Adam.",
      )
      parser.add_argument(
          "--lr",
          type=float,
          default=default_lr,
          help="Learning rate of the optimizer.",
      )
      parser.add_argument(
          "--opt_args",
          default=default_opt_args,
          nargs="+",
          type=str,
          help="Overriding arguments for the optimizer. \n Must follow the pattern : \n name=value separated by spaces."
          "Example: --opt_args weight_decay=0.001 eps=1e-8 betas=0.9,0.999",
      )
  
      return parser
  
imports: from argparse import ArgumentParser
  from typing import Any, Dict, List, Optional, Union
label_desc: Use image node_id 1 for calling a global function with example usage: add_optimizer_args(parent_parser, optimizer, default_lr, default_opt_args) and returns: parser