sktime / pytorch-forecasting

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

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

Open dara1400 opened 6 months ago

dara1400 commented 6 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 3 months 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 3 months 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 3 months ago

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

Good idea.