Shortcuts

ProgressBarBase

class pytorch_lightning.callbacks.ProgressBarBase[source]

Bases: pytorch_lightning.callbacks.base.Callback

The base class for progress bars in Lightning. It is a Callback that keeps track of the batch progress in the Trainer. You should implement your highly custom progress bars with this as the base class.

Example:

class LitProgressBar(ProgressBarBase):

    def __init__(self):
        super().__init__()  # don't forget this :)
        self.enable = True

    def disable(self):
        self.enable = False

    def on_train_batch_end(self, trainer, pl_module, outputs, batch_idx):
        super().on_train_batch_end(trainer, pl_module, outputs, batch_idx)  # don't forget this :)
        percent = (self.train_batch_idx / self.total_train_batches) * 100
        sys.stdout.flush()
        sys.stdout.write(f'{percent:.01f} percent complete \r')

bar = LitProgressBar()
trainer = Trainer(callbacks=[bar])
disable()[source]

You should provide a way to disable the progress bar.

The Trainer will call this to disable the output on processes that have a rank different from 0, e.g., in multi-node training.

enable()[source]

You should provide a way to enable the progress bar.

The Trainer will call this in e.g. pre-training routines like the learning rate finder to temporarily enable and disable the main progress bar.

get_metrics(trainer, pl_module)[source]

Combines progress bar metrics collected from the trainer with standard metrics from get_standard_metrics. Implement this to override the items displayed in the progress bar.

Here is an example of how to override the defaults:

def get_metrics(self, trainer, model):
    # don't show the version number
    items = super().get_metrics(trainer, model)
    items.pop("v_num", None)
    return items
Return type

Dict[str, Union[int, str]]

Returns

Dictionary with the items to be displayed in the progress bar.

on_init_end(trainer)[source]

Called when the trainer initialization ends, model has not yet been set.

on_predict_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx)[source]

Called when the predict batch ends.

on_predict_epoch_start(trainer, pl_module)[source]

Called when the predict epoch begins.

on_test_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx)[source]

Called when the test batch ends.

on_test_start(trainer, pl_module)[source]

Called when the test begins.

on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)[source]

Called when the train batch ends.

on_train_epoch_start(trainer, pl_module)[source]

Called when the train epoch begins.

on_train_start(trainer, pl_module)[source]

Called when the train begins.

on_validation_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx)[source]

Called when the validation batch ends.

on_validation_start(trainer, pl_module)[source]

Called when the validation loop begins.

print(*args, **kwargs)[source]

You should provide a way to print without breaking the progress bar.

property predict_batch_idx: int

The current batch index being processed during predicting.

Use this to update your progress bar.

Return type

int

property test_batch_idx: int

The current batch index being processed during testing.

Use this to update your progress bar.

Return type

int

property total_predict_batches: int

The total number of predicting batches during testing, which may change from epoch to epoch.

Use this to set the total number of iterations in the progress bar. Can return inf if the predict dataloader is of infinite size.

Return type

int

property total_test_batches: int

The total number of testing batches during testing, which may change from epoch to epoch.

Use this to set the total number of iterations in the progress bar. Can return inf if the test dataloader is of infinite size.

Return type

int

property total_train_batches: int

The total number of training batches during training, which may change from epoch to epoch.

Use this to set the total number of iterations in the progress bar. Can return inf if the training dataloader is of infinite size.

Return type

int

property total_val_batches: int

The total number of validation batches during validation, which may change from epoch to epoch.

Use this to set the total number of iterations in the progress bar. Can return inf if the validation dataloader is of infinite size.

Return type

int

property train_batch_idx: int

The current batch index being processed during training.

Use this to update your progress bar.

Return type

int

property val_batch_idx: int

The current batch index being processed during validation.

Use this to update your progress bar.

Return type

int