Fix patience for identical scores (#7250)

* Fix patience for identical scores

Fix training patience so that the earliest best step is chosen for
identical max scores.

* Restore break, remove print

* Explicitly define best_step for clarity
This commit is contained in:
Adriane Boyd 2021-03-06 08:42:14 +01:00 committed by GitHub
parent dfb23a419e
commit 97bcf2ae3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,7 +230,10 @@ def train_while_improving(
if is_best_checkpoint is not None: if is_best_checkpoint is not None:
losses = {} losses = {}
# Stop if no improvement in `patience` updates (if specified) # Stop if no improvement in `patience` updates (if specified)
best_score, best_step = max(results) # Negate step value so that the earliest best step is chosen for the
# same score, i.e. (1.0, 100) is chosen over (1.0, 200)
best_result = max((r_score, -r_step) for r_score, r_step in results)
best_step = -best_result[1]
if patience and (step - best_step) >= patience: if patience and (step - best_step) >= patience:
break break
# Stop if we've exhausted our max steps (if specified) # Stop if we've exhausted our max steps (if specified)