Skip to content

Callbacks

callbacks

Callback (ABC)

Callback objects define events on which it will run during the model training cycle.

clean(self)

Clean up

on_epoch_cancel(self)

Called after epoch is cancelled

on_epoch_end(self)

Called after each epoch

on_epoch_start(self)

Called Before each Epoch

on_fit_cancel(self)

Called after model.fit(...)is cancelled

on_fit_end(self)

Called after model.fit(...)

on_fit_start(self)

Called on each model.fit(...)

on_forward_cancel(self)

Called after model.forward(...) is cancelled

on_forward_end(self)

Called after model.forward(...)

on_forward_start(self)

Called before model.forward(...)

on_train_epoch_cancel(self)

Called after training epoch is cancelled

on_train_epoch_end(self, *args, **kwargs)

Called after end of training epoch

on_train_epoch_start(self)

Called on start of training epoch

on_train_step_cancel(self)

Called after training step is cancelled

on_train_step_end(self, *args, **kwargs)

Called after training step

on_train_step_start(self)

called before train_step

on_val_epoch_cancel(self)

called after validation epoch cancelled

on_val_epoch_end(self, *args, **kwargs)

called after validation epoch ends

on_val_epoch_start(self)

Called on start of validation epoch

on_val_step_cancel(self)

Called after validation step is cancelled

on_val_step_end(self, *args, **kwargs)

Called after validation step

on_val_step_start(self)

Called on validation step

with_event(self, event_type, func, exception, final_fn=<function dummy at 0x7fe12c36f9d0>)

Calls a function with event wrapped around. Inspired from FastAI. Ref: https://github.com/fastai/fastai/blob/6e44b354f4d12bdfa2c9530f38f851c54a05764d/fastai/learner.py#L162

export

ModelCheckpoint (Callback)

__init__(self, filename=None, path='/home/docs/checkouts/readthedocs.org/user_builds/gradsflow/checkouts/latest', save_extra=False) special

Saves Model checkpoint

Parameters:

Name Type Description Default
filename Optional[str]

name of checkpoint

None
path str

folder path location of the model checkpoint

'/home/docs/checkouts/readthedocs.org/user_builds/gradsflow/checkouts/latest'
save_extra bool

whether to save extra details like tracker

False

on_epoch_end(self)

Called after each epoch

gpu

EmissionTrackerCallback (Callback)

Tracks the carbon emissions produced by deep neural networks using CodeCarbon. To use this callback first install codecarbon using pip install codecarbon. For offline use, you must have to specify the country code.

Parameters:

Name Type Description Default
offline

whether to use internet connection or not. You will have to provide the country code country_iso_code for offline use.

required
**kwargs

passed directly to codecarbon class.

required

on_fit_end(self)

Called after model.fit(...)

logger special

comet

CometCallback (Callback)

Comet Logging callback. To use this callback pip install comet-ml.

Parameters:

Name Type Description Default
project_name

Name of the Project

required
api_key

project API key

required
offline

log experiment offline

required
on_epoch_end(self)

Called after each epoch

on_fit_start(self)

Called on each model.fit(...)

on_train_epoch_start(self)

Called on start of training epoch

on_train_step_end(self, *args, **kwargs)

Called after training step

on_val_epoch_start(self)

Called on start of validation epoch

on_val_step_end(self, *args, **kwargs)

Called after validation step

logger

CSVLogger (Callback)

Saves Model training metrics as CSV

Parameters:

Name Type Description Default
filename

filename of the csv

required
path

folder path location of the csv

required
verbose

Whether to show output

required
on_epoch_end(self)

Called after each epoch

ModelCheckpoint (Callback)

Saves Model checkpoint

Parameters:

Name Type Description Default
filename

name of checkpoint

required
path

folder path location of the model checkpoint

required
save_extra

whether to save extra details like tracker

required
on_epoch_end(self)

Called after each epoch

progress

ProgressCallback (Callback)

clean(self)

Clean up

on_epoch_end(self)

Called after each epoch

on_fit_end(self)

Called after model.fit(...)

on_fit_start(self)

Called on each model.fit(...)

on_train_epoch_end(self, *args, **kwargs)

Called after end of training epoch

on_train_epoch_start(self)

Called on start of training epoch

on_train_step_end(self, *args, **kwargs)

Called after training step

on_val_epoch_end(self, *args, **kwargs)

called after validation epoch ends

on_val_epoch_start(self)

Called on start of validation epoch

on_val_step_end(self, *args, **kwargs)

Called after validation step

raytune

TorchTuneCheckpointCallback (Callback)

on_epoch_end(self)

Called after each epoch

TorchTuneReport (Callback)

on_epoch_end(self)

Called after each epoch

runner

CallbackRunner (Callback)

clean(self)

Remove all the callbacks except TrainEvalCallback added during model.fit

on_epoch_end(self)

Called after each epoch

on_epoch_start(self)

Called Before each Epoch

on_fit_end(self)

Called after model.fit(...)

on_fit_start(self)

Called on each model.fit(...)

on_forward_end(self)

Called after model.forward(...)

on_forward_start(self)

Called before model.forward(...)

on_train_epoch_end(self, *args, **kwargs)

Called after end of training epoch

on_train_epoch_start(self)

Called on start of training epoch

on_train_step_end(self, *args, **kwargs)

Called after training step

on_train_step_start(self)

called before train_step

on_val_epoch_end(self, *args, **kwargs)

called after validation epoch ends

on_val_epoch_start(self)

Called on start of validation epoch

on_val_step_end(self, *args, **kwargs)

Called after validation step

on_val_step_start(self)

Called on validation step

training

TrainEvalCallback (Callback)

on_train_epoch_start(self)

Called on start of training epoch

on_train_step_end(self, *args, **kwargs)

Called after training step

on_train_step_start(self)

called before train_step

on_val_epoch_start(self)

Called on start of validation epoch

on_val_step_end(self, *args, **kwargs)

Called after validation step


Last update: September 29, 2021