From 6919de5f69c9b86f33654716974c6d6bee09261b Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Wed, 30 Jul 2025 11:36:37 +0530 Subject: [PATCH 01/11] fix ci test failures due to rich progress bar --- .../pytorch/callbacks/progress/rich_progress.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index 7bb98e8a9058c..67c68605d0e6e 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -331,7 +331,19 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: self._reset_progress_bar_ids() reconfigure(**self._console_kwargs) self._console = get_console() - self._console.clear_live() + + # Compatibility shim for Rich >= 14.1.0: + # In recent Rich releases, the internal `_live` variable was replaced with `_live_stack` (a list) + # to support nested Live displays. This broke our original call to `clear_live()`, + # because it now only pops one Live instance instead of clearing them all. + # We check for `_live_stack` and clear it manually for compatibility across + # both old and new Rich versions. + if hasattr(self._console, "_live_stack"): + if len(self._console._live_stack) > 0: + self._console._live_stack.clear() + else: + self._console.clear_live() + self._metric_component = MetricsTextColumn( trainer, self.theme.metrics, From be89680a08456ad048af1749f9679b1c80908188 Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Wed, 30 Jul 2025 12:27:43 +0530 Subject: [PATCH 02/11] update --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index 67c68605d0e6e..cdc16575d3aca 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -340,7 +340,7 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # both old and new Rich versions. if hasattr(self._console, "_live_stack"): if len(self._console._live_stack) > 0: - self._console._live_stack.clear() + self._console.clear_live() else: self._console.clear_live() From 32ee0617c615a80c67be3b4e99226e52f1cfd5e0 Mon Sep 17 00:00:00 2001 From: Deependu Date: Mon, 4 Aug 2025 15:24:01 +0530 Subject: [PATCH 03/11] Update src/lightning/pytorch/callbacks/progress/rich_progress.py Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index cd51b0fe0ea60..d10834054ea5d 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -338,9 +338,8 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # because it now only pops one Live instance instead of clearing them all. # We check for `_live_stack` and clear it manually for compatibility across # both old and new Rich versions. - if hasattr(self._console, "_live_stack"): - if len(self._console._live_stack) > 0: - self._console.clear_live() + if getattr(self._console, "_live_stack", 0) > 0: + self._console.clear_live() else: self._console.clear_live() From ef4165078d109a0120cb0ba31c90a186e70aaead Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Mon, 4 Aug 2025 15:31:11 +0530 Subject: [PATCH 04/11] update --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index d10834054ea5d..cd51b0fe0ea60 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -338,8 +338,9 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # because it now only pops one Live instance instead of clearing them all. # We check for `_live_stack` and clear it manually for compatibility across # both old and new Rich versions. - if getattr(self._console, "_live_stack", 0) > 0: - self._console.clear_live() + if hasattr(self._console, "_live_stack"): + if len(self._console._live_stack) > 0: + self._console.clear_live() else: self._console.clear_live() From 0c007856ec2f3cce664123f03aaf60a3c6a886bb Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Mon, 4 Aug 2025 12:37:19 +0200 Subject: [PATCH 05/11] Apply suggestions from code review --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index cd51b0fe0ea60..ef989a6f72df3 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -338,9 +338,8 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # because it now only pops one Live instance instead of clearing them all. # We check for `_live_stack` and clear it manually for compatibility across # both old and new Rich versions. - if hasattr(self._console, "_live_stack"): - if len(self._console._live_stack) > 0: - self._console.clear_live() + if len(getattr(self._console, "_live_stack", [])) > 0: + self._console.clear_live() else: self._console.clear_live() From 879927aef7f418761c09a0a1a8f79e1f9e2f03b6 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Mon, 4 Aug 2025 12:40:52 +0200 Subject: [PATCH 06/11] bump rich --- requirements/pytorch/extra.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/pytorch/extra.txt b/requirements/pytorch/extra.txt index 0f11b19c23431..ab3a36f7dad3b 100644 --- a/requirements/pytorch/extra.txt +++ b/requirements/pytorch/extra.txt @@ -6,6 +6,6 @@ matplotlib>3.1, <3.10.0 omegaconf >=2.2.3, <2.4.0 hydra-core >=1.2.0, <1.4.0 jsonargparse[signatures,jsonnet] >=4.39.0, <4.41.0 -rich >=12.3.0, <14.1.0 +rich >=12.3.0, <14.2.0 tensorboardX >=2.2, <2.7.0 # min version is set by torch.onnx missing attribute bitsandbytes >=0.45.2,<0.47.0; platform_system != "Darwin" From 475c263d55f5d5d206466d75f1918f8bc345abce Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Mon, 4 Aug 2025 12:56:17 +0200 Subject: [PATCH 07/11] Apply suggestions from code review Co-authored-by: Deependu --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index ef989a6f72df3..725a1be74de56 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -338,7 +338,9 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # because it now only pops one Live instance instead of clearing them all. # We check for `_live_stack` and clear it manually for compatibility across # both old and new Rich versions. - if len(getattr(self._console, "_live_stack", [])) > 0: + if hasattr(self._console, "_live_stack"): + if len(self._console._live_stack) > 0: + self._console.clear_live() self._console.clear_live() else: self._console.clear_live() From 0d0aa0264d40a333241ff005b4ef952734c9343b Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Mon, 4 Aug 2025 16:27:36 +0530 Subject: [PATCH 08/11] update --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index 725a1be74de56..cd51b0fe0ea60 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -341,7 +341,6 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: if hasattr(self._console, "_live_stack"): if len(self._console._live_stack) > 0: self._console.clear_live() - self._console.clear_live() else: self._console.clear_live() From 76d8310e296a0f7428f79d6e5d17f207816edade Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Mon, 4 Aug 2025 13:01:57 +0200 Subject: [PATCH 09/11] Apply suggestions from code review --- src/lightning/pytorch/callbacks/progress/rich_progress.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index cd51b0fe0ea60..2bb3c596f371b 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -338,9 +338,8 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: # because it now only pops one Live instance instead of clearing them all. # We check for `_live_stack` and clear it manually for compatibility across # both old and new Rich versions. - if hasattr(self._console, "_live_stack"): - if len(self._console._live_stack) > 0: - self._console.clear_live() + if hasattr(self._console, "_live_stack") and len(self._console._live_stack) > 0: + self._console.clear_live() else: self._console.clear_live() From d5a15c52b1a9b73e679fdff3f9abca89c0aba69a Mon Sep 17 00:00:00 2001 From: Jirka B Date: Mon, 4 Aug 2025 13:03:11 +0200 Subject: [PATCH 10/11] rev --- .../pytorch/callbacks/progress/rich_progress.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lightning/pytorch/callbacks/progress/rich_progress.py b/src/lightning/pytorch/callbacks/progress/rich_progress.py index 2bb3c596f371b..ff092fa99d825 100644 --- a/src/lightning/pytorch/callbacks/progress/rich_progress.py +++ b/src/lightning/pytorch/callbacks/progress/rich_progress.py @@ -333,13 +333,14 @@ def _init_progress(self, trainer: "pl.Trainer") -> None: self._console = get_console() # Compatibility shim for Rich >= 14.1.0: - # In recent Rich releases, the internal `_live` variable was replaced with `_live_stack` (a list) - # to support nested Live displays. This broke our original call to `clear_live()`, - # because it now only pops one Live instance instead of clearing them all. - # We check for `_live_stack` and clear it manually for compatibility across - # both old and new Rich versions. - if hasattr(self._console, "_live_stack") and len(self._console._live_stack) > 0: - self._console.clear_live() + if hasattr(self._console, "_live_stack"): + # In recent Rich releases, the internal `_live` variable was replaced with `_live_stack` (a list) + # to support nested Live displays. This broke our original call to `clear_live()`, + # because it now only pops one Live instance instead of clearing them all. + # We check for `_live_stack` and clear it manually for compatibility across + # both old and new Rich versions. + if len(self._console._live_stack) > 0: + self._console.clear_live() else: self._console.clear_live() From 5b2b62e05a668be06b3afdf70016f97d9ed281bc Mon Sep 17 00:00:00 2001 From: Jirka B Date: Mon, 4 Aug 2025 13:04:57 +0200 Subject: [PATCH 11/11] chlog --- src/lightning/pytorch/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lightning/pytorch/CHANGELOG.md b/src/lightning/pytorch/CHANGELOG.md index 5b364ac1c7a3e..81c7bfc656885 100644 --- a/src/lightning/pytorch/CHANGELOG.md +++ b/src/lightning/pytorch/CHANGELOG.md @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed -- +- fix progress bar console clearing for Rich `14.1+` ([#21016](https://github.com/Lightning-AI/pytorch-lightning/pull/21016)) ---