def update_scale(self, overflow):
iter_since_rescale = self._num_steps - self._last_rescale_iter<EOL>if overflow:<EOL><INDENT>self._last_overflow_iter = self._num_steps<EOL>self._overflows_since_rescale += <NUM_LIT:1><EOL>percentage = self._overflows_since_rescale / float(iter_since_rescale)<EOL>if percentage >= self.tolerance:<EOL><INDENT>self.loss_scale /= self.scale_factor<EOL>self._last_rescale_iter = self._num_steps<EOL>self._overflows_since_rescale = <NUM_LIT:0><EOL>logging.info('<STR_LIT>',<EOL>self.loss_scale)<EOL><DEDENT><DEDENT>elif (self._num_steps - self._last_overflow_iter) % self.scale_window == <NUM_LIT:0>:<EOL><INDENT>self.loss_scale *= self.scale_factor<EOL>self._last_rescale_iter = self._num_steps<EOL><DEDENT>self._num_steps += <NUM_LIT:1><EOL>
dynamically update loss scale