jdb78 / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
3.87k stars 611 forks source link

[ENH] option to turn off printing in prediction/inference #1576

Open dara1400 opened 3 months ago

dara1400 commented 3 months ago

I want to use model.predict in a loop. It keeps printing this:

GPU available: True (cuda), used: True TPU available: False, using: 0 TPU cores IPU available: False, using: 0 IPUs HPU available: False, using: 0 HPUs LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]

Is there way to stop it from printing?

IlIlllIIllIIlll commented 1 month ago

First, import the logging module:

import logging

Then, add the following line to suppress the message:

logging.getLogger("lightning.pytorch.utilities.rank_zero").setLevel(logging.WARNING)

This will prevent the following output from being printed:

GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs

Next, add this line to suppress another message:

logging.getLogger("lightning.pytorch.accelerators.cuda").setLevel(logging.WARNING)

This will stop the following output from appearing:

LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]

Good luck!

fkiraly commented 2 weeks ago

Related: https://github.com/sktime/sktime/pull/6891 - should we perhaps address this at the source, and add a verbosity option, @XinyuWuu?

XinyuWuu commented 2 weeks ago

Related: sktime/sktime#6891 - should we perhaps address this at the source, and add a verbosity option, @XinyuWuu?

Good idea.