-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import final | ||
|
||
from typing_extensions import override | ||
|
||
|
||
class EarlyStopper(ABC): | ||
"""Stops training when an implementation-specific condition is not met.""" | ||
|
||
@abstractmethod | ||
def should_stop(self, step_nr: int, score: float) -> bool: | ||
""" | ||
:param step_nr: The number of the current training step. | ||
:para score: The validation score of the current training step. | ||
:returns: ``True`` if the training should be stopped; otherwise, ``False``. | ||
""" | ||
|
||
|
||
@final | ||
class NoopEarlyStopper(EarlyStopper): | ||
@override | ||
def should_stop(self, step_nr: int, score: float) -> bool: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters