Skip to content

Commit

Permalink
Save vertical space + old fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed Feb 12, 2020
1 parent 68e4bce commit ac46636
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions fastai/callbacks/lr_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def on_batch_end(self, iteration:int, smooth_loss:TensorOrNumber, **kwargs:Any)-
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.
if not self.stop:
self.stop = iteration
if not self.stop: self.stop = iteration
if num_distrib() <= 1: return { 'stop_epoch': True, 'stop_training' : True }

def on_epoch_end(self, **kwargs:Any)->None:
Expand Down
3 changes: 2 additions & 1 deletion fastai/callbacks/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def on_epoch_end(self, epoch:int, **kwargs:Any)->None:
"Compare the value monitored to its best score and maybe save the model."
if self.every=="epoch": self.learn.save(f'{self.name}_{epoch}')
else: #every="improvement"
current = self.get_monitor_value().cpu()
current = self.get_monitor_value()
if isinstance(current, Tensor): current = current.cpu()
if current is not None and self.operator(current, self.best):
print(f'Better model found at epoch {epoch} with {self.monitor} value: {current}.')
self.best = current
Expand Down

0 comments on commit ac46636

Please sign in to comment.