pytorch_pfn_extras.training.triggers.EarlyStoppingTrigger#
- class pytorch_pfn_extras.training.triggers.EarlyStoppingTrigger(self, check_trigger=(1, 'epoch'), monitor='main/loss', patience=3, mode='auto', verbose=False, max_trigger=(100, 'epoch'))#
Bases:
Trigger
Trigger for Early Stopping
This trigger works as follows. Within each check interval defined by the
check_trigger
argument, it monitors and accumulates the reported value at each iteration. At the end of each interval, it computes the mean of the accumulated values and compares it to the previous ones to maintain the best value. When it finds that the best value is not updated for some periods (defined bypatience
), this trigger fires.- Parameters:
monitor (str) – The metric you want to monitor
check_trigger (TriggerLike) – Trigger that decides the comparison interval between current best value and new value. This must be a tuple in the form of
<int>, 'epoch'
or<int>, 'iteration'
which is passed toIntervalTrigger
.patience (int) – Counts to let the trigger be patient. The trigger will not fire until the condition is met for successive
patience
checks.mode (str) –
'max'
,'min'
, or'auto'
. It is used to determine how to compare the monitored values.verbose (bool) – Enable verbose output. If verbose is true, you can get more information
max_trigger (Tuple[int, UnitLiteral]) – Upper bound of the number of training loops
Methods
__init__
([check_trigger, monitor, patience, ...])load_state_dict
(state)may_fire
(iteration, epoch_length)Flags if the trigger may fire at the current iteration
state_dict
()- __call__(manager)#
Decides whether the training loop should be stopped.
- Parameters:
manager (ExtensionsManager) – Manager object that this trigger is associated with. The
observation
of this manager is used to determine if the trigger should fire.- Returns:
True
if the training loop should be stopped.- Return type:
bool
- __init__(check_trigger=(1, 'epoch'), monitor='main/loss', patience=3, mode='auto', verbose=False, max_trigger=(100, 'epoch'))#
- Parameters:
check_trigger (TriggerLike) –
monitor (str) –
patience (int) –
mode (str) –
verbose (bool) –
max_trigger (Tuple[int, UnitLiteral]) –
- Return type:
None
- get_training_length()#
- Return type:
Tuple[float, str]
- may_fire(iteration, epoch_length)#
Flags if the trigger may fire at the current iteration
This must not alter the trigger state
- Parameters:
iteration (int) –
epoch_length (int) –
- Return type:
bool