Skip to content

Commit 242b40e

Browse files
authored
Merge branch 'master' into torch_28_add_missing_device_id
2 parents 08a3e7c + b581924 commit 242b40e

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

src/lightning/pytorch/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3939

4040
- Fixed misalignment column while using rich model summary in `DeepSpeedstrategy` ([#21100](https://github.com/Lightning-AI/pytorch-lightning/pull/21100))
4141

42+
43+
- Fixed `RichProgressBar` crashing when sanity checking using val dataloader with 0 len ([#21108](https://github.com/Lightning-AI/pytorch-lightning/pull/21108))
44+
4245
---
4346

4447
## [2.5.3] - 2025-08-13

src/lightning/pytorch/callbacks/progress/rich_progress.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ def on_sanity_check_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningM
390390

391391
@override
392392
def on_sanity_check_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
393-
if self.progress is not None:
394-
assert self.val_sanity_progress_bar_id is not None
393+
if self.progress is not None and self.val_sanity_progress_bar_id is not None:
395394
self.progress.update(self.val_sanity_progress_bar_id, advance=0, visible=False)
396395
self.refresh()
397396

src/lightning/pytorch/trainer/connectors/logger_connector/logger_connector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def log_metrics(self, metrics: _OUT_DICT, step: Optional[int] = None) -> None:
9393
9494
Args:
9595
metrics: Metric values
96-
step: Step for which metrics should be logged. Default value is `self.global_step` during training or
97-
the total validation / test log step count during validation and testing.
96+
step: Step for which metrics should be logged. If a `step` metric is logged, this value will
97+
be used else will default to `self.global_step` during training or the total log step count
98+
during validation and testing.
9899
99100
"""
100101
if not self.trainer.loggers or not metrics:

tests/tests_pytorch/callbacks/progress/test_rich_progress_bar.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,31 @@ def test_rich_progress_bar_metrics_theme_update(*_):
577577
theme = RichProgressBar(theme=RichProgressBarTheme(metrics_format=".3e", metrics_text_delimiter="\n")).theme
578578
assert theme.metrics_format == ".3e"
579579
assert theme.metrics_text_delimiter == "\n"
580+
581+
582+
@RunIf(rich=True)
583+
def test_rich_progress_bar_empty_val_dataloader_model(tmp_path):
584+
"""Test that RichProgressBar doesn't crash with empty val_dataloader list from model."""
585+
586+
class EmptyListModel(BoringModel):
587+
def train_dataloader(self):
588+
return DataLoader(RandomDataset(32, 64), batch_size=2)
589+
590+
def val_dataloader(self):
591+
return []
592+
593+
model = EmptyListModel()
594+
progress_bar = RichProgressBar()
595+
596+
trainer = Trainer(
597+
default_root_dir=tmp_path,
598+
max_epochs=1,
599+
num_sanity_val_steps=1,
600+
callbacks=[progress_bar],
601+
limit_train_batches=2,
602+
enable_checkpointing=False,
603+
logger=False,
604+
)
605+
606+
# This should not raise an AssertionError
607+
trainer.fit(model)

0 commit comments

Comments
 (0)