-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
🐛 Bug
Some internal printing mechanisms don't play nicely with RichProgressBar.
This can result in the progress bar getting interleaved into the printed data.
For example, this affects the pretty table of metrics that is printed after Trainer.testing your model:
Testing ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1 0:00:00 • 0:00:00 0.00it/s ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Test metric ┃ DataLoader 0 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ test_loss │ -4.4067792892456055 │
└───────────────────────────┴───────────────────────────┘
A similar issue can also come up, when using RichModelSummary.summarize.
To Reproduce
Take the BoringModel sample code and add
callbacks=[pl.callbacks.RichProgressBar()]
to the Trainer.
Expected behavior
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Test metric ┃ DataLoader 0 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ test_loss │ -4.4067792892456055 │
└───────────────────────────┴───────────────────────────┘
Testing ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1 0:00:00 • 0:00:00 0.00it/s
Environment
* CUDA:
- GPU:
- NVIDIA GeForce GTX 1050
- available: True
- version: 11.3
* Packages:
- numpy: 1.22.3
- pyTorch_debug: False
- pyTorch_version: 1.11.0+cu113
- pytorch-lightning: 1.6.0
- tqdm: 4.63.2
* System:
- OS: Linux
- architecture:
- 64bit
- ELF
- processor:
- python: 3.10.4
- version: #1 SMP PREEMPT Mon Mar 28 09:16:36 UTC 2022
Fix
Instead of creating a new Console and printing to it, RichModelSummary.summarize and EvaluationLoop._print_results should check if trainer has a progress_bar_callback of type RichProgressBar and if so, it should use trainer.progress_bar_callback.progress.console.
Edit: Actually a better solution might be using rich.get_console() instead of creating new instances of rich.console.Console() everywhere and if you need to change the kwargs (because user passed console_kwargs in RichProgressBar) use rich.reconfigure(**console_kwargs).