How to disable progress bar in Pytorch Lightning
I would like to know if these issues can be solved or else how can I disable the progress bar and instead, just print some log details on the screen.
As far as I know this problem is still unresolved. The pl team points that it is "TQDM related thing" and they can't do anything about it. Maybe you want to read this issue
My temporary fix is :
from tqdm import tqdm class LitProgressBar(ProgressBar): def init_validation_tqdm(self): bar = tqdm( disable=True, ) return bar bar = LitProgressBar() trainer = Trainer(callbacks=[bar])
This method simply disables the validation progress bar and allows you to keep the correct training bar [refer 1 and 2]. Note that using
progress_bar_refresh_rate=0 will disable the update of all progress bars.
Further solution: (Update1 2021-07-22)
According to this answer, the
tqdm seems to only be glitching in the
PyCharm console. So,
a possible answer is to do something with
Pycharm setting. Fortunately, I find this answer
Go to "Edit configurations". Click on the run/debug configuration that is being used. There should be an option "Emulate terminal in output console". Check that. Image added for reference.
Along with the
positionargument also set the
leaveargument. The code should look like this. I have added
ncolsso that the progress bar doesn't take up whole of the console.
from tqdm import tqdm import time for i in tqdm(range(5), position=0, desc="i", leave=False, colour='green', ncols=80): for j in tqdm(range(10), position=1, desc="j", leave=False, colour='red', ncols=80): time.sleep(0.5)
When the code is now run, the output of the console is as shown below.
i: 20%|████████▍ | 1/5 [00:05<00:20, 5.10s/it] j: 60%|████████████████████████▌ | 6/10 [00:03<00:02, 1.95it/s]
Follwing the above two steps, we can display the progress bar in the Pycharm in the normal way. To finish the step2 in the
Pytorch-lightning, we need to override functions init_train_tqdm(), init_validation_tqdm(), init_test_tqdm() to change the ncols. Some codes like this (hope it helps):
class LitProgressBar(ProgressBar): def init_train_tqdm(self) -> tqdm: """ Override this to customize the tqdm bar for training. """ bar = tqdm( desc='Training', initial=self.train_batch_idx, position=(2 * self.process_position), disable=self.is_disabled, leave=True, dynamic_ncols=False, # This two lines are only for pycharm ncols=100, file=sys.stdout, smoothing=0, ) return bar def init_validation_tqdm(self) -> tqdm: """ Override this to customize the tqdm bar for validation. """ # The main progress bar doesn't exist in `trainer.validate()` has_main_bar = self.main_progress_bar is not None bar = tqdm( desc='Validating', position=(2 * self.process_position + has_main_bar), disable=self.is_disabled, leave=False, dynamic_ncols=False, ncols=100, file=sys.stdout ) return bar def init_test_tqdm(self) -> tqdm: """ Override this to customize the tqdm bar for testing. """ bar = tqdm( desc="Testing", position=(2 * self.process_position), disable=self.is_disabled, leave=True, dynamic_ncols=False, ncols=100, file=sys.stdout ) return bar
If it does not work for you, please update the version of
Pytorch-lightning to the lastest one.
show_progress_bar=False deprecated since version 0.7.2, but you can use
progress_bar_refresh_rate has been deprecated in v1.5 and will be removed in v1.7. To disable the progress bar, set
enable_progress_bar to false
progress_bar_refresh_rate: How often to refresh progress bar (in steps). Value ``0`` disables progress bar. Ignored when a custom progress bar is passed to :paramref:`~Trainer.callbacks`. Default: None, means a suitable value will be chosen based on the environment (terminal, Google COLAB, etc.). .. deprecated:: v1.5 ``progress_bar_refresh_rate`` has been deprecated in v1.5 and will be removed in v1.7. Please pass :class:`~pytorch_lightning.callbacks.progress.TQDMProgressBar` with ``refresh_rate`` directly to the Trainer's ``callbacks`` argument instead. To disable the progress bar, pass ``enable_progress_bar = False`` to the Trainer. enable_progress_bar: Whether to enable to progress bar by default.
Use the command
show_progress_bar=False in Trainer.