Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable tqdm's progressbar and keep only the text info in Pytorch Lightning (or in tqdm in general)

I am working on Pytorchlightning and tqdm's progressbar is very buggy, it keep resizing back and forth from short to long, making reading the logging text so unpleasant, I realized that the progressbar is not really necessary and would like to keep only the info about the current epoch, current batch, accuracy, loss, etc.

From my searching it seems like you can disable whole tqdm display(progressbar and text), but how can I selectively disable only progressbar but not the text?

like image 415
wanburana Avatar asked Sep 02 '25 16:09

wanburana


1 Answers

The tqdm way to disable the "meter" (while retaining display of stats) is to set ncols=0 and dynamic_ncols=False (see tqdm documentation).

The way to customize the default progress bar behavior in pytorch_lightning is to pass a custom ProgressBar in as a callback when building the Trainer.

Putting the two together, if you wanted to modify the progress bar during training you could do something like the following:

import pytorch_lightning as pl
from pytorch_lightning.callbacks import ProgressBar


class MeterlessProgressBar(ProgressBar):

    def init_train_tqdm(self):
        bar = super().init_train_tqdm()
        bar.dynamic_ncols = False
        bar.ncols = 0
        return bar

bar = MeterlessProgressBar()
trainer = pl.Trainer(callbacks=[bar])

You can separately customize for the sanity check, prediction, validation, and test by overriding: init_sanity_tqdm, init_predict_tqdm, init_validation_tqdm, and init_test_tqdm respectively. (If you want a quick and dirty way to do something to all progress bars, you could consider overriding the _update_bar method instead.)

like image 112
teichert Avatar answered Sep 04 '25 05:09

teichert