docstr: Computes the sum of gradients of the given tensor w.r.t. graph leaves.
  
  Compared to :func:`fairseq.optim.FairseqOptimizer.backward`, this function
  additionally dynamically scales the loss to avoid gradient underflow.
code: def backward(self, loss, update_main_grads=False, retain_graph=False):
      """
      Computes the sum of gradients of the given tensor w.r.t. graph leaves.
  
      Compared to :func:`fairseq.optim.FairseqOptimizer.backward`, this function
      additionally dynamically scales the loss to avoid gradient underflow.
      """
      if self.scaler is not None:
          loss = loss * self.scaler.loss_scale
      loss.backward(retain_graph=retain_graph)
      self._needs_sync = True
      if update_main_grads:
          self.update_main_grads()
  
imports: import math
  from itertools import chain
  from typing import Optional
  import parlai.utils.logging
label_desc: Use image node_id 6 for calling the SafeFP16Optimizer obj's underlying member method code with example usage: obj.backward(loss, update_main_grads, retain_graph) without return types