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.

[feature request] tqdm for training

See original GitHub issue

It would be convenient to have tqdm wrapped around the main training loop — especially if it was from tqdm.auto import tqdm, as it autodetects whether it runs in a Jupyter notebook or in a terminal and uses either stderr or a widget.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
dnikucommented, Jul 11, 2021

For those finding this issue via search, here is a version that works with Stable Baselines 3:

from tqdm.notebook import tqdm
from stable_baselines3.common.callbacks import BaseCallback

class TqdmCallback(BaseCallback):
    def __init__(self):
        super().__init__()
        self.progress_bar = None
    
    def _on_training_start(self):
        self.progress_bar = tqdm(total=self.locals['total_timesteps'])
    
    def _on_step(self):
        self.progress_bar.update(1)
        return True

    def _on_training_end(self):
        self.progress_bar.close()
        self.progress_bar = None
5reactions
dnikucommented, Apr 29, 2019

It is a good idea to implement that using callback, thank you.

I’ve experimented a little and this seems to work with PPO2:

from tqdm.auto import tqdm

class TqdmCallback(object):
    def __init__(self):
        self.pbar = None
    
    def __call__(self, _locals, _globals):
        if self.pbar is None:
            self.pbar = tqdm(total=_locals['nupdates'])
            
        self.pbar.update(1)
        
        if _locals['update'] == _locals['nupdates']:
            self.pbar.close()
            self.pbar = None

        return True

One thought is that perhaps stable-baselines should accept multiple callbacks (Keras style), but that would be a topic for another issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Training models with a progress bar - Towards Data Science
tqdm is a Python library for adding progress bar. It lets you configure and display a progress bar with metrics you want to...
Read more >
How to Use Progress Bars in Python? | tqdm and tqdm Notebook
tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. In this article learn how to create...
Read more >
Fine-tune a pretrained model - Hugging Face
When you use a pretrained model, you train it on a dataset specific to your task. This is known as fine-tuning, an incredibly...
Read more >
Advanced Model Training with Fully Sharded Data Parallel ...
This tutorial introduces more advanced features of Fully Sharded Data Parallel ... tqdm.tqdm( range(len(train_loader)), colour="blue", desc="r0 Training ...
Read more >
Track your loop using tqdm: 7 ways progress bars in Python ...
tqdm does not require any dependencies and works across multiple python environments. Integrating tqdm can be done effortlessly in loops, ...
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