From 9819f796ba6819060c2b0d492b44e553a33153d5 Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Tue, 19 Apr 2022 11:43:04 -0400 Subject: [PATCH 01/17] replace standard_metrics variable --- 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 42ad957235f2c..3801b971d58a9 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -220,7 +220,7 @@ def get_metrics(self, trainer, model): Return: Dictionary with the items to be displayed in the progress bar. """ - standard_metrics = pl_module.get_progress_bar_dict() + standard_metrics = standard_metrics = get_standard_metrics(trainer, pl_module) pbar_metrics = trainer.progress_bar_metrics duplicates = list(standard_metrics.keys() & pbar_metrics.keys()) if duplicates: From c1240875aa6997b8983715f94df2b3350d593886 Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Tue, 19 Apr 2022 11:45:37 -0400 Subject: [PATCH 02/17] remove get_progress_bar_dict from LightningModule --- pytorch_lightning/core/lightning.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 33ba4b2990e12..8153f26b04960 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -1731,35 +1731,6 @@ def unfreeze(self) -> None: self.train() - def get_progress_bar_dict(self) -> Dict[str, Union[int, str]]: - r""" - .. deprecated:: v1.5 - This method was deprecated in v1.5 in favor of - `pytorch_lightning.callbacks.progress.base.get_metrics` and will be removed in v1.7. - - Implement this to override the default items displayed in the progress bar. - By default it includes the average loss value, split index of BPTT (if used) - and the version of the experiment when using a logger. - - .. code-block:: - - Epoch 1: 4%|▎ | 40/1095 [00:03<01:37, 10.84it/s, loss=4.501, v_num=10] - - Here is an example how to override the defaults: - - .. code-block:: python - - def get_progress_bar_dict(self): - # don't show the version number - items = super().get_progress_bar_dict() - items.pop("v_num", None) - return items - - Return: - Dictionary with the items to be displayed in the progress bar. - """ - return progress_base.get_standard_metrics(self.trainer, self) - def _verify_is_manual_optimization(self, fn_name): if self.automatic_optimization: raise MisconfigurationException( From c4a0c23e2cd3851c6aab80ebff23af5e6620c2cd Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Tue, 19 Apr 2022 11:46:25 -0400 Subject: [PATCH 03/17] fix typo in standard_metrics --- 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 3801b971d58a9..91a662455545f 100644 --- a/pytorch_lightning/callbacks/progress/base.py +++ b/pytorch_lightning/callbacks/progress/base.py @@ -220,7 +220,7 @@ def get_metrics(self, trainer, model): Return: Dictionary with the items to be displayed in the progress bar. """ - standard_metrics = standard_metrics = get_standard_metrics(trainer, pl_module) + standard_metrics = get_standard_metrics(trainer, pl_module) pbar_metrics = trainer.progress_bar_metrics duplicates = list(standard_metrics.keys() & pbar_metrics.keys()) if duplicates: From 58fef2f6de20462821dd4ee4a545042540939b4d Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Thu, 21 Apr 2022 13:12:40 -0400 Subject: [PATCH 04/17] completely remove test --- tests/deprecated_api/test_remove_1-7.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 329f181ccb485..3e94b55367381 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -47,28 +47,6 @@ def test_v1_7_0_datamodule_transform_properties(tmpdir): _ = LightningDataModule(val_transforms="b") -def test_v1_7_0_moved_get_progress_bar_dict(tmpdir): - class TestModel(BoringModel): - def get_progress_bar_dict(self): - items = super().get_progress_bar_dict() - items.pop("v_num", None) - return items - - trainer = Trainer( - default_root_dir=tmpdir, - fast_dev_run=True, - ) - test_model = TestModel() - with pytest.deprecated_call(match=r"`LightningModule.get_progress_bar_dict` method was deprecated in v1.5"): - trainer.fit(test_model) - standard_metrics_postfix = trainer.progress_bar_callback.main_progress_bar.postfix - assert "loss" in standard_metrics_postfix - assert "v_num" not in standard_metrics_postfix - - with pytest.deprecated_call(match=r"`trainer.progress_bar_dict` is deprecated in v1.5"): - _ = trainer.progress_bar_dict - - def test_v1_7_0_deprecated_on_task_dataloader(tmpdir): class CustomBoringModel(BoringModel): def on_train_dataloader(self): From 378ed2b3a9b116cd4a6315756d18096c53424a88 Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Thu, 21 Apr 2022 13:15:43 -0400 Subject: [PATCH 05/17] remove from HookedModel --- tests/trainer/logging_/test_logger_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/trainer/logging_/test_logger_connector.py b/tests/trainer/logging_/test_logger_connector.py index bd8fe86141282..167648f9dacf7 100644 --- a/tests/trainer/logging_/test_logger_connector.py +++ b/tests/trainer/logging_/test_logger_connector.py @@ -194,7 +194,6 @@ def __init__(self, not_supported): "on_before_batch_transfer", "transfer_batch_to_device", "on_after_batch_transfer", - "get_progress_bar_dict", } ) # remove `nn.Module` hooks From e2875a0e31f2927504023ac16ac6599fae860dfd Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Thu, 21 Apr 2022 13:28:44 -0400 Subject: [PATCH 06/17] remove warning from configuration_validator.py --- .../trainer/configuration_validator.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pytorch_lightning/trainer/configuration_validator.py b/pytorch_lightning/trainer/configuration_validator.py index f23e978d0df02..363ce22ccd73a 100644 --- a/pytorch_lightning/trainer/configuration_validator.py +++ b/pytorch_lightning/trainer/configuration_validator.py @@ -142,21 +142,6 @@ def __verify_train_val_loop_configuration(trainer: "pl.Trainer", model: "pl.Ligh " Please use `val_dataloader()` directly." ) - -def _check_progress_bar(model: "pl.LightningModule") -> None: - r""" - Checks if get_progress_bar_dict is overridden and sends a deprecation warning. - - Args: - model: The model to check the get_progress_bar_dict method. - """ - if is_overridden("get_progress_bar_dict", model): - rank_zero_deprecation( - "The `LightningModule.get_progress_bar_dict` method was deprecated in v1.5 and will be removed in v1.7." - " Please use the `ProgressBarBase.get_metrics` instead." - ) - - def _check_on_post_move_to_device(model: "pl.LightningModule") -> None: r""" Checks if `on_post_move_to_device` method is overridden and sends a deprecation warning. From b7921b15dadd008e8a03a392091ce02e56b71cd1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 17:39:05 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytorch_lightning/trainer/configuration_validator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytorch_lightning/trainer/configuration_validator.py b/pytorch_lightning/trainer/configuration_validator.py index 363ce22ccd73a..38aa4263a76f9 100644 --- a/pytorch_lightning/trainer/configuration_validator.py +++ b/pytorch_lightning/trainer/configuration_validator.py @@ -142,6 +142,7 @@ def __verify_train_val_loop_configuration(trainer: "pl.Trainer", model: "pl.Ligh " Please use `val_dataloader()` directly." ) + def _check_on_post_move_to_device(model: "pl.LightningModule") -> None: r""" Checks if `on_post_move_to_device` method is overridden and sends a deprecation warning. From 1c75db61fa3a464bc300d45abcdcd1a52f72d033 Mon Sep 17 00:00:00 2001 From: Raymond G Schireman Date: Thu, 21 Apr 2022 13:59:10 -0400 Subject: [PATCH 08/17] restore _check_progress_bar() --- .../trainer/configuration_validator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pytorch_lightning/trainer/configuration_validator.py b/pytorch_lightning/trainer/configuration_validator.py index 363ce22ccd73a..61210325b242c 100644 --- a/pytorch_lightning/trainer/configuration_validator.py +++ b/pytorch_lightning/trainer/configuration_validator.py @@ -142,6 +142,20 @@ def __verify_train_val_loop_configuration(trainer: "pl.Trainer", model: "pl.Ligh " Please use `val_dataloader()` directly." ) + +def _check_progress_bar(model: "pl.LightningModule") -> None: + r""" + Checks if get_progress_bar_dict is overridden and sends a deprecation warning. + Args: + model: The model to check the get_progress_bar_dict method. + """ + if is_overridden("get_progress_bar_dict", model): + rank_zero_deprecation( + "The `LightningModule.get_progress_bar_dict` method was deprecated in v1.5 and will be removed in v1.7." + " Please use the `ProgressBarBase.get_metrics` instead." + ) + + def _check_on_post_move_to_device(model: "pl.LightningModule") -> None: r""" Checks if `on_post_move_to_device` method is overridden and sends a deprecation warning. From 94818bc9684d163977508d8d218e89902a8c8a3e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:02:56 +0000 Subject: [PATCH 09/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytorch_lightning/trainer/configuration_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/trainer/configuration_validator.py b/pytorch_lightning/trainer/configuration_validator.py index 61210325b242c..849f3c9366e97 100644 --- a/pytorch_lightning/trainer/configuration_validator.py +++ b/pytorch_lightning/trainer/configuration_validator.py @@ -155,7 +155,7 @@ def _check_progress_bar(model: "pl.LightningModule") -> None: " Please use the `ProgressBarBase.get_metrics` instead." ) - + def _check_on_post_move_to_device(model: "pl.LightningModule") -> None: r""" Checks if `on_post_move_to_device` method is overridden and sends a deprecation warning. From bcd0a7835e7fd88974002d1f6f343ff0a457712b Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 15:23:37 -0400 Subject: [PATCH 10/17] remove progress_bar_dict(self) property --- pytorch_lightning/trainer/trainer.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index dbde578a1dc80..adc589384fcea 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -2190,19 +2190,6 @@ def distributed_sampler_kwargs(self) -> Optional[dict]: def data_parallel(self) -> bool: return isinstance(self.strategy, ParallelStrategy) - @property - def progress_bar_dict(self) -> dict: - """Read-only for progress bar metrics.""" - rank_zero_deprecation( - "`trainer.progress_bar_dict` is deprecated in v1.5 and will be removed in v1.7." - " Use `ProgressBarBase.get_metrics` instead." - ) - ref_model = self.lightning_module - ref_model = cast(pl.LightningModule, ref_model) - if self.progress_bar_callback: - return self.progress_bar_callback.get_metrics(self, ref_model) - return self.progress_bar_metrics - @property def enable_validation(self) -> bool: """Check if we should run validation during training.""" From 4743cda39d7f280988914800086b67b3c2e2a325 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 16:39:59 -0400 Subject: [PATCH 11/17] fix import --- pytorch_lightning/trainer/trainer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index adc589384fcea..f089e77148c96 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -23,7 +23,7 @@ from copy import deepcopy from datetime import timedelta from pathlib import Path -from typing import Any, Callable, cast, Dict, Generator, Iterable, List, Optional, Type, Union +from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Type, Union from weakref import proxy import torch From b378997b71d7886b03e6654e722ccc37af818a38 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 16:41:01 -0400 Subject: [PATCH 12/17] remove unused import --- pytorch_lightning/core/lightning.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 354f74babcbd0..a4f343fe68966 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -32,7 +32,6 @@ import pytorch_lightning as pl from pytorch_lightning.callbacks.base import Callback -from pytorch_lightning.callbacks.progress import base as progress_base from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks, ModelHooks from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin, HyperparametersMixin from pytorch_lightning.core.optimizer import LightningOptimizer From 72e092abcc672d67f4025dea784e0384fc356f44 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 18:02:55 -0400 Subject: [PATCH 13/17] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d21359729d6f3..ee87cc0fa83cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed deprecated `dataloader_idx` argument from `on_train_batch_start/end` hooks `Callback` and `LightningModule` ([#12769](https://github.com/PyTorchLightning/pytorch-lightning/pull/12769)) + +- Removed deprecated `get_progress_bar_dict` property from `LightningModule` ([#12839](https://github.com/PyTorchLightning/pytorch-lightning/pull/12839)) + ### Fixed From de0fc303c3794e36d7cbd4ce0150535ed3eaa2b3 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 22:32:03 -0400 Subject: [PATCH 14/17] remove _check_progress_bar(model) --- .../trainer/configuration_validator.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pytorch_lightning/trainer/configuration_validator.py b/pytorch_lightning/trainer/configuration_validator.py index 849f3c9366e97..cec643065382e 100644 --- a/pytorch_lightning/trainer/configuration_validator.py +++ b/pytorch_lightning/trainer/configuration_validator.py @@ -49,8 +49,6 @@ def verify_loop_configurations(trainer: "pl.Trainer") -> None: __verify_dp_batch_transfer_support(trainer, model) _check_add_get_queue(model) - # TODO: Delete _check_progress_bar in v1.7 - _check_progress_bar(model) # TODO: Delete _check_on_post_move_to_device in v1.7 _check_on_post_move_to_device(model) _check_deprecated_callback_hooks(trainer) @@ -143,19 +141,6 @@ def __verify_train_val_loop_configuration(trainer: "pl.Trainer", model: "pl.Ligh ) -def _check_progress_bar(model: "pl.LightningModule") -> None: - r""" - Checks if get_progress_bar_dict is overridden and sends a deprecation warning. - Args: - model: The model to check the get_progress_bar_dict method. - """ - if is_overridden("get_progress_bar_dict", model): - rank_zero_deprecation( - "The `LightningModule.get_progress_bar_dict` method was deprecated in v1.5 and will be removed in v1.7." - " Please use the `ProgressBarBase.get_metrics` instead." - ) - - def _check_on_post_move_to_device(model: "pl.LightningModule") -> None: r""" Checks if `on_post_move_to_device` method is overridden and sends a deprecation warning. From ae49aea0a618722ca2b30d68fbc44bfdb791edcc Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Apr 2022 22:52:52 -0400 Subject: [PATCH 15/17] add back in imports to pass CI --- tests/deprecated_api/test_remove_1-7.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index bc5285b88dcae..3e94b55367381 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -20,7 +20,7 @@ import pytest import torch -from pytorch_lightning import Callback, Trainer +from pytorch_lightning import Callback, LightningDataModule, Trainer from pytorch_lightning.callbacks.lr_monitor import LearningRateMonitor from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger from pytorch_lightning.overrides.distributed import IndexBatchSamplerWrapper @@ -34,6 +34,7 @@ from pytorch_lightning.strategies import SingleDeviceStrategy from tests.deprecated_api import _soft_unimport_module from tests.helpers import BoringModel +from tests.helpers.datamodules import MNISTDataModule from tests.loggers.test_logger import CustomLogger from tests.plugins.environments.test_lsf_environment import _make_rankfile From 661adf07df56974047f625f1b5154a8b85c1b2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Fri, 22 Apr 2022 16:29:58 +0200 Subject: [PATCH 16/17] Bad merge --- tests/deprecated_api/test_remove_1-7.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 3e94b55367381..7541c1ba79d4b 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -39,14 +39,6 @@ from tests.plugins.environments.test_lsf_environment import _make_rankfile -def test_v1_7_0_datamodule_transform_properties(tmpdir): - dm = MNISTDataModule() - with pytest.deprecated_call(match=r"DataModule property `val_transforms` was deprecated in v1.5"): - dm.val_transforms = "b" - with pytest.deprecated_call(match=r"DataModule property `val_transforms` was deprecated in v1.5"): - _ = LightningDataModule(val_transforms="b") - - def test_v1_7_0_deprecated_on_task_dataloader(tmpdir): class CustomBoringModel(BoringModel): def on_train_dataloader(self): From d3799dabbc414e0abb5a19b0d41b72fe19e5b5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Fri, 22 Apr 2022 16:42:42 +0200 Subject: [PATCH 17/17] Remove unused imports --- tests/deprecated_api/test_remove_1-7.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 7541c1ba79d4b..c93aa78660a5a 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -20,7 +20,7 @@ import pytest import torch -from pytorch_lightning import Callback, LightningDataModule, Trainer +from pytorch_lightning import Callback, Trainer from pytorch_lightning.callbacks.lr_monitor import LearningRateMonitor from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger from pytorch_lightning.overrides.distributed import IndexBatchSamplerWrapper @@ -34,7 +34,6 @@ from pytorch_lightning.strategies import SingleDeviceStrategy from tests.deprecated_api import _soft_unimport_module from tests.helpers import BoringModel -from tests.helpers.datamodules import MNISTDataModule from tests.loggers.test_logger import CustomLogger from tests.plugins.environments.test_lsf_environment import _make_rankfile