--- title: Callbacks keywords: fastai sidebar: home_sidebar summary: "API details." ---

    %load_ext autoreload
    %autoreload 2
    %matplotlib inline

## `class` `TorchCallback`[source]

> `TorchCallback`()

## `class` `BasicConfig`[source]

> `BasicConfig`(`priority`=`0`) :: `TorchCallback`

Handles basic model tasks like putting the model on the GPU and switching between train and eval modes.

## `class` `StatsHandler`[source]

> `StatsHandler`(`priority`=`5`) :: `TorchCallback`

This updates metrics at the end of each epoch to account for potentially varying batch sizes.

## `class` `MetricPrinter`[source]

> `MetricPrinter`(`priority`=`10`) :: `TorchCallback`

Prints metrics at the end of each epoch. This is one of the default callbacks provided in BaseModel - it does not need to be passed in explicitly.

## `class` `EarlyStopper`[source]

> `EarlyStopper`(`goal`:`('max', 'min')`, `metric`=`'loss'`, `min_improvement`=`0.0`, `patience`=`3`, `priority`=`15`) :: `TorchCallback`

## `class` `PerformanceThreshold`[source]

> `PerformanceThreshold`(`metric`, `goal`:`('min', 'max')`, `threshold`, `skip_epochs`=`0`, `split`:`('train', 'val')`=`'val'`, `priority`=`15`) :: `TorchCallback`

## `class` `ModelCheckpoint`[source]

> `ModelCheckpoint`(`metric`=`'loss'`, `goal`:`('max', 'min')`=`'min'`, `priority`=`25`) :: `TorchCallback`

## `class` `MetricHistory`[source]

> `MetricHistory`(`fname`=`'history.csv'`, `plot_fname`=`'history.png'`, `priority`=`90`) :: `TorchCallback`

Separate from StatsHandler in case we don't want to log outputs.

## `class` `S3Uploader`[source]

> `S3Uploader`(`prefix`, `priority`=`95`) :: `TorchCallback`

Upload model and logs to S3 when training finishes.

## `class` `EC2Closer`[source]

> `EC2Closer`(`timeout`=`5`, `priority`=`100`) :: `TorchCallback`

## `class` `ModelUnfreezer`[source]

> `ModelUnfreezer`(`i2n`, `unfreeze_type`:`('groups', 'layers')`=`'groups'`, `mode`:`('batch', 'epoch')`=`'epoch'`, `priority`=`25`) :: `TorchCallback`

Gradually unfreeze a model during training.

## `class` `SchedulerMixin`[source]

> `SchedulerMixin`() :: `TorchCallback`

## `class` `CosineLRScheduler`[source]

> `CosineLRScheduler`(`warm`=`0.3`, `restarts`=`False`, `cycle_len`=`5`, `cycle_decay`=`0.0`, `min_lr`=`None`, `verbose`=`False`, `priority`=`10`) :: `SchedulerMixin`

Learning rate scheduler that makes updates each batch.