From c379bed6c9f9bb0f07362ac47c13b030fd7e1a55 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Thu, 16 Dec 2021 11:14:52 +0800 Subject: [PATCH 01/12] to Optional[Dict[str, Any], Console] --- pytorch_lightning/callbacks/progress/rich_progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 2e24df6da61f6..b6e05060abbfc 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -228,7 +228,7 @@ def __init__( refresh_rate: int = 1, leave: bool = False, theme: RichProgressBarTheme = RichProgressBarTheme(), - console_kwargs: Optional[Dict[str, Any]] = None, + console_kwargs: Optional[Dict[str, Any], Console] = None, ) -> None: if not _RICH_AVAILABLE: raise MisconfigurationException( From a1b01522a3de28e5846c29af97b8818a3e353e7f Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Thu, 16 Dec 2021 11:49:09 +0800 Subject: [PATCH 02/12] update --- pytorch_lightning/callbacks/progress/rich_progress.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index b6e05060abbfc..987b6f729a31e 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -15,6 +15,7 @@ from dataclasses import dataclass from datetime import timedelta from typing import Any, Dict, Optional, Union +import copy from pytorch_lightning.callbacks.progress.base import ProgressBarBase from pytorch_lightning.utilities.exceptions import MisconfigurationException @@ -211,7 +212,7 @@ class RichProgressBar(ProgressBarBase): Set it to ``0`` to disable the display. leave: Leaves the finished progress bar in the terminal at the end of the epoch. Default: False theme: Contains styles used to stylize the progress bar. - console_kwargs: Args for constructing a `Console` + console_kwargs: Args for constructing a `Console` or a `Console` object Raises: ModuleNotFoundError: @@ -228,7 +229,7 @@ def __init__( refresh_rate: int = 1, leave: bool = False, theme: RichProgressBarTheme = RichProgressBarTheme(), - console_kwargs: Optional[Dict[str, Any], Console] = None, + console_kwargs: Optional[Union[Dict[str, Any], Console]] = None, ) -> None: if not _RICH_AVAILABLE: raise MisconfigurationException( @@ -284,7 +285,10 @@ def predict_description(self) -> str: def _init_progress(self, trainer): if self.is_enabled and (self.progress is None or self._progress_stopped): self._reset_progress_bar_ids() - self._console = Console(**self._console_kwargs) + if isinstance(self._console_kwargs, Console): + self._console = copy.deepcopy(self._console_kwargs) + else: + self._console = Console(**self._console_kwargs) self._console.clear_live() self._metric_component = MetricsTextColumn(trainer, self.theme.metrics) self.progress = CustomProgress( From b0b6a24f5c6c0c428ef2982965632bdeed80fb71 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Thu, 16 Dec 2021 11:51:57 +0800 Subject: [PATCH 03/12] update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f95ebaebac6c..dfddbb0d276da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed duplicated file extension when uploading model checkpoints with `NeptuneLogger` ([#11015](https://github.com/PyTorchLightning/pytorch-lightning/pull/11015)) +- Changed the `console_kwargs` arg of `RichProgressBar` to accept `Console` object ([#11100](https://github.com/PyTorchLightning/pytorch-lightning/pull/11100)) + ### Deprecated From 37ecfd8ea4b2a59c418b7eafa302b18a7def20e1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 03:53:22 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytorch_lightning/callbacks/progress/rich_progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 987b6f729a31e..3003963867e08 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -11,11 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import copy import math from dataclasses import dataclass from datetime import timedelta from typing import Any, Dict, Optional, Union -import copy from pytorch_lightning.callbacks.progress.base import ProgressBarBase from pytorch_lightning.utilities.exceptions import MisconfigurationException From 53830663dda13c09f8558ff4bf855b905d776b37 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Thu, 16 Dec 2021 16:03:30 +0800 Subject: [PATCH 05/12] fix --- pytorch_lightning/callbacks/progress/rich_progress.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 987b6f729a31e..5af522a03b817 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -21,7 +21,8 @@ from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _RICH_AVAILABLE -Task, Style = None, None +Task, Style, Console = None, None, None + if _RICH_AVAILABLE: from rich.console import Console, RenderableType from rich.progress import BarColumn, Progress, ProgressColumn, Task, TaskID, TextColumn From d045e03ddb4f41ac0acfce5f66daff6be355a056 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:03:17 +0800 Subject: [PATCH 06/12] Revert "fix" This reverts commit 53830663dda13c09f8558ff4bf855b905d776b37. --- pytorch_lightning/callbacks/progress/rich_progress.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 7f316014a3898..3003963867e08 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -21,8 +21,7 @@ from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _RICH_AVAILABLE -Task, Style, Console = None, None, None - +Task, Style = None, None if _RICH_AVAILABLE: from rich.console import Console, RenderableType from rich.progress import BarColumn, Progress, ProgressColumn, Task, TaskID, TextColumn From 39f24321b5a17252b3cf0b56899b5904bb5f8cc4 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:03:27 +0800 Subject: [PATCH 07/12] Revert "update" This reverts commit b0b6a24f5c6c0c428ef2982965632bdeed80fb71. --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa42c60097e15..418fb64962a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,8 +114,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed duplicated file extension when uploading model checkpoints with `NeptuneLogger` ([#11015](https://github.com/PyTorchLightning/pytorch-lightning/pull/11015)) -- Changed the `console_kwargs` arg of `RichProgressBar` to accept `Console` object ([#11100](https://github.com/PyTorchLightning/pytorch-lightning/pull/11100)) - - Moved ownership of the `Accelerator` instance to the `TrainingTypePlugin`; all training-type plugins now take an optional parameter `accelerator` ([#11022](https://github.com/PyTorchLightning/pytorch-lightning/pull/11022)) From a9f2819bd03f9f6914d66d3aaccedb40bbd8eb9b Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:03:37 +0800 Subject: [PATCH 08/12] Revert "update" This reverts commit a1b01522a3de28e5846c29af97b8818a3e353e7f. --- pytorch_lightning/callbacks/progress/rich_progress.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 3003963867e08..777f0355e1ba7 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -212,7 +212,7 @@ class RichProgressBar(ProgressBarBase): Set it to ``0`` to disable the display. leave: Leaves the finished progress bar in the terminal at the end of the epoch. Default: False theme: Contains styles used to stylize the progress bar. - console_kwargs: Args for constructing a `Console` or a `Console` object + console_kwargs: Args for constructing a `Console` Raises: ModuleNotFoundError: @@ -229,7 +229,7 @@ def __init__( refresh_rate: int = 1, leave: bool = False, theme: RichProgressBarTheme = RichProgressBarTheme(), - console_kwargs: Optional[Union[Dict[str, Any], Console]] = None, + console_kwargs: Optional[Dict[str, Any], Console] = None, ) -> None: if not _RICH_AVAILABLE: raise MisconfigurationException( @@ -285,10 +285,7 @@ def predict_description(self) -> str: def _init_progress(self, trainer): if self.is_enabled and (self.progress is None or self._progress_stopped): self._reset_progress_bar_ids() - if isinstance(self._console_kwargs, Console): - self._console = copy.deepcopy(self._console_kwargs) - else: - self._console = Console(**self._console_kwargs) + self._console = Console(**self._console_kwargs) self._console.clear_live() self._metric_component = MetricsTextColumn(trainer, self.theme.metrics) self.progress = CustomProgress( From 2390a6fe42a163264f868f7257540813fa417e82 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:05:05 +0800 Subject: [PATCH 09/12] Revert "to Optional[Dict[str, Any], Console]" This reverts commit c379bed6c9f9bb0f07362ac47c13b030fd7e1a55. --- pytorch_lightning/callbacks/progress/rich_progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 777f0355e1ba7..7bb65582752ce 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -229,7 +229,7 @@ def __init__( refresh_rate: int = 1, leave: bool = False, theme: RichProgressBarTheme = RichProgressBarTheme(), - console_kwargs: Optional[Dict[str, Any], Console] = None, + console_kwargs: Optional[Dict[str, Any]] = None, ) -> None: if not _RICH_AVAILABLE: raise MisconfigurationException( From 635cf35d02a18a8976b96b5c7916516f4ece4d4e Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:05:52 +0800 Subject: [PATCH 10/12] apply reviews --- pytorch_lightning/callbacks/progress/rich_progress.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pytorch_lightning/callbacks/progress/rich_progress.py b/pytorch_lightning/callbacks/progress/rich_progress.py index 7bb65582752ce..abf4c45a2173f 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -319,17 +319,6 @@ def on_validation_start(self, trainer, pl_module): super().on_validation_start(trainer, pl_module) self._init_progress(trainer) - def __getstate__(self): - # can't pickle the rich progress objects - state = self.__dict__.copy() - state["progress"] = None - state["_console"] = None - return state - - def __setstate__(self, state): - self.__dict__ = state - self._console = Console(**self._console_kwargs) - def on_sanity_check_start(self, trainer, pl_module): super().on_sanity_check_start(trainer, pl_module) self._init_progress(trainer) From 5df3d7dcf34b3f37fb1c2fb943056d87a9dd7f90 Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:10:37 +0800 Subject: [PATCH 11/12] update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 418fb64962a51..a6edd19b169aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed duplicated file extension when uploading model checkpoints with `NeptuneLogger` ([#11015](https://github.com/PyTorchLightning/pytorch-lightning/pull/11015)) +- Removed `__getstate__` and `__setstate__` of `RichProgressBar` ([#11100](https://github.com/PyTorchLightning/pytorch-lightning/pull/11100)) + - Moved ownership of the `Accelerator` instance to the `TrainingTypePlugin`; all training-type plugins now take an optional parameter `accelerator` ([#11022](https://github.com/PyTorchLightning/pytorch-lightning/pull/11022)) From 51c2888983c857e4fef7ddb7b927f5e31eabba6a Mon Sep 17 00:00:00 2001 From: quancs <1017241746@qq.com> Date: Fri, 17 Dec 2021 15:13:55 +0800 Subject: [PATCH 12/12] Update pytorch_lightning/callbacks/progress/rich_progress.py --- 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 abf4c45a2173f..f983ccdaab12e 100644 --- a/pytorch_lightning/callbacks/progress/rich_progress.py +++ b/pytorch_lightning/callbacks/progress/rich_progress.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import copy import math from dataclasses import dataclass from datetime import timedelta