Open davidgilbertson opened 2 years ago
After a bit of digging I've found what I'm sure you already know: that this is a known issue with Progress Bars. So I wonder if there's a way to detect if you're in an environment that's going to result in a wall of console text (check sys.stdout.isatty()
?) and alter the output accordingly?
I notice that the tqdm source has a check for isatty()
, but it only runs if disable=None
. When Lightning calls Tqdm
it appears to pass disable
as either True
or False
(never None
) so this check doesn't get to run. This just turns it off entirely which is not great, because it works fine if you only have one and don't interrupt it.
If you really wanted to get this working nicely for PyCharm (and other non-tty) users, you could keep track of how many progress bars you're running and check isatty()
and act accordingly.
@davidgilbertson We have many PyCharm users here also developing Lightning, and have seen this issue from the very beginning of progress bar integration. PyCharm does not support the necessary features for tqdm to act correctly when nesting bars. More info in their FAQ here: https://github.com/tqdm/tqdm/#faq-and-known-issues. I don't know ways to work around it reliably.
If you would like to experiment with this or contribute something here, that would be great. Even a note in the docs, like you said, would already be valuable IMO.
FYI, we also have a second progress bar implementation using rich: https://pytorch-lightning.readthedocs.io/en/stable/common/progress_bar.html?highlight=rich#richprogressbar
Thanks for the reply.
I've just put together my own hacky little thing. I'm sure as I get to know Lightning better I'll come up with something more elegant. For now at least it prevents the wall of text.
class MyProgressBar(TQDMProgressBar):
def init_validation_tqdm(self):
bar = super().init_validation_tqdm()
if not sys.stdout.isatty():
bar.disable = True
return bar
def init_predict_tqdm(self):
bar = super().init_predict_tqdm()
if not sys.stdout.isatty():
bar.disable = True
return bar
def init_test_tqdm(self):
bar = super().init_test_tqdm()
if not sys.stdout.isatty():
bar.disable = True
return bar
trainer = pl.Trainer(
...
callbacks=[MyProgressBar()],
)
And it's a sign of a well-written package that I was so easily able to get in and modify this behaviour. Good stuff!
Hey guys,
Thanks for this excellent library. I have one question regarding the RichProgressBar()
. I cannot see the progress bar during the training or validation stage when using it in my notebooks. Can anyone please help me with this?
Hey guys,
Thanks for this excellent library. I have one question regarding the
RichProgressBar()
. I cannot see the progress bar during the training or validation stage when using it in my notebooks. Can anyone please help me with this?
I have same problem.
y runs if
disable=None
. When Lightning callsTqdm
it appears to passdisable
as eitherTrue
orFalse
(neverNone
) so this check doesn't get to run. This just turn
You can try set "leave=True"
class MyProgressBar(TQDMProgressBar): def init_validation_tqdm(self): bar = super().init_validation_tqdm() if not sys.stdout.isatty(): bar.disable = True return bar def init_predict_tqdm(self): bar = super().init_predict_tqdm() if not sys.stdout.isatty(): bar.disable = True return bar def init_test_tqdm(self): bar = super().init_test_tqdm() if not sys.stdout.isatty(): bar.disable = True return bar
Thank you @davidgilbertson for providing this code! It works great for me on Pycharm!
@harryseely @davidgilbertson If this works well, would you consider sending a PR to lightning? I'm sure the community who use PyCharm would appreciate this improvement and I'd be happy to test it out as well.
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions - the Lightning Team!
@davidgilbertson the issue still persists but thanks for the solution.
Bug description
With a simple model like this:
I get a console that looks like this. It runs the progress bar as it should up to about 86%, then spits out some validation stuff and from then on each update to the progress 'bar' is a new line:
If I don't have a
validation_step
method in my class, the progress bar works as it should.How to reproduce the bug
No response
Error messages and logs
No response
Environment
More info
This is most likely specific to PyCharm, which uses a custom console. To replicate this you need to make sure you've selected "Run with Python Console" in the run config.
Probably the most relevant bug in PyCharm is this one.
Running as a script in a terminal, it works as expected, (but I can't even see the progress bar when I use VSCode and "Run in interactive window".)
I only started looking at Lightning yesterday and it looks great, but the wall of console text makes it a bit painful to work with, since it swamps any other messages. Maybe I'll soon learn how to disable the progress meter or use the rich one. Regardless, I would suggest that if this occurs for all PyCharm users, at the very least it would be worth putting a note in the docs to lessen the bad first impression for new users.
cc @borda @awaelchli