code: def update_scale(self, overflow):
          
          iter_since_rescale = self._num_steps - self._last_rescale_iter
          if overflow:
              self._last_overflow_iter = self._num_steps
              self._overflows_since_rescale += 1
              percentage = self._overflows_since_rescale / float(iter_since_rescale)
              # we tolerate a certrain amount of NaNs before actually scaling it down
              if percentage >= self.tolerance:
                  self.loss_scale /= self.scale_factor
                  self._last_rescale_iter = self._num_steps
                  self._overflows_since_rescale = 0
                  logging.info('DynamicLossScaler: overflow detected. set loss_scale = %s',
                               self.loss_scale)
          elif (self._num_steps - self._last_overflow_iter) % self.scale_window == 0:
              self.loss_scale *= self.scale_factor
              self._last_rescale_iter = self._num_steps
          self._num_steps += 1
docs: dynamically update loss scale