Skip to content

Callbacks

Callbacks can be used with the LightningCLI trainer to inject custom behavior into the training process. Callbacks are configured in the trainer section of the YAML configuration file.

We provide a few custom callbacks for common use cases, but many more are available in the Lightning ecosystem. Check the Trainer documentation for more details.

# Example Callback Configuration
trainer:
  callbacks:
  - class_path: modelgenerator.callbacks.PredictionWriter
    dict_kwargs:
      output_dir: my_predictions
      filetype: tsv
      write_cols:
        - id
        - prediction
        - label
model:
  ...
data:
  ...

modelgenerator.callbacks.PredictionWriter

Bases: Callback

Write batch predictions to files, and merge batch files into a single file at the end of the epoch. Note: When saving the given data to a TSV file, any tensors in the data will have their last dimension squeezed and converted into lists to ensure proper formatting for TSV output.

Parameters:

Name Type Description Default
output_dir str

Directory to save predictions.

required
filetype str

Type of outputfile. Options are 'tsv' and 'pt'.

required
write_cols list

The head columns of tsv file if filetype is set to 'tsv'. Defaults to None

None

modelgenerator.callbacks.FTScheduler

Bases: BaseFinetuning

Finetuning scheduler that gradually unfreezes layers based on a schedule

Parameters:

Name Type Description Default
ft_schedule_path str

Path to a finetuning schedule that mentions which modules to unfreeze at which epoch. See tutorial for examples.

required