docstr: Input optimizer is the base optimizer for example Adam.
docstr_tok: ["Input","optimizer","is","the","base","optimizer","for","example","Adam","."]
code: def __init__(
      self,
      optimizer,
      clip_grad,
      log_num_zeros_in_grad,
      check_for_nan_in_grad,
      params_have_main_grad,
      models,
  ):
      """Input optimizer is the base optimizer for example Adam."""
      self.optimizer = optimizer
      assert self.optimizer, "no optimizer is provided."
      # Set gradient clipping and logging params.
      self.clip_grad = clip_grad
      self.log_num_zeros_in_grad = log_num_zeros_in_grad
      self.check_for_nan_in_grad = check_for_nan_in_grad
      self.params_have_main_grad = params_have_main_grad
  
      # 'models' are retained for access to the contiguous grad buffers.
      # (see distributed optimizer)
      self.models = models
  
imports: from abc import ABC
  from abc import abstractmethod
  from apex.multi_tensor_apply import multi_tensor_applier
  import amp_C
  import torch
  from megatron import get_timers
  from megatron import print_rank_0
  from megatron.core import mpu, tensor_parallel
  from megatron.model import Float16Module
  from megatron.model.module import param_is_not_shared
  from .clip_grads import clip_grad_norm_fp32, count_zeros_fp32
label_desc: Use image node_id 1 to create a new MegatronOptimizer object from inherited base classes: ABC with example: obj = MegatronOptimizer(optimizer, clip_grad, log_num_zeros_in_grad, check_for_nan_in_grad, params_have_main_grad, models)