noether.core.callbacks.early_stoppers

Submodules

Exceptions

EarlyStopIteration

Custom StopIteration exception for Early Stoppers.

Classes

EarlyStopperBase

Base class for early stoppers that is used to define the interface for early stoppers used by the trainers.

FixedEarlyStopper

Early stopper (training) based on a fixed number of epochs, updates, or samples.

FixedEarlyStopperConfig

MetricEarlyStopper

Early stopper (training) based on a metric value to be monitored.

MetricEarlyStopperConfig

Internal base class for all registry-based configs.

Package Contents

exception noether.core.callbacks.early_stoppers.EarlyStopIteration

Bases: StopIteration

Custom StopIteration exception for Early Stoppers.

Initialize self. See help(type(self)) for accurate signature.

class noether.core.callbacks.early_stoppers.EarlyStopperBase(callback_config, trainer, model, data_container, tracker, log_writer, checkpoint_writer, metric_property_provider, name=None)

Bases: noether.core.callbacks.periodic.PeriodicCallback

Base class for early stoppers that is used to define the interface for early stoppers used by the trainers.

Parameters:
to_short_interval_string()

Convert the interval to a short string representation used for logging.

Return type:

str

periodic_callback(*, interval_type, update_counter, **kwargs)

Check if training should stop and raise exception if needed.

Parameters:
  • interval_type (noether.core.callbacks.periodic.IntervalType) – Type of interval that triggered this callback.

  • update_counter (noether.core.utils.training.UpdateCounter) – UpdateCounter instance with current training state.

  • **kwargs – Additional keyword arguments.

Raises:

EarlyStopIteration – If training should be stopped based on the stopping criterion.

Return type:

None

class noether.core.callbacks.early_stoppers.FixedEarlyStopper(callback_config, **kwargs)

Bases: noether.core.callbacks.early_stoppers.base.EarlyStopperBase

Early stopper (training) based on a fixed number of epochs, updates, or samples.

Example config:

- kind: noether.core.callbacks.FixedEarlyStopper
  stop_at_epoch: 10
  name: FixedEarlyStopper
Parameters:
  • callback_config (FixedEarlyStopperConfig) – The configuration for the callback. See FixedEarlyStopperConfig for available options.

  • **kwargs – Additional arguments to pass to the parent class.

stop_at_sample
stop_at_update
stop_at_epoch
class noether.core.callbacks.early_stoppers.FixedEarlyStopperConfig(/, **data)

Bases: pydantic.BaseModel

Parameters:

data (Any)

kind: str | None = None
name: Literal['FixedEarlyStopper'] = None
stop_at_sample: int | None = None
stop_at_update: int | None = None
stop_at_epoch: int | None = None
validate_callback_frequency()

Ensures that exactly one stop (‘stop_at_*’) is specified

Return type:

FixedEarlyStopperConfig

class noether.core.callbacks.early_stoppers.MetricEarlyStopper(callback_config, **kwargs)

Bases: noether.core.callbacks.early_stoppers.base.EarlyStopperBase

Early stopper (training) based on a metric value to be monitored.

Example config:

- kind: noether.core.callbacks.MetricEarlyStopper
  every_n_epochs: 1
  metric_key: loss/val/total
  tolerance: 0.10
  name: MetricEarlyStopper
Parameters:
  • callback_config (MetricEarlyStopperConfig) – Configuration for the callback. See MetricEarlyStopperConfig for available options including metric key and tolerance.

  • **kwargs – Additional arguments to pass to the parent class.

metric_key
higher_is_better
tolerance
tolerance_counter = 0
best_metric
class noether.core.callbacks.early_stoppers.MetricEarlyStopperConfig(/, **data)

Bases: noether.core.callbacks.base.CallBackBaseConfig

Internal base class for all registry-based configs.

Provides auto-registration via __init_subclass__. Not meant to be used directly - use specific config base classes instead.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

name: Literal['MetricEarlyStopper'] = None
metric_key: str

The key of the metric to monitor

tolerance: int

The number of times the metric can stagnate before stopping training

classmethod check_tolerance_positive(v)

Ensures that tolerance is at least 1.

Parameters:

v (int)

Return type:

int