code: def get_training_state(
      iterations: int,
      epoch: int,
      model: torch.nn.Module,
      optimizer: Union[BaseOptim, torch.optim.Optimizer],
      best_metric: float,
      gradient_scaler: torch.cuda.amp.GradScaler,
      model_ema: Optional[torch.nn.Module] = None,
  ) -> Dict:
      """Create a checkpoint dictionary that includes all required states to resume the training from its current state.
  
      Args:
          iterations: An integer denoting training iteration number. Each iteration corresponds to forward-backward passes
              on a batch with all GPUs.
          epoch: An integer denoting epoch number.
          model: The model being trained.
          optimizer: Optimizer object, which possibly store training optimization state variables.
          best_metric: Best observed value of the tracking validation metric. For example, best top-1 validation accuracy
              that is observed until the current iteration.
          gradient_scaler: `GradScaler` object storing required automatic mixed precision state.
          model_ema: EMA model to be stored in the checkpoint.
  
      Returns:
          A dictionary that includes all required states to resume the training from its current state.
      """
      model_state = get_model_state_dict(model)
      training_state = {
          "iterations": iterations,
          "epoch": epoch,
          "model_state_dict": model_state,
          "optim_state_dict": optimizer.state_dict(),
          "best_metric": best_metric,
          "gradient_scaler_state_dict": gradient_scaler.state_dict(),
      }
      if model_ema is not None:
          training_state["ema_state_dict"] = get_model_state_dict(
              model_ema
          )
      return training_state
  
imports: import argparse
  import glob
  import math
  import os
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from cvnets import EMA
  from optim import BaseOptim
  from utils import logger
  from utils.common_utils import unwrap_model_fn
  from utils.ddp_utils import is_master
  from utils.download_utils import get_local_path
label_desc: Use image node_id 6 for calling a global function with example usage: get_training_state(iterations, epoch, model, optimizer, best_metric, gradient_scaler, model_ema) and returns: training_state