code: def on_batch_end(self, iteration:int, smooth_loss:TensorOrNumber, **kwargs:Any)->None:
          "Determine if loss has runaway and we should stop."
          if iteration==0 or smooth_loss < self.best_loss: self.best_loss = smooth_loss
          self.opt.lr = self.sched.step()
          if self.sched.is_done or (self.stop_div and (smooth_loss > 4*self.best_loss or torch.isnan(smooth_loss))):
              #We use the smoothed loss to decide on the stopping since it's less shaky.
              return {'stop_epoch': True, 'stop_training': Truef on_batch_end(self, iteration:int, smooth_loss:TensorOrNumber, **kwargs:Any)->None:
          "Determine if loss has runaway and we should stop."
          if iteration==0 or smooth_loss < self.best_loss: self.best_loss = smooth_loss
          self.opt.lr = self.sched.step()
          if self.sched.is_done or (self.stop_div and (smooth_loss > 4*self.best_loss or torch.isnan(smooth_loss))):
              #We use the smoothed loss to decide on the stopping since it's less shaky.
              return {'stop_epoch': True, 'stop_training': True}
docs: Determine if loss has runaway and we should stop.