From 772ebff4a2973f9c7ea5852a62f11d2103c09eaf Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 8 Jan 2022 21:13:59 -0800 Subject: [PATCH 01/41] Move progress bar disabling out of the Trainer --- pytorch_lightning/callbacks/progress/base.py | 1 + pytorch_lightning/trainer/trainer.py | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 4808bd39629e1..6d1f75f206c60 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -159,6 +159,7 @@ def print(self, *args, **kwargs): def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer + self.enable() if trainer.is_global_zero else self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: r""" diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index ea3cab325bbd6..50939adbdbc78 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -1278,9 +1278,6 @@ def _pre_training_routine(self): def _run_train(self) -> None: self._pre_training_routine() - if not self.is_global_zero and self.progress_bar_callback is not None: - self.progress_bar_callback.disable() - self._run_sanity_check() # enable train mode @@ -1292,9 +1289,6 @@ def _run_train(self) -> None: self.fit_loop.run() def _run_evaluate(self) -> _EVALUATE_OUTPUT: - if not self.is_global_zero and self.progress_bar_callback is not None: - self.progress_bar_callback.disable() - assert self.evaluating # reload dataloaders From 9e85570a7e96c1f95e4e6bea8256eb8b08dbd8fa Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 8 Jan 2022 22:36:23 -0800 Subject: [PATCH 02/41] fix test --- pytorch_lightning/callbacks/progress/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 6d1f75f206c60..2b09a031f5179 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -159,7 +159,8 @@ def print(self, *args, **kwargs): def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer - self.enable() if trainer.is_global_zero else self.disable() + if not trainer.is_global_zero: + self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: r""" From c5b4c49ad938461bfa6752b027ff1acb9ff0b1c3 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 9 Jan 2022 23:12:57 -0800 Subject: [PATCH 03/41] add test and update changelog --- CHANGELOG.md | 3 ++ pytorch_lightning/callbacks/progress/base.py | 6 +--- tests/callbacks/test_tqdm_progress_bar.py | 31 +++++++++++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e2bde5be2d0b..7b9dc4861d20d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -410,6 +410,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed the lr-scheduler state not being dumped to checkpoint when using the deepspeed strategy ([#11307](https://github.com/PyTorchLightning/pytorch-lightning/pull/11307)) +- Fixed bug where progress bar was not being disabled when not in rank zero during predict ([#11377](https://github.com/PyTorchLightning/pytorch-lightning/pull/11377)) + + ## [1.5.8] - 2022-01-05 ### Fixed diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 2b09a031f5179..6655c9665bd77 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -137,11 +137,7 @@ def total_predict_batches(self) -> int: return sum(self.trainer.num_predict_batches) def disable(self): - """You should provide a way to disable the progress bar. - - The :class:`~pytorch_lightning.trainer.trainer.Trainer` will call this to disable the - output on processes that have a rank different from 0, e.g., in multi-node training. - """ + """You should provide a way to disable the progress bar.""" raise NotImplementedError def enable(self): diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 00f325976182a..541935809c214 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -17,7 +17,7 @@ from collections import defaultdict from typing import Union from unittest import mock -from unittest.mock import ANY, call +from unittest.mock import ANY, call, PropertyMock import pytest import torch @@ -619,3 +619,32 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] + + +@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): + """Test that the progress bar is disabled when not in global rank zero.""" + progress_bar = TQDMProgressBar() + model = BoringModel() + trainer = Trainer( + default_root_dir=tmpdir, + callbacks=[progress_bar], + fast_dev_run=True, + ) + is_global_zero.return_value = False + + progress_bar.enable() + trainer.fit(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled From 7ff1dc8baf14575f4db3b9f8819ab922f778cd01 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Tue, 11 Jan 2022 21:52:18 -0800 Subject: [PATCH 04/41] fix docstring --- pytorch_lightning/callbacks/progress/base.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 22d8ee9a35857..848e535b80c12 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -131,11 +131,7 @@ def total_predict_batches(self) -> Union[int, float]: return sum(self.trainer.num_predict_batches) def disable(self) -> None: - """You should provide a way to disable the progress bar. - - The :class:`~pytorch_lightning.trainer.trainer.Trainer` will call this to disable the - output on processes that have a rank different from 0, e.g., in multi-node training. - """ + """You should provide a way to disable the progress bar.""" raise NotImplementedError def enable(self) -> None: From 31a6e8f9275a6ee121cb85ebcb2028dbc7b0db79 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Fri, 14 Jan 2022 18:08:45 -0800 Subject: [PATCH 05/41] test debug --- tests/checkpointing/test_model_checkpoint.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/checkpointing/test_model_checkpoint.py b/tests/checkpointing/test_model_checkpoint.py index 0371d02d4b26b..179543d170f3e 100644 --- a/tests/checkpointing/test_model_checkpoint.py +++ b/tests/checkpointing/test_model_checkpoint.py @@ -151,7 +151,6 @@ def on_validation_epoch_end(self): limit_train_batches=limit_train_batches, limit_val_batches=limit_val_batches, max_epochs=max_epochs, - enable_progress_bar=False, ) calls = mock_training_epoch_loop(trainer) trainer.fit(model) From 1de162a38b4df583f13ccc2bbab0a156f1f6b0af Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Fri, 14 Jan 2022 18:30:27 -0800 Subject: [PATCH 06/41] debug 2 --- pytorch_lightning/trainer/trainer.py | 6 ++++++ tests/checkpointing/test_model_checkpoint.py | 1 + 2 files changed, 7 insertions(+) diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index cb423dfa18c9e..39cadb7f9e7ef 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -1291,6 +1291,9 @@ def _pre_training_routine(self): def _run_train(self) -> None: self._pre_training_routine() + if not self.is_global_zero and self.progress_bar_callback is not None: + self.progress_bar_callback.disable() + self._run_sanity_check() # enable train mode @@ -1302,6 +1305,9 @@ def _run_train(self) -> None: self.fit_loop.run() def _run_evaluate(self) -> _EVALUATE_OUTPUT: + if not self.is_global_zero and self.progress_bar_callback is not None: + self.progress_bar_callback.disable() + assert self.evaluating # reload dataloaders diff --git a/tests/checkpointing/test_model_checkpoint.py b/tests/checkpointing/test_model_checkpoint.py index 179543d170f3e..0371d02d4b26b 100644 --- a/tests/checkpointing/test_model_checkpoint.py +++ b/tests/checkpointing/test_model_checkpoint.py @@ -151,6 +151,7 @@ def on_validation_epoch_end(self): limit_train_batches=limit_train_batches, limit_val_batches=limit_val_batches, max_epochs=max_epochs, + enable_progress_bar=False, ) calls = mock_training_epoch_loop(trainer) trainer.fit(model) From e3cb7de196e82e2d28ba798b57e346ee2a2ec440 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 15 Jan 2022 00:45:52 -0800 Subject: [PATCH 07/41] debug rich --- pytorch_lightning/callbacks/progress/base.py | 4 ++-- pytorch_lightning/callbacks/progress/rich_progress.py | 4 ++++ pytorch_lightning/trainer/trainer.py | 6 ------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 5c35bf122bf0f..7a03ee4741030 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -149,8 +149,8 @@ def print(self, *args: Any, **kwargs: Any) -> None: def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer - if not trainer.is_global_zero: - self.disable() + # if not trainer.is_global_zero: + # self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: r""" diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 570c6d7df669c..f9b395d869892 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -246,6 +246,10 @@ def __init__( self._progress_stopped: bool = False self.theme = theme + def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: + if not trainer.is_global_zero: + self.disable() + @property def refresh_rate(self) -> float: return self._refresh_rate diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index 39cadb7f9e7ef..cb423dfa18c9e 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -1291,9 +1291,6 @@ def _pre_training_routine(self): def _run_train(self) -> None: self._pre_training_routine() - if not self.is_global_zero and self.progress_bar_callback is not None: - self.progress_bar_callback.disable() - self._run_sanity_check() # enable train mode @@ -1305,9 +1302,6 @@ def _run_train(self) -> None: self.fit_loop.run() def _run_evaluate(self) -> _EVALUATE_OUTPUT: - if not self.is_global_zero and self.progress_bar_callback is not None: - self.progress_bar_callback.disable() - assert self.evaluating # reload dataloaders From 70ef542f7248270f3e7611e78fd3c4b164944667 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 15 Jan 2022 01:01:05 -0800 Subject: [PATCH 08/41] debug rich 2 --- pytorch_lightning/callbacks/progress/rich_progress.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index f9b395d869892..be8c02a1aba79 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -247,6 +247,7 @@ def __init__( self.theme = theme def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: + super().setup(trainer, pl_module, stage) if not trainer.is_global_zero: self.disable() From 2ead1a1d1fb516bbd75be4c1dafc973224d5a46c Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 15 Jan 2022 13:54:34 -0800 Subject: [PATCH 09/41] debug tqdm --- pytorch_lightning/callbacks/progress/tqdm_progress.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pytorch_lightning/callbacks/progress/tqdm_progress.py b/pytorch_lightning/callbacks/progress/tqdm_progress.py index 95c5666957635..802d7cc2818b2 100644 --- a/pytorch_lightning/callbacks/progress/tqdm_progress.py +++ b/pytorch_lightning/callbacks/progress/tqdm_progress.py @@ -111,6 +111,11 @@ def __init__(self, refresh_rate: int = 1, process_position: int = 0): self._test_progress_bar: Optional[_tqdm] = None self._predict_progress_bar: Optional[_tqdm] = None + def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: + super().setup(trainer, pl_module, stage) + if not trainer.is_global_zero: + self.disable() + def __getstate__(self) -> Dict: # can't pickle the tqdm objects return {k: v if not isinstance(v, _tqdm) else None for k, v in vars(self).items()} From 03cd465802faff5ee6fbbf88ddf658a6447d4ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Sun, 16 Jan 2022 14:33:12 +0100 Subject: [PATCH 10/41] add missing import --- pytorch_lightning/callbacks/progress/rich_progress.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index be8c02a1aba79..1564a78bccf5c 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -16,6 +16,7 @@ from datetime import timedelta from typing import Any, Dict, Optional, Union +import pytorch_lightning as pl from pytorch_lightning.callbacks.progress.base import ProgressBarBase from pytorch_lightning.utilities.imports import _RICH_AVAILABLE From 68fc6e9b6ea1aef78fe6b8d1d99f0b42d5a0b90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Sun, 16 Jan 2022 14:34:40 +0100 Subject: [PATCH 11/41] update submodule --- _notebooks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_notebooks b/_notebooks index 0c325829101d5..290fb466de1fc 160000 --- a/_notebooks +++ b/_notebooks @@ -1 +1 @@ -Subproject commit 0c325829101d5a6ebf32ed99bbf5b09badf04a59 +Subproject commit 290fb466de1fcc2ac6025f74b56906592911e856 From 0f89745de1dec4f43709c340b46fcc6750225450 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 10:59:40 -0800 Subject: [PATCH 12/41] revert after debug --- pytorch_lightning/callbacks/progress/base.py | 4 ++-- pytorch_lightning/callbacks/progress/rich_progress.py | 5 ----- pytorch_lightning/callbacks/progress/tqdm_progress.py | 5 ----- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 7a03ee4741030..5c35bf122bf0f 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -149,8 +149,8 @@ def print(self, *args: Any, **kwargs: Any) -> None: def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer - # if not trainer.is_global_zero: - # self.disable() + if not trainer.is_global_zero: + self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: r""" diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index be8c02a1aba79..570c6d7df669c 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -246,11 +246,6 @@ def __init__( self._progress_stopped: bool = False self.theme = theme - def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: - super().setup(trainer, pl_module, stage) - if not trainer.is_global_zero: - self.disable() - @property def refresh_rate(self) -> float: return self._refresh_rate diff --git a/pytorch_lightning/callbacks/progress/tqdm_progress.py b/pytorch_lightning/callbacks/progress/tqdm_progress.py index 802d7cc2818b2..95c5666957635 100644 --- a/pytorch_lightning/callbacks/progress/tqdm_progress.py +++ b/pytorch_lightning/callbacks/progress/tqdm_progress.py @@ -111,11 +111,6 @@ def __init__(self, refresh_rate: int = 1, process_position: int = 0): self._test_progress_bar: Optional[_tqdm] = None self._predict_progress_bar: Optional[_tqdm] = None - def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: - super().setup(trainer, pl_module, stage) - if not trainer.is_global_zero: - self.disable() - def __getstate__(self) -> Dict: # can't pickle the tqdm objects return {k: v if not isinstance(v, _tqdm) else None for k, v in vars(self).items()} From b35b74193b9d1b670e4aedc842976e97a34e4dcb Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 11:04:15 -0800 Subject: [PATCH 13/41] fix import --- pytorch_lightning/callbacks/progress/rich_progress.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 6374d060313e6..570c6d7df669c 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -16,7 +16,6 @@ from datetime import timedelta from typing import Any, Dict, Optional, Union -import pytorch_lightning as pl from pytorch_lightning.callbacks.progress.base import ProgressBarBase from pytorch_lightning.utilities.imports import _RICH_AVAILABLE From d4d61d524321796695965fbebf317e1a6c55f415 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 11:20:32 -0800 Subject: [PATCH 14/41] remove mock patch --- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index f35a2f1008f90..2d3ac27673262 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,7 +620,7 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) +#@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() From ea1ee85fb481cdec790440f102eee50307660014 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 16 Jan 2022 19:21:52 +0000 Subject: [PATCH 15/41] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 2d3ac27673262..5d3388131c81c 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,7 +620,7 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -#@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) +# @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() From 670a2f494d2419ee589baf004b800995fc1801a6 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 11:48:53 -0800 Subject: [PATCH 16/41] debug change mock --- tests/callbacks/test_tqdm_progress_bar.py | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 2d3ac27673262..0acb78a2e3b49 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,8 +620,7 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -#@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): +def test_tqdm_progress_bar_disabled_when_not_rank_zero(tmpdir): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() model = BoringModel() @@ -630,20 +629,21 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): callbacks=[progress_bar], fast_dev_run=True, ) - is_global_zero.return_value = False + with mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) as is_global_zero: + is_global_zero.return_value = False - progress_bar.enable() - trainer.fit(model) - assert progress_bar.is_disabled + progress_bar.enable() + trainer.fit(model) + assert progress_bar.is_disabled - progress_bar.enable() - trainer.validate(model) - assert progress_bar.is_disabled + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled - progress_bar.enable() - trainer.test(model) - assert progress_bar.is_disabled + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled - progress_bar.enable() - trainer.predict(model) - assert progress_bar.is_disabled + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled From 3e87df1a4e3f7c7c027e8881ef2843d1b2bf53ac Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 12:46:39 -0800 Subject: [PATCH 17/41] comment out test --- tests/callbacks/test_tqdm_progress_bar.py | 55 ++++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 0acb78a2e3b49..4a070b4768dd4 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,30 +620,31 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -def test_tqdm_progress_bar_disabled_when_not_rank_zero(tmpdir): - """Test that the progress bar is disabled when not in global rank zero.""" - progress_bar = TQDMProgressBar() - model = BoringModel() - trainer = Trainer( - default_root_dir=tmpdir, - callbacks=[progress_bar], - fast_dev_run=True, - ) - with mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) as is_global_zero: - is_global_zero.return_value = False - - progress_bar.enable() - trainer.fit(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.validate(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.test(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.predict(model) - assert progress_bar.is_disabled +# @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) +# def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): +# """Test that the progress bar is disabled when not in global rank zero.""" +# progress_bar = TQDMProgressBar() +# model = BoringModel() +# trainer = Trainer( +# default_root_dir=tmpdir, +# callbacks=[progress_bar], +# fast_dev_run=True, +# ) + +# is_global_zero.return_value = False + +# progress_bar.enable() +# trainer.fit(model) +# assert progress_bar.is_disabled + +# progress_bar.enable() +# trainer.validate(model) +# assert progress_bar.is_disabled + +# progress_bar.enable() +# trainer.test(model) +# assert progress_bar.is_disabled + +# progress_bar.enable() +# trainer.predict(model) +# assert progress_bar.is_disabled From 36ecb926951e713c26ccfe56bb0878b8e90aff40 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 13:38:58 -0800 Subject: [PATCH 18/41] test debug --- tests/callbacks/test_tqdm_progress_bar.py | 54 +++++++++++------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 4a070b4768dd4..d165c31dc5720 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,31 +620,29 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -# @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock) -# def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): -# """Test that the progress bar is disabled when not in global rank zero.""" -# progress_bar = TQDMProgressBar() -# model = BoringModel() -# trainer = Trainer( -# default_root_dir=tmpdir, -# callbacks=[progress_bar], -# fast_dev_run=True, -# ) - -# is_global_zero.return_value = False - -# progress_bar.enable() -# trainer.fit(model) -# assert progress_bar.is_disabled - -# progress_bar.enable() -# trainer.validate(model) -# assert progress_bar.is_disabled - -# progress_bar.enable() -# trainer.test(model) -# assert progress_bar.is_disabled - -# progress_bar.enable() -# trainer.predict(model) -# assert progress_bar.is_disabled +@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): + """Test that the progress bar is disabled when not in global rank zero.""" + progress_bar = TQDMProgressBar() + model = BoringModel() + trainer = Trainer( + default_root_dir=tmpdir, + callbacks=[progress_bar], + fast_dev_run=True, + ) + + progress_bar.enable() + trainer.fit(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled From 36a8bdf72f5003efea1a61e642496829bbc8f75e Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 13:55:59 -0800 Subject: [PATCH 19/41] move test --- tests/callbacks/test_tqdm_progress_bar.py | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index d165c31dc5720..2f85e4a672d94 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -558,6 +558,34 @@ def get_metrics(self, trainer: Trainer, model: LightningModule): assert "v_num" not in standard_metrics.keys() +@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): + """Test that the progress bar is disabled when not in global rank zero.""" + progress_bar = TQDMProgressBar() + model = BoringModel() + trainer = Trainer( + default_root_dir=tmpdir, + callbacks=[progress_bar], + fast_dev_run=True, + ) + + progress_bar.enable() + trainer.fit(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled + + def test_tqdm_progress_bar_correct_value_epoch_end(tmpdir): class MockedProgressBar(TQDMProgressBar): calls = defaultdict(list) @@ -618,31 +646,3 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] - - -@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): - """Test that the progress bar is disabled when not in global rank zero.""" - progress_bar = TQDMProgressBar() - model = BoringModel() - trainer = Trainer( - default_root_dir=tmpdir, - callbacks=[progress_bar], - fast_dev_run=True, - ) - - progress_bar.enable() - trainer.fit(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.validate(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.test(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.predict(model) - assert progress_bar.is_disabled From 2ccb27a4ab5e535d8471d988f6f021419e6069cc Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sun, 16 Jan 2022 14:32:48 -0800 Subject: [PATCH 20/41] reset mock --- tests/callbacks/test_tqdm_progress_bar.py | 58 ++++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 2f85e4a672d94..9a70a92c76327 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -558,34 +558,6 @@ def get_metrics(self, trainer: Trainer, model: LightningModule): assert "v_num" not in standard_metrics.keys() -@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): - """Test that the progress bar is disabled when not in global rank zero.""" - progress_bar = TQDMProgressBar() - model = BoringModel() - trainer = Trainer( - default_root_dir=tmpdir, - callbacks=[progress_bar], - fast_dev_run=True, - ) - - progress_bar.enable() - trainer.fit(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.validate(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.test(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.predict(model) - assert progress_bar.is_disabled - - def test_tqdm_progress_bar_correct_value_epoch_end(tmpdir): class MockedProgressBar(TQDMProgressBar): calls = defaultdict(list) @@ -646,3 +618,33 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] + + +@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): + """Test that the progress bar is disabled when not in global rank zero.""" + progress_bar = TQDMProgressBar() + model = BoringModel() + trainer = Trainer( + default_root_dir=tmpdir, + callbacks=[progress_bar], + fast_dev_run=True, + ) + + progress_bar.enable() + trainer.fit(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled + + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled + + is_global_zero.reset_mock() From e60e2b973bc79c7a0da6276cad35e090e74516c7 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Mon, 17 Jan 2022 09:07:26 -0800 Subject: [PATCH 21/41] add standalone --- tests/callbacks/test_tqdm_progress_bar.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 9a70a92c76327..5fde9d6097feb 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -619,7 +619,7 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] - +@RunIf(standalone=True) @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): """Test that the progress bar is disabled when not in global rank zero.""" @@ -646,5 +646,3 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): progress_bar.enable() trainer.predict(model) assert progress_bar.is_disabled - - is_global_zero.reset_mock() From 2f48e6cfa886b6910d928f00721762285ef45872 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Jan 2022 17:08:43 +0000 Subject: [PATCH 22/41] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/callbacks/test_tqdm_progress_bar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 5fde9d6097feb..57ad78cdad365 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -619,6 +619,7 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] + @RunIf(standalone=True) @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): From de98fd89a4d9739896b1bd8fee3840e25afa2a7c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 15:46:35 +0000 Subject: [PATCH 23/41] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d3cfe93f24ab..59f8a2b67d888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -431,10 +431,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed the lr-scheduler state not being dumped to checkpoint when using the deepspeed strategy ([#11307](https://github.com/PyTorchLightning/pytorch-lightning/pull/11307)) - + - Fixed bug where progress bar was not being disabled when not in rank zero during predict ([#11377](https://github.com/PyTorchLightning/pytorch-lightning/pull/11377)) - + - Disbled sampler replacement when using `IterableDataset` ([#11507](https://github.com/PyTorchLightning/pytorch-lightning/pull/11507)) From 39453a4a3d85ddfa55d3292cfa978868d3725731 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Thu, 20 Jan 2022 12:18:37 -0800 Subject: [PATCH 24/41] remove standalone --- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 5fde9d6097feb..d165c31dc5720 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -619,7 +619,7 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] -@RunIf(standalone=True) + @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): """Test that the progress bar is disabled when not in global rank zero.""" From 72c9ea29a9643394800e90b3194538bc909b4e3c Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Thu, 20 Jan 2022 13:56:22 -0800 Subject: [PATCH 25/41] action-tmate debug --- .github/workflows/ci_test-conda.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci_test-conda.yml b/.github/workflows/ci_test-conda.yml index fa366e645f1d9..8fbae76ab70c4 100644 --- a/.github/workflows/ci_test-conda.yml +++ b/.github/workflows/ci_test-conda.yml @@ -70,3 +70,7 @@ jobs: flags: cpu,pytest,torch${{ matrix.pytorch-version }} name: CPU-coverage fail_ci_if_error: false + + - name: Setup tmate session + if: always() + uses: mxschmitt/action-tmate@v3 From 0b081852f7774722e6475a1197886b0c35432ec2 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 11:51:09 -0800 Subject: [PATCH 26/41] remove tmpdir --- .github/workflows/ci_test-conda.yml | 2 ++ tests/callbacks/test_tqdm_progress_bar.py | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_test-conda.yml b/.github/workflows/ci_test-conda.yml index 8fbae76ab70c4..afb6651994213 100644 --- a/.github/workflows/ci_test-conda.yml +++ b/.github/workflows/ci_test-conda.yml @@ -74,3 +74,5 @@ jobs: - name: Setup tmate session if: always() uses: mxschmitt/action-tmate@v3 + with: + sudo: false diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index d165c31dc5720..4d263f4aa8c0c 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -619,14 +619,12 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] - @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero, tmpdir): +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() model = BoringModel() trainer = Trainer( - default_root_dir=tmpdir, callbacks=[progress_bar], fast_dev_run=True, ) From d26267798571eaa9368ed8e126666c75b1daa358 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jan 2022 19:52:25 +0000 Subject: [PATCH 27/41] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/callbacks/test_tqdm_progress_bar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 4d263f4aa8c0c..a22d514e40a43 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -619,6 +619,7 @@ def test_step(self, batch, batch_idx): trainer.test(model, verbose=False) assert pbar.calls["test"] == [] + @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): """Test that the progress bar is disabled when not in global rank zero.""" From d4303d1c504ecc1f020898a76d372224ce6a91ba Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 14:15:38 -0800 Subject: [PATCH 28/41] comment out test contents --- tests/callbacks/test_tqdm_progress_bar.py | 45 ++++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 4d263f4aa8c0c..f9e02a266258e 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -622,25 +622,26 @@ def test_step(self, batch, batch_idx): @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): """Test that the progress bar is disabled when not in global rank zero.""" - progress_bar = TQDMProgressBar() - model = BoringModel() - trainer = Trainer( - callbacks=[progress_bar], - fast_dev_run=True, - ) - - progress_bar.enable() - trainer.fit(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.validate(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.test(model) - assert progress_bar.is_disabled - - progress_bar.enable() - trainer.predict(model) - assert progress_bar.is_disabled + pass + # progress_bar = TQDMProgressBar() + # model = BoringModel() + # trainer = Trainer( + # callbacks=[progress_bar], + # fast_dev_run=True, + # ) + + # progress_bar.enable() + # trainer.fit(model) + # assert progress_bar.is_disabled + + # progress_bar.enable() + # trainer.validate(model) + # assert progress_bar.is_disabled + + # progress_bar.enable() + # trainer.test(model) + # assert progress_bar.is_disabled + + # progress_bar.enable() + # trainer.predict(model) + # assert progress_bar.is_disabled From f0b975e0b7c76df8ac9e884241b7f261bb48a1f0 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 14:57:02 -0800 Subject: [PATCH 29/41] debug --- .github/workflows/ci_test-conda.yml | 6 ------ tests/callbacks/test_tqdm_progress_bar.py | 13 ++++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci_test-conda.yml b/.github/workflows/ci_test-conda.yml index afb6651994213..fa366e645f1d9 100644 --- a/.github/workflows/ci_test-conda.yml +++ b/.github/workflows/ci_test-conda.yml @@ -70,9 +70,3 @@ jobs: flags: cpu,pytest,torch${{ matrix.pytorch-version }} name: CPU-coverage fail_ci_if_error: false - - - name: Setup tmate session - if: always() - uses: mxschmitt/action-tmate@v3 - with: - sudo: false diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index e07aa07d669b8..f33fd128b5912 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -623,13 +623,12 @@ def test_step(self, batch, batch_idx): @mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): """Test that the progress bar is disabled when not in global rank zero.""" - pass - # progress_bar = TQDMProgressBar() - # model = BoringModel() - # trainer = Trainer( - # callbacks=[progress_bar], - # fast_dev_run=True, - # ) + progress_bar = TQDMProgressBar() + model = BoringModel() + trainer = Trainer( + callbacks=[progress_bar], + fast_dev_run=True, + ) # progress_bar.enable() # trainer.fit(model) From 35c2eed2ce868beb3d2669f4fcb80a323739cfbe Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 15:13:49 -0800 Subject: [PATCH 30/41] debug 2 --- tests/callbacks/test_tqdm_progress_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index f33fd128b5912..37be0af94e0de 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -630,8 +630,8 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): fast_dev_run=True, ) - # progress_bar.enable() - # trainer.fit(model) + progress_bar.enable() + trainer.fit(model) # assert progress_bar.is_disabled # progress_bar.enable() From 470b4c345cf2687b851151d09590e6a0a5768995 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 15:32:02 -0800 Subject: [PATCH 31/41] debug 3 --- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 37be0af94e0de..b8d506385c4b6 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -632,7 +632,7 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): progress_bar.enable() trainer.fit(model) - # assert progress_bar.is_disabled + assert progress_bar.is_disabled # progress_bar.enable() # trainer.validate(model) From 72789715ae77f9c6c8d98b63a23a9236b89907f4 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 16:01:31 -0800 Subject: [PATCH 32/41] debug 4 --- tests/callbacks/test_tqdm_progress_bar.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index b8d506385c4b6..c50b3154f4d1d 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -634,13 +634,13 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer.fit(model) assert progress_bar.is_disabled - # progress_bar.enable() - # trainer.validate(model) - # assert progress_bar.is_disabled + progress_bar.enable() + trainer.validate(model) + assert progress_bar.is_disabled - # progress_bar.enable() - # trainer.test(model) - # assert progress_bar.is_disabled + progress_bar.enable() + trainer.test(model) + assert progress_bar.is_disabled # progress_bar.enable() # trainer.predict(model) From 0d1d82f292492c1215449433fd06b1dda71cf517 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 16:54:38 -0800 Subject: [PATCH 33/41] add limit batches --- tests/callbacks/test_tqdm_progress_bar.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index c50b3154f4d1d..d6b05a106e8a8 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -627,6 +627,10 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): model = BoringModel() trainer = Trainer( callbacks=[progress_bar], + limit_train_batches=1, + limit_val_batches=1, + limit_test_batches=1, + limit_predict_batches=1, fast_dev_run=True, ) @@ -642,6 +646,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer.test(model) assert progress_bar.is_disabled - # progress_bar.enable() - # trainer.predict(model) - # assert progress_bar.is_disabled + progress_bar.enable() + trainer.predict(model) + assert progress_bar.is_disabled From 92dd0f15733e9e361acdf3adac32b6bbf9b7bd4c Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 17:12:09 -0800 Subject: [PATCH 34/41] debug --- tests/callbacks/test_tqdm_progress_bar.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index d6b05a106e8a8..1d95b6c9ec523 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -627,10 +627,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): model = BoringModel() trainer = Trainer( callbacks=[progress_bar], - limit_train_batches=1, - limit_val_batches=1, - limit_test_batches=1, - limit_predict_batches=1, fast_dev_run=True, ) @@ -648,4 +644,4 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): progress_bar.enable() trainer.predict(model) - assert progress_bar.is_disabled + # assert progress_bar.is_disabled From b644de8988caa780865cc83fa703fea87aa8cd88 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 18:00:39 -0800 Subject: [PATCH 35/41] enable_checkpointing=False --- tests/callbacks/test_tqdm_progress_bar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 1d95b6c9ec523..5187c7543e29b 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -628,6 +628,7 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer = Trainer( callbacks=[progress_bar], fast_dev_run=True, + enable_checkpointing=False, ) progress_bar.enable() @@ -644,4 +645,4 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): progress_bar.enable() trainer.predict(model) - # assert progress_bar.is_disabled + assert progress_bar.is_disabled From cf618d43d71bd30c8dc5139f7f0b7b697a7a04da Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 18:23:13 -0800 Subject: [PATCH 36/41] debug --- tests/callbacks/test_tqdm_progress_bar.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 5187c7543e29b..b34d2922da304 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -628,7 +628,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer = Trainer( callbacks=[progress_bar], fast_dev_run=True, - enable_checkpointing=False, ) progress_bar.enable() @@ -643,6 +642,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer.test(model) assert progress_bar.is_disabled - progress_bar.enable() + #progress_bar.enable() trainer.predict(model) - assert progress_bar.is_disabled + # assert progress_bar.is_disabled From bfaaefe405435fcd7c448d544edcf19f77762835 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 23 Jan 2022 02:24:32 +0000 Subject: [PATCH 37/41] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index b34d2922da304..6dcbf9629984e 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -642,6 +642,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer.test(model) assert progress_bar.is_disabled - #progress_bar.enable() + # progress_bar.enable() trainer.predict(model) # assert progress_bar.is_disabled From bbfaf2fca1caedabb805c08a19bb923f408a7d9c Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Sat, 22 Jan 2022 19:05:12 -0800 Subject: [PATCH 38/41] debug --- pytorch_lightning/callbacks/progress/base.py | 2 +- tests/callbacks/test_tqdm_progress_bar.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 5c35bf122bf0f..869159779b8da 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -149,7 +149,7 @@ def print(self, *args: Any, **kwargs: Any) -> None: def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer - if not trainer.is_global_zero: + if not trainer.is_global_zero and stage != "predict": self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index b34d2922da304..1d95b6c9ec523 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -642,6 +642,6 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): trainer.test(model) assert progress_bar.is_disabled - #progress_bar.enable() + progress_bar.enable() trainer.predict(model) # assert progress_bar.is_disabled From 22e5f3e107c138cffb416311f6ec0caf5fb3ca0c Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 2 Feb 2022 13:02:04 -0800 Subject: [PATCH 39/41] fix --- pytorch_lightning/callbacks/progress/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/base.py b/pytorch_lightning/callbacks/progress/base.py index 869159779b8da..5c35bf122bf0f 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -149,7 +149,7 @@ def print(self, *args: Any, **kwargs: Any) -> None: def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: Optional[str] = None) -> None: self._trainer = trainer - if not trainer.is_global_zero and stage != "predict": + if not trainer.is_global_zero: self.disable() def get_metrics(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> Dict[str, Union[int, str]]: From 3c7ea8c007e3da111a345662f071d4e2df77ab02 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 2 Feb 2022 13:49:49 -0800 Subject: [PATCH 40/41] mock global rank --- tests/callbacks/test_tqdm_progress_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index a22d514e40a43..8e8dbbdfb9221 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,8 +620,8 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): +@mock.patch("pytorch_lightning.strategies.strategy.Strategy.global_rank", new_callable=PropertyMock, return_value=1) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(global_rank): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() model = BoringModel() From 0dab6b9e64fbc3d954768531257c662a05804cd3 Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 2 Feb 2022 20:28:01 -0800 Subject: [PATCH 41/41] change order --- tests/callbacks/test_tqdm_progress_bar.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/callbacks/test_tqdm_progress_bar.py b/tests/callbacks/test_tqdm_progress_bar.py index 8e8dbbdfb9221..1b7faf8c3ae88 100644 --- a/tests/callbacks/test_tqdm_progress_bar.py +++ b/tests/callbacks/test_tqdm_progress_bar.py @@ -620,8 +620,8 @@ def test_step(self, batch, batch_idx): assert pbar.calls["test"] == [] -@mock.patch("pytorch_lightning.strategies.strategy.Strategy.global_rank", new_callable=PropertyMock, return_value=1) -def test_tqdm_progress_bar_disabled_when_not_rank_zero(global_rank): +@mock.patch("pytorch_lightning.trainer.trainer.Trainer.is_global_zero", new_callable=PropertyMock, return_value=False) +def test_tqdm_progress_bar_disabled_when_not_rank_zero(is_global_zero): """Test that the progress bar is disabled when not in global rank zero.""" progress_bar = TQDMProgressBar() model = BoringModel() @@ -635,13 +635,13 @@ def test_tqdm_progress_bar_disabled_when_not_rank_zero(global_rank): assert progress_bar.is_disabled progress_bar.enable() - trainer.validate(model) + trainer.predict(model) assert progress_bar.is_disabled progress_bar.enable() - trainer.test(model) + trainer.validate(model) assert progress_bar.is_disabled progress_bar.enable() - trainer.predict(model) + trainer.test(model) assert progress_bar.is_disabled