Lightning-AI/pytorch-lightning

`ProgressBar` created in `LightningModule.configure_callbacks` does not override default `ProgressBar`

Open

#16.990 geöffnet am 7. März 2023

Auf GitHub ansehen
 (3 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)Python (3.233 Forks)batch import
bugcallbackdiscussionhelp wanted

Repository-Metriken

Stars
 (26.687 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 9T 15h) (3 gemergte PRs in 30 T)

Beschreibung

Bug description

Currently, the only way to truly override the default progress bar is to pass one to the Trainer.__init__ using the callbacks kwarg. When a progress bar is created via LightningModule.configure_callbacks, it does not override the default progress bar and instead co-exists with it. This likely happens because the Trainer does not call _callback_connector.configure_progress_bar when calling LightningModule.configure_callbacks.

How to reproduce

  1. Create a LightningModule:
import pytorch_lightning as lightning

class MyModule(lightning.LightningModule):
    ...
    def training_step(self, batch, batch_idx):
        print("Callbacks:", list(self.trainer.callbacks))
        ...

    def configure_callbacks(self):
        return [ProgressBarBase()]

module = MyModule()
  1. Train without passing additional callbacks:
trainer = pl.Trainer()
trainer.fit(module)
  1. Both progress bars are in the callbacks as can be seen in the print we defined in training_step. Output will look something like this:
Callbacks: [TQDMProgressBar(), ProgressBarBase()]

Why is this a bug?

Passing multiple ProgressBars to Trainer.__init__ is prohibited with a MisconfigurationException. Having multiple ProgressBars in the way described above raises no error. It also causes weird output, because both progress bars are being updated.

cc @borda @awaelchli

Contributor Guide