# composer.callbacks.early_stopper#

Early stopping callback.

Classes

 EarlyStopper This callback tracks a training or evaluation metric and halts training if the metric does not improve within a given interval.
class composer.callbacks.early_stopper.EarlyStopper(monitor, dataloader_label, comp=None, min_delta=0.0, patience=1)[source]#

This callback tracks a training or evaluation metric and halts training if the metric does not improve within a given interval.

Example

>>> from composer.callbacks.early_stopper import EarlyStopper
>>> from torchmetrics.classification.accuracy import Accuracy
>>> # constructing trainer object with this callback
>>> early_stopper = EarlyStopper("Accuracy", "my_evaluator", patience=1)
>>> evaluator = Evaluator(
...     label = 'my_evaluator',
...     metrics = Accuracy()
... )
>>> trainer = Trainer(
...     model=model,
...     optimizers=optimizer,
...     max_duration="1ep",
...     callbacks=[early_stopper],
... )

Parameters
• monitor (str) – The name of the metric to monitor.

• dataloader_label (str) – The label of the dataloader or evaluator associated with the tracked metric. If monitor is in an Evaluator, the dataloader_label field should be set to the Evaluator’s label. If monitor is a training metric or an ordinary evaluation metric not in an Evaluator, dataloader_label should be set to ‘train’ or ‘eval’ respectively.

• comp (Union[str, Callable[[Any, Any], Any]], optional) – A comparison operator to measure change of the monitored metric. The comparison operator will be called comp(current_value, prev_best). For metrics where the optimal value is low (error, loss, perplexity), use a less than operator and for metrics like accuracy where the optimal value is higher, use a greater than operator. Defaults to torch.less() if loss, error, or perplexity are substrings of the monitored metric, otherwise defaults to torch.greater()

• min_delta (float, optional) – An optional float that requires a new value to exceed the best value by at least that amount. Defaults to 0.

• patience (int | str | Time, optional) – The interval of time the monitored metric can not improve without stopping training. Defaults to 1 epoch. If patience is an integer, it is interpreted as the number of epochs.