-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
When I'm using Pytorch Lightning with RichProgressBar
, an error is raised:
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py", line 1056, in _run_stage
self.fit_loop.run()
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/loops/fit_loop.py", line 212, in run
self.on_run_start()
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/loops/fit_loop.py", line 417, in on_run_start
call._call_callback_hooks(trainer, "on_train_start")
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/trainer/call.py", line 227, in _call_callback_hooks
fn(trainer, trainer.lightning_module, *args, **kwargs)
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/callbacks/progress/rich_progress.py", line 358, in on_train_start
self._init_progress(trainer)
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/lightning/pytorch/callbacks/progress/rich_progress.py", line 334, in _init_progress
self._console.clear_live()
File "/home/users/envs/miniconda3/envs/tmpl/lib/python3.12/site-packages/rich/console.py", line 847, in clear_live
self._live_stack.pop()
IndexError: pop from empty list
The issue appears to be introduced in rich version 14.1.0. The code runs correctly when rich is downgraded to 14.0.0 or any lower version. The following minimal script consistently reproduces it:
import torch
from torch.utils.data import DataLoader, TensorDataset
import lightning as L
from lightning.pytorch.callbacks import RichProgressBar
class SimpleModel(L.LightningModule):
def __init__(self):
super().__init__()
self.layer = torch.nn.Linear(32, 1)
def training_step(self, batch, batch_idx):
x, y = batch
loss = torch.nn.functional.mse_loss(self.layer(x), y)
self.log("train_loss", loss)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=0.01)
X = torch.randn(100, 32)
y = torch.randn(100, 1)
dataset = TensorDataset(X, y)
train_loader = DataLoader(dataset, batch_size=8)
model = SimpleModel()
progress_bar = RichProgressBar()
trainer = L.Trainer(max_epochs=5, callbacks=[progress_bar], accelerator="cpu")
trainer.fit(model, train_loader)
Platform
Click to expand
> python -m rich.diagnose
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=219 ColorSystem.TRUECOLOR> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = 'truecolor' │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│ height = 59 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = True │
│ is_jupyter = False │
│ is_terminal = True │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=219, height=59), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=219, │
│ is_terminal=True, │
│ encoding='utf-8', │
│ max_height=59, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=219, height=59) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 219 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available. │
│ │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ truecolor = False │
│ vt = False │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'CLICOLOR': None, │
│ 'COLORTERM': 'truecolor', │
│ 'COLUMNS': None, │
│ 'JPY_PARENT_PID': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'LINES': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': 'vscode', │
│ 'TERM': 'xterm-256color', │
│ 'TTY_COMPATIBLE': None, │
│ 'TTY_INTERACTIVE': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"
> pip freeze | grep rich
rich==14.1.0
ernestognw, josephbou, codeblooded, jeffreycwitt, itymchyshyn-sc and 1 more