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

Force display of iterations per second (it/s) - instead of displaying inverse (s/it) based on rate #1259

Open
tloki opened this issue Oct 11, 2021 · 6 comments

Comments

@tloki
Copy link

tloki commented Oct 11, 2021

For a given code example:

from tqdm import tqdm
from time import sleep

for i in tqdm(range(100)):
    sleep(1.5)

the output looks like this:
6%|▌ | 6/100 [00:09<02:21, 1.50s/it]

but I'd like for it to actually force display it/s (generally, units per time, and possibly vice versa) so the output for this example (with the required parameter being set) would look like this:

6%|▌ | 6/100 [00:09<02:21, 0.67it/s]

as I see it, this functionality is basically hardcoded in std.py (in master branch as of October 2021)

rate_fmt = rate_inv_fmt if inv_rate and inv_rate > 1 else rate_noinv_fmt

a modification of the above code line to
rate_fmt = rate_noinv_fmt

achieves desired behavior, but does not parametrize the rate when each format should be displayed. As I see it right now, that hardcoded "1" may be the only thing in need of parametrizing (possibly member variable) with an option to be set to None or so to completely ignore it, while a default value could be 1 to preserve current default behavior.

is there any other way right now to "force" set it/s mode (without changing tqdm code), and possibly set the "trigger" frequency? Say, for example, one might want to display seconds per iteration only if rate is lower than 1e-3 it/s)...

EDIT 1, 2 & 3: sentence formatting, spelling, punctuation

@tloki tloki changed the title Force display of iterations per second (it/s) instead of (dynamically displayed) (s/it) and it/s based on rate Force display of iterations per second (it/s) instead of inverse (s/it) based on rate Oct 11, 2021
@tloki tloki changed the title Force display of iterations per second (it/s) instead of inverse (s/it) based on rate Force display of iterations per second (it/s) - instead of displaying inverse (s/it) based on rate Oct 11, 2021
@ldeluigi
Copy link

image
It's quite annoying that the unit of measure is inconsistent between subsequent runs of the same code (same speed, that is).
Hopefully, one of the two units is preferred and should be fixed as constant, or at least an option/default should be added.

@tloki
Copy link
Author

tloki commented Oct 22, 2021

It is not inconsistent, it is clearly dependant of speed of your iteration - which by your image is not the same (your data loader probably had some time to load some batches during validation so in the beggining of training epoch 29 you had higher training rate).

but you are affected by the fact that your slower iterations are displayed in seconds per iteration with simmilar number to one that was in iterations per second. with rate unit being fixed to it/s or s/it - you would be able to recognize this more clearly.

@alexreg
Copy link

alexreg commented Feb 17, 2023

Indeed, this is clearly undesirable in the case your rate hovers around 1, in which case you can get the unit flipping between itself and its inverse quite frequently!

@roflmaostc
Copy link

roflmaostc commented Apr 25, 2023

Ha!

Got fooled by this,really nasty imho.

@aalanwyr
Copy link

aalanwyr commented Aug 18, 2023

I also hit this confusion of the tqdm unit (it/s and s/it)
Luckily, we can use a tag to fix this unit :  bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_noinv_fmt}]"
Such as:

for rep in tqdm(range(10), desc="Inference", ncols=100, total=10, leave=True):
    sleep(2)
    print("iteration:", rep)
Inference:  10%|█████▎                                               | 1/10 [00:02<00:18,  2.00s/it]iteration: 1

for rep in tqdm(range(10), desc="Inference", ncols=100, total=10, leave=True, bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_noinv_fmt}]"):
    sleep(2)
    print("iteration:", rep) 
Inference:  10%|█████▎                                               | 1/10 [00:02<00:18,  0.50it/s]iteration: 1

martinmCGG pushed a commit to martinmCGG/stylegan3 that referenced this issue Oct 25, 2023
@clemisch
Copy link

clemisch commented May 8, 2024

So there is no built-in switch for this? This explicit bar format seems like a very verbose way of achieving consistent units.

...nevertheless, thank you for sharing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants