6

Logger in PyTorch-Lightning prints information about the model to be trained (or evaluated) and the progress during the training,

However, in my case I would like to hide all messages from the logger in order not to flood the output in Jupyter Notebook.

I've looked into the API of the Trainer class on the official docs page https://pytorch-lightning.readthedocs.io/en/latest/common/trainer.html#trainer-flags and it seems like there is no option to turn off the messages from the logger.

There is a parameter log_every_n_steps which can be set to big value, but nevertheless, the logging result after each epoch is displayed.

How can one disable the logging?

3 Answers3

7

I am assuming that two things are particularly bothering you in terms of flooding output stream:

One, The "weight summary":

  | Name | Type   | Params
--------------------------------
0 | l1   | Linear | 100 K 
1 | l2   | Linear | 1.3 K 
--------------------------------
...

Second, the progress bar:

Epoch 0:  74%|███████████   | 642/1874 [00:02<00:05, 233.59it/s, loss=0.85, v_num=wxln]

PyTorch Lightning provided very clear and elegant solutions for turning them off: Trainer(progress_bar_refresh_rate=0) for turning off progress bar and Trainer(weights_summary=None) for turning off weight summary.

ayandas
  • 2,070
  • 1
  • 13
  • 26
  • 3
    `progress_bar_refresh_rate` seems to be deprecated now. It is recommended to use `enable_progress_bar=False`. Or add a `TQDMProgressBar` Callback and adapt it's `refresh_rate` – Michael Boesl Jan 19 '22 at 07:49
0

Maybe try like that?

logging.getLogger("package").propagate = False
vvvvv
  • 25,404
  • 19
  • 49
  • 81
0

The solution was the combination of the @Artyrm Sergeev suggestion and the answer suggested here https://stackoverflow.com/a/52559560/13614416.

  1. Get all pytorch_lightning loggers:

    pl_loggers = [ logging.getLogger(name) for name in logging.root.manager.loggerDict if 'pytorch_lightning' in name ]

  2. Put the trainer.fit inside following construction:

    with io.capture_output() as captured: trainer.fit(...)