Skip to content

tqdm progress bar in v1.6 is slower than v1.5 #13179

@akihironitta

Description

@akihironitta

🐛 Bug

Training the boring model is slow with 1.6.0 (and master) compared to 1.5.10 with tqdm progress bar enabled.

time: 9.177419368177652  # 1.5.10
time: 12.62373811379075  # 1.6.0

To Reproduce

from time import monotonic
from pytorch_lightning import Trainer
from tests.helpers import BoringModel

def main():
    model = BoringModel()
    trainer = Trainer(
        max_epochs=100,
        enable_model_summary=False,
        enable_checkpointing=False,
        logger=False,
        # profiler="advanced",
    )
    t0 = monotonic()
    trainer.fit(model)
    print("time:", monotonic() - t0)

if __name__ == "__main__":
    main()

Expected behavior

No regression in speed.

Environment

  • PyTorch Lightning Version (e.g., 1.5.0): 1.5.10 vs. 1.6.0
  • PyTorch Version (e.g., 1.10): 1.11.0 and 1.8.2
  • Python version (e.g., 3.9): 3.9
  • OS (e.g., Linux): Linux
  • CUDA/cuDNN version:
  • GPU models and configuration:
  • How you installed PyTorch (conda, pip, source):
  • If compiling from source, the output of torch.__config__.show():
  • Any other relevant information:

Additional context

The following benchmark result suggests that 8a549a5 (#11213) made the above code somewhat slow. Profiling the above script makes me think that the cause of the slowness is that #11213 added the expensive bar.refresh() call which still exists in master here:
https://github.com/PyTorchLightning/pytorch-lightning/blob/a6e9bc2943bf2c82036e31a4948bd8caa54957ee/pytorch_lightning/callbacks/progress/tqdm_progress.py#L390
benchmark result: https://www.akihironitta.com/lightning-benchmarks/#bench_fit.AnotherBoringBenchmark.time_it?branch=master&branch=release%2F1.5.x&pytorch=1.11&pytorch=1.8.2&torchvision=&pip%2Bprotobuf=3.20.1


Update: Just uncommented the refresh() call in https://github.com/PyTorchLightning/pytorch-lightning/tree/perf-tqdm and confirmed that it improves the performance to around the level of 1.5.10.


However, I'm not sure if we really need to fix this because:

  • users will disable the progress bar anyway when they need maximum performance, and they'll see progress via their logger usually
  • (and bar.refresh() makes the progress bar look smoother.)

cc @tchaton @rohitgr7 @awaelchli @Borda @akihironitta

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions