question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rich progress bar doesn't play nicely with other prints

See original GitHub issue

πŸ› 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).

cc @kaushikb11 @rohitgr7

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RuRocommented, Apr 21, 2022

Sorry, I am kind of busy right now. I am trying to submit issues as I run into them, but I don’t currently have the time to properly fix them. If this issue is still not fixed in a couple of weeks, I might revisit it and submit the PRs, but for now I’ll have to pass.

0reactions
RuRocommented, Apr 26, 2022

@carmocca rich==12.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rich progress bar doesn't play nicely with other prints #12824
Some internal printing mechanisms don't play nicely with RichProgressBar. This can result in the progress bar getting interleaved into theΒ ...
Read more >
rich.prompt.Confirm not working in rich.Progress context python
I am working on an app that uses a rich.Progress for rendering progress bars. The problem is rich.prompt.Confirm just flashes instead ofΒ ...
Read more >
Progress Display β€” Rich 12.6.0 documentation
Rich progress display supports multiple tasks, each with a bar and progress information. You can use this to track concurrent tasks where the...
Read more >
Progress Bar - Typer - tiangolo
Typer progressbar ΒΆ. If you can, you should use Rich as explained above, it has more features, it's more advanced, and can display...
Read more >
How does apt render its fancy progress bar? - Hacker News
PowerShell does have progress bars, but rendering them is (was?) on the critical path. I once had a script that was downloading a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found