Skip to content
Merged
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `RichModelSummary` callback ([#9546](https://github.com/PyTorchLightning/pytorch-lightning/pull/9546))


- Added `enable_progress_bar` to Trainer constructor ([#9664](https://github.com/PyTorchLightning/pytorch-lightning/pull/9664))


- Added `pl_legacy_patch` load utility for loading old checkpoints that have pickled legacy Lightning attributes ([#9166](https://github.com/PyTorchLightning/pytorch-lightning/pull/9166))


Expand Down Expand Up @@ -262,7 +265,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Deprecated `LightningLoggerBase.close`, `LoggerCollection.close` in favor of `LightningLoggerBase.finalize`, `LoggerCollection.finalize` ([#9422](https://github.com/PyTorchLightning/pytorch-lightning/pull/9422))


- Deprecated passing `progress_bar_refresh_rate` to the `Trainer` constructor in favor of adding the `ProgressBar` callback with `refresh_rate` directly to the list of callbacks ([#9616](https://github.com/PyTorchLightning/pytorch-lightning/pull/9616))
- Deprecated passing `progress_bar_refresh_rate` to the `Trainer` constructor in favor of adding the `ProgressBar` callback with `refresh_rate` directly to the list of callbacks, or passing `enable_progress_bar=False` to disable the progress bar ([#9616](https://github.com/PyTorchLightning/pytorch-lightning/pull/9616))


### Removed
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_basic_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def lightning_loop(cls_model, idx, device_type: str = "cuda", num_epochs=10):
trainer = Trainer(
# as the first run is skipped, no need to run it long
max_epochs=num_epochs if idx > 0 else 1,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
gpus=1 if device_type == "cuda" else 0,
checkpoint_callback=False,
Expand Down
17 changes: 17 additions & 0 deletions docs/source/common/trainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,10 @@ See the :doc:`profiler documentation <../advanced/profiler>`. for more details.

progress_bar_refresh_rate
^^^^^^^^^^^^^^^^^^^^^^^^^
``progress_bar_refresh_rate`` has been deprecated in v1.5 and will be removed in v1.7.
Please pass :class:`~pytorch_lightning.callbacks.progress.ProgressBar` with ``refresh_rate``
directly to the Trainer's ``callbacks`` argument instead. To disable the progress bar,
pass ``enable_progress_bar = False`` to the Trainer.

.. raw:: html

Expand All @@ -1305,6 +1309,19 @@ Note:
Lightning will set it to 20 in these environments if the user does not provide a value.
- This argument is ignored if a custom callback is passed to :paramref:`~Trainer.callbacks`.

enable_progress_bar
^^^^^^^^^^^^^^^^^^^

Whether to enable or disable the progress bar. Defaults to True.

.. testcode::

# default used by the Trainer
trainer = Trainer(enable_progress_bar=True)

# disable progress bar
trainer = Trainer(enable_progress_bar=False)

reload_dataloaders_every_n_epochs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ def add_arguments_to_parser(self, parser):
{
"trainer.max_epochs": 15,
"trainer.weights_summary": None,
"trainer.progress_bar_refresh_rate": 1,
"trainer.num_sanity_val_steps": 0,
}
)
Expand Down
11 changes: 9 additions & 2 deletions pytorch_lightning/trainer/connectors/callback_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def on_trainer_init(
self,
callbacks: Optional[Union[List[Callback], Callback]],
checkpoint_callback: bool,
enable_progress_bar: bool,
progress_bar_refresh_rate: Optional[int],
process_position: int,
default_root_dir: Optional[str],
Expand Down Expand Up @@ -79,10 +80,16 @@ def on_trainer_init(
rank_zero_deprecation(
f"Setting `Trainer(progress_bar_refresh_rate={progress_bar_refresh_rate})` is deprecated in v1.5 and"
" will be removed in v1.7. Please pass `pytorch_lightning.callbacks.progress.ProgressBar` with"
" `refresh_rate` directly to the Trainer's `callbacks` argument instead."
" `refresh_rate` directly to the Trainer's `callbacks` argument instead. Or, to disable the progress"
" bar pass `enable_progress_bar = False` to the Trainer."
)

self.trainer._progress_bar_callback = self.configure_progress_bar(progress_bar_refresh_rate, process_position)
if enable_progress_bar:
self.trainer._progress_bar_callback = self.configure_progress_bar(
progress_bar_refresh_rate, process_position
)
else:
self.trainer._progress_bar_callback = None

# configure the ModelSummary callback
self._configure_model_summary_callback(weights_summary)
Expand Down
7 changes: 6 additions & 1 deletion pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(
ipus: Optional[int] = None,
log_gpu_memory: Optional[str] = None,
progress_bar_refresh_rate: Optional[int] = None, # TODO: remove in v1.7
enable_progress_bar: bool = True,
overfit_batches: Union[int, float] = 0.0,
track_grad_norm: Union[int, float, str] = -1,
check_val_every_n_epoch: int = 1,
Expand Down Expand Up @@ -285,7 +286,10 @@ def __init__(
.. deprecated:: v1.5
``progress_bar_refresh_rate`` has been deprecated in v1.5 and will be removed in v1.7.
Please pass :class:`~pytorch_lightning.callbacks.progress.ProgressBar` with ``refresh_rate``
directly to the Trainer's ``callbacks`` argument instead.
directly to the Trainer's ``callbacks`` argument instead. To disable the progress bar,
pass ``enable_progress_bar = False`` to the Trainer.

enable_progress_bar: Whether to enable to progress bar by default.

profiler: To profile individual steps during training and assist in identifying bottlenecks.

Expand Down Expand Up @@ -450,6 +454,7 @@ def __init__(
self.callback_connector.on_trainer_init(
callbacks,
checkpoint_callback,
enable_progress_bar,
progress_bar_refresh_rate,
process_position,
default_root_dir,
Expand Down
4 changes: 2 additions & 2 deletions tests/accelerators/test_ddp_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_multi_gpu_model_ddp_spawn(tmpdir):
limit_val_batches=10,
gpus=[0, 1],
accelerator="ddp_spawn",
progress_bar_refresh_rate=0,
enable_progress_bar=False,
)

model = BoringModel()
Expand All @@ -73,7 +73,7 @@ def test_ddp_all_dataloaders_passed_to_fit(tmpdir):

trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
max_epochs=1,
limit_train_batches=0.2,
limit_val_batches=0.2,
Expand Down
2 changes: 1 addition & 1 deletion tests/accelerators/test_dp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_multi_gpu_model_dp(tmpdir):
limit_val_batches=10,
gpus=[0, 1],
accelerator="dp",
progress_bar_refresh_rate=0,
enable_progress_bar=False,
)

model = BoringModel()
Expand Down
6 changes: 2 additions & 4 deletions tests/callbacks/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def configure_callbacks(self):

model = TestModel()
trainer_options = dict(
default_root_dir=tmpdir, checkpoint_callback=False, fast_dev_run=True, progress_bar_refresh_rate=0
default_root_dir=tmpdir, checkpoint_callback=False, fast_dev_run=True, enable_progress_bar=False
)

def assert_expected_calls(_trainer, model_callback, trainer_callback):
Expand Down Expand Up @@ -86,9 +86,7 @@ def configure_callbacks(self):
return [model_callback_mock]

model = TestModel()
trainer = Trainer(
default_root_dir=tmpdir, fast_dev_run=True, checkpoint_callback=False, progress_bar_refresh_rate=1
)
trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True, checkpoint_callback=False)

callbacks_before_fit = trainer.callbacks.copy()
assert callbacks_before_fit
Expand Down
6 changes: 3 additions & 3 deletions tests/callbacks/test_early_stopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def validation_epoch_end(self, outputs):
callbacks=[early_stop_callback],
num_sanity_val_steps=0,
max_epochs=10,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
)
trainer.fit(model)
assert trainer.current_epoch == expected_stop_epoch
Expand Down Expand Up @@ -177,7 +177,7 @@ def training_epoch_end(self, outputs):
callbacks=[early_stop_callback],
num_sanity_val_steps=0,
max_epochs=10,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
)
trainer.fit(model)
assert trainer.current_epoch == expected_stop_epoch
Expand Down Expand Up @@ -444,7 +444,7 @@ def validation_step(self, batch, batch_idx):
default_root_dir=tmpdir,
limit_val_batches=1,
callbacks=EarlyStopping(monitor="foo"),
progress_bar_refresh_rate=0,
enable_progress_bar=False,
**kwargs,
)

Expand Down
4 changes: 2 additions & 2 deletions tests/callbacks/test_finetuning_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def forward(self, x):
limit_train_batches=1,
limit_val_batches=1,
max_epochs=2,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
callbacks=[ckpt, BackboneFinetuning(unfreeze_backbone_at_epoch=1)],
)
trainer.fit(BackboneBoringModel())
Expand All @@ -436,7 +436,7 @@ def forward(self, x):
limit_train_batches=1,
limit_val_batches=1,
max_epochs=3,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
callbacks=BackboneFinetuning(unfreeze_backbone_at_epoch=1),
resume_from_checkpoint=ckpt.last_model_path,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/callbacks/test_lr_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def configure_optimizers(self):
limit_val_batches=0.1,
limit_train_batches=0.5,
callbacks=[lr_monitor],
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
)
trainer.fit(TestModel())
Expand All @@ -272,7 +272,7 @@ def configure_optimizers(self):
limit_val_batches=2,
limit_train_batches=2,
callbacks=[lr_monitor],
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
)
trainer.fit(TestModel())
Expand Down Expand Up @@ -310,7 +310,7 @@ def configure_optimizers(self):
limit_val_batches=2,
limit_train_batches=2,
callbacks=[lr_monitor],
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
)

Expand Down Expand Up @@ -388,7 +388,7 @@ def finetune_function(self, pl_module, epoch: int, optimizer, opt_idx: int):
limit_val_batches=0,
limit_train_batches=2,
callbacks=[TestFinetuning(), lr_monitor, Check()],
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
checkpoint_callback=False,
)
Expand Down
14 changes: 11 additions & 3 deletions tests/callbacks/test_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,19 @@ def test_progress_bar_on(tmpdir, callbacks: list, refresh_rate: Optional[int]):
assert progress_bars[0] is trainer.progress_bar_callback


@pytest.mark.parametrize("callbacks,refresh_rate", [([], 0), ([], False), ([ModelCheckpoint(dirpath="../trainer")], 0)])
def test_progress_bar_off(tmpdir, callbacks: list, refresh_rate: Union[bool, int]):
@pytest.mark.parametrize(
"callbacks,refresh_rate,enable_progress_bar",
[([], 0, True), ([], False, True), ([ModelCheckpoint(dirpath="../trainer")], 0, True), ([], 1, False)],
)
def test_progress_bar_off(tmpdir, callbacks: list, refresh_rate: Union[bool, int], enable_progress_bar: bool):
"""Test different ways the progress bar can be turned off."""

trainer = Trainer(default_root_dir=tmpdir, callbacks=callbacks, progress_bar_refresh_rate=refresh_rate)
trainer = Trainer(
default_root_dir=tmpdir,
callbacks=callbacks,
progress_bar_refresh_rate=refresh_rate,
enable_progress_bar=enable_progress_bar,
)

progress_bars = [c for c in trainer.callbacks if isinstance(c, ProgressBar)]
assert 0 == len(progress_bars)
Expand Down
8 changes: 4 additions & 4 deletions tests/callbacks/test_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def train_with_pruning_callback(

trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
checkpoint_callback=False,
logger=False,
Expand Down Expand Up @@ -225,7 +225,7 @@ def apply_lottery_ticket_hypothesis(self):
)
trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
checkpoint_callback=False,
logger=False,
Expand All @@ -252,7 +252,7 @@ def test_multiple_pruning_callbacks(tmpdir, caplog, make_pruning_permanent: bool

trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
weights_summary=None,
checkpoint_callback=False,
logger=False,
Expand Down Expand Up @@ -321,7 +321,7 @@ def on_save_checkpoint(self, trainer, pl_module, checkpoint):
ckpt_callback = ModelCheckpoint(
monitor="test", save_top_k=2, save_last=True, save_on_train_epoch_end=save_on_train_epoch_end
)
trainer = Trainer(callbacks=[pruning_callback, ckpt_callback], max_epochs=3, progress_bar_refresh_rate=0)
trainer = Trainer(callbacks=[pruning_callback, ckpt_callback], max_epochs=3, enable_progress_bar=False)
with caplog.at_level(INFO):
trainer.fit(model)

Expand Down
2 changes: 1 addition & 1 deletion tests/callbacks/test_stochastic_weight_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def train_with_swa(

trainer = Trainer(
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
max_epochs=max_epochs,
limit_train_batches=5,
limit_val_batches=0,
Expand Down
4 changes: 2 additions & 2 deletions tests/checkpointing/test_checkpoint_callback_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_default_checkpoint_freq(save_mock, tmpdir, epochs: int, val_check_inter
weights_summary=None,
val_check_interval=val_check_interval,
limit_val_batches=1,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
)
trainer.fit(model)

Expand Down Expand Up @@ -119,7 +119,7 @@ def training_epoch_end(self, outputs) -> None:
trainer = Trainer(
callbacks=[callbacks.ModelCheckpoint(dirpath=tmpdir, monitor="my_loss_step", save_top_k=k, mode="max")],
default_root_dir=tmpdir,
progress_bar_refresh_rate=0,
enable_progress_bar=False,
max_epochs=epochs,
weights_summary=None,
val_check_interval=val_check_interval,
Expand Down
Loading