docstr: Clips gradient norm and updates dynamic loss scaler.
docstr_tok: ["Clips","gradient","norm","and","updates","dynamic","loss","scaler","."]
code: def clip_grad_norm(self, max_norm):
      """Clips gradient norm and updates dynamic loss scaler."""
      self._sync_fp16_grads_to_fp32()
      grad_norm = utils.clip_grad_norm_(
          self.fp32_params.grad.data, max_norm
      )
  
      # detect overflow and adjust loss scale
      overflow = Fairseq_DynamicLossScaler.has_overflow(grad_norm)
      self.scaler.update_scale(overflow)
      if overflow:
          if self.scaler.loss_scale <= self.min_loss_scale:
              # Use FloatingPointError as an uncommon error that parent
              # functions can safely catch to stop training.
              raise FloatingPointError(
                  (
                      "Minimum loss scale reached ({}). Your loss is probably exploding. "
                      "Try lowering the learning rate, using gradient clipping or "
                      "increasing the batch size."
                  ).format(self.min_loss_scale)
              )
          raise OverflowError(
              "setting loss scale to: " + str(self.scaler.loss_scale)
          )
      return grad_norm
  
imports: from itertools import chain
  import torch
  from fairseq import utils
  from fairseq.optim.fp16_optimizer import DynamicLossScaler
label_desc: Use image node_id 8 for calling the Fairseq_FP16OptimizerMixin obj's underlying member method code with example usage: obj.clip_grad_norm(max_norm) and returns: grad_norm