Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LitProgressBar ignores TQDM_MINITERS #19346

Closed
wouterzwerink opened this issue Jan 25, 2024 · 5 comments · Fixed by #19381
Closed

LitProgressBar ignores TQDM_MINITERS #19346

wouterzwerink opened this issue Jan 25, 2024 · 5 comments · Fixed by #19381
Labels
bug Something isn't working help wanted Open to be worked on progress bar: tqdm ver: 2.1.x

Comments

@wouterzwerink
Copy link
Contributor

wouterzwerink commented Jan 25, 2024

Bug description

tqdm supports setting the environment variable TQDM_MINITERS to reduce the frequency of progress bar updates.
Since lightning trainer defaults to a TQDM progress bar, I expected this to work for lightning. However, pytorch lightnings trainer seems to ignore this.

What version are you seeing the problem on?

v2.1

How to reproduce the bug

export TQDM_MINITERS=5
python your_script.py


where script can be anything using a `pytorch_lightning.Trainer` with `progress_bar_enabled=True`

Error messages and logs

Environment

Current environment
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow): Trainer
#- PyTorch Lightning Version (e.g., 1.5.0): 2.1.3
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0): 2.0.1
#- Python version (e.g., 3.9): 3.9
#- OS (e.g., Linux): Linux
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source): poetry
#- Running environment of LightningApp (e.g. local, cloud):

More info

No response

cc @awaelchli

@wouterzwerink wouterzwerink added bug Something isn't working needs triage Waiting to be triaged by maintainers labels Jan 25, 2024
@awaelchli
Copy link
Contributor

awaelchli commented Jan 25, 2024

@wouterzwerink Could you point us to the documentation for this? There is nothing like that in the source code of tqdm: https://github.com/search?q=repo:tqdm/tqdm+TQDM_MINITERS&type=code
and
https://github.com/search?q=repo:tqdm/tqdm+MINITERS&type=code

@awaelchli awaelchli added repro needed The issue is missing a reproducible example progress bar: tqdm and removed needs triage Waiting to be triaged by maintainers labels Jan 25, 2024
@wouterzwerink
Copy link
Contributor Author

@awaelchli yes unfortunately it's documented quite poorly!
They use this wrapper to overwrite their function defaults with environment variables
https://github.com/tqdm/tqdm/blob/4c956c20b83be4312460fc0c4812eeb3fef5e7df/tqdm/utils.py#L34

Applied here to TQDM:
https://github.com/tqdm/tqdm/blob/4c956c20b83be4312460fc0c4812eeb3fef5e7df/tqdm/std.py#L953

@awaelchli
Copy link
Contributor

awaelchli commented Jan 25, 2024

Thanks for the pointer! My blind guess is that maybe it doesn't work because we have our own small wrapper:


(but it should, since we call super().__init__?). Might be worth investigating what's going on there. Apart from that, I don't see why it wouldn't work because we're using tqdm quite plainly.

@wouterzwerink
Copy link
Contributor Author

I tried just adding

if __name__ == "__main__":
    import time

    for _ in Tqdm(range(100)):
        time.sleep(1)

to the bottom of this file: pytorch-lightning/src/lightning/pytorch/callbacks/progress/tqdm_progress.py

Calling it with and without TQDM_MINITERS set works as expected. So this Tqdm wrapper class is not causing any issues

@awaelchli
Copy link
Contributor

Ah ok, I understand what miniters does now. miniters=x is supposed to update only ever x ticks. But then it makes sense that it doesn't work with Lightning because our progress bar implementation directly updates the bar (there is no iterable over it), because we need explicit and dynamic control over when the update happens:

def _update_n(bar: _tqdm, value: int) -> None:
if not bar.disable:
bar.n = value
bar.refresh()

But I think there is probably an easy way to incorporate it by just grabbing the default refresh rate from the env variable here:

def _resolve_refresh_rate(refresh_rate: int) -> int:
if os.getenv("COLAB_GPU") and refresh_rate == 1:
# smaller refresh rate on colab causes crashes, choose a higher value
rank_zero_debug("Using a higher refresh rate on Colab. Setting it to `20`")
return 20
return refresh_rate

Would you be interested to contribute this change?

@awaelchli awaelchli added help wanted Open to be worked on and removed repro needed The issue is missing a reproducible example labels Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on progress bar: tqdm ver: 2.1.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants