Skip to content

Commit

Permalink
handling of None values
Browse files Browse the repository at this point in the history
  • Loading branch information
civodlu committed Apr 14, 2021
1 parent 35f83aa commit bda797b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/trw/callbacks/callback_early_stopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ def _initialize(self, num_epochs):
max_loss_by_epoch[e] = None
continue

values = sorted(values)
rank = round(len(values) * (1.0 - self.discard_if_among_worst_X_performers))
threshold = values[rank]
if values is not None:
values = sorted(values)
rank = round(len(values) * (1.0 - self.discard_if_among_worst_X_performers))
threshold = values[rank]
else:
threshold = None
max_loss_by_epoch[e] = threshold
self.max_loss_by_epoch = max_loss_by_epoch
logger.info(f'max_loss_by_step={max_loss_by_epoch}')
Expand All @@ -101,7 +104,7 @@ def __call__(self, options, history, model, **kwargs):
logger.info(f'epoch={epoch}, loss={loss}, early termination!')
raise ExceptionAbortRun(
history=history,
reason=f'Early termination. loss={loss}. raise_stop_fn returned true!')
reason=f'Early termination (epoch={len(history)}). loss={loss}. raise_stop_fn returned true!')

# return ONLY after the `raise_stop_fn` check: often,
# the `loss` will be based on the validation (potentially mostly none)
Expand Down

0 comments on commit bda797b

Please sign in to comment.