Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import warning on unused optional libraries: wandb, gym #563

Open
its-dron opened this issue Feb 18, 2021 · 8 comments
Open

Import warning on unused optional libraries: wandb, gym #563

its-dron opened this issue Feb 18, 2021 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed refactoring

Comments

@its-dron
Copy link

its-dron commented Feb 18, 2021

馃悰 Bug

If wandb isn't installed, a warning is thrown upon import pl_bolts that alerts us to install wandb, before we've made any attempt nor effort to use it. The same warning occurs for gym.

>>> import pl_bolts
<PYENV>/site-packages/pl_bolts/utils/warnings.py:32: UserWarning: You want to use `wandb` which is not installed yet, install it with `pip install wandb`.
<PYENV>/site-packages/pl_bolts/utils/warnings.py:32: UserWarning: You want to use `gym` which is not installed yet, install it with `pip install gym`.

To Reproduce

  1. Create env with latest pl_bolts but without wandb.
  2. python -c 'import pl_bolts'

Expected behavior

No warnings about uninstalled downstream libraries until we attempt to use them.

Environment

pl_bolts 0.3.0

Additional context

Appears to have been introduced in #477

@its-dron its-dron added fix fixing issues... help wanted Extra attention is needed labels Feb 18, 2021
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@akihironitta akihironitta added enhancement New feature or request and removed fix fixing issues... help wanted Extra attention is needed labels Feb 19, 2021
@akihironitta akihironitta self-assigned this Feb 19, 2021
@akihironitta
Copy link
Contributor

akihironitta commented Feb 19, 2021

@its-dron Hi, thank you for your suggestion! Your suggestion sounds reasonable!

@PyTorchLightning/core-bolts We could probably remove these (noisy?) warnings and also make sure to raise ModuleNotFoundError with a helpful message when instantiating an object from class or when calling functions like this. I'll quickly send a PR if you agree to this.

@akihironitta akihironitta removed their assignment Mar 30, 2021
@akihironitta akihironitta added the help wanted Extra attention is needed label Mar 30, 2021
@akihironitta akihironitta added this to To do in Code Health / Refatoring via automation Mar 30, 2021
@braun-steven
Copy link

braun-steven commented Dec 8, 2022

Does anyone have a solution to this? The UnderReviewWarning message is spamming everything. The following filter does not work:

import warnings
from pl_bolts.utils.stability import UnderReviewWarning

warnings.simplefilter("ignore", UnderReviewWarning)

Edit:

Is pl-bolts doing something wrong with the warnings?

import warnings

warnings.simplefilter("ignore")
warnings.warn("test")
import pl_bolts  # Raises "UnderReviewWarning"
exit()

The warnings.warn("test") call is ignored as expected but import pl_bolts raises four UnderReviewWarnings. Why are they not caught with the catch-all ignore filter?

@shubhamkulkarni01
Copy link

This is causing real problems for DDP usage with multiple workers in DataLoaders. When running with DDP_spawn with multi-worker dataloaders, the message prints hundreds of times per epoch.

I have isolated the issue with this warning to the following line (line 75 in stability.py):

filterwarnings("once", message, UnderReviewWarning)

This attaches the new filter to the beginning of warnings.filters in accordance with https://docs.python.org/3/library/warnings.html#warnings.filterwarnings.

Printing warning.filters before and after importing pl_bolts confirms this issue. Warning filters match the first filter with the necessary conditions, which means it will always match one of the "once" filters attached by pl_bolts that is prepended to the list instead of your "ignore" filter.

My proposed fix is to change that line to read
filterwarnings("once", message, UnderReviewWarning, append=True). This way, user attached filters are respected.

I'm new to lightning-bolts so I'm not sure how I can raise this as a PR, but would be happy to do so! Currently have it patched in my own code with the following hacky solution:

    import warnings
    warnings.simplefilter("ignore")

    original_filterwarnings = warnings.filterwarnings
    def _filterwarnings(*args, **kwargs):
        return original_filterwarnings(*args, **{**kwargs, 'append':True})
    warnings.filterwarnings = _filterwarnings

@elliott-imhoff
Copy link

To avoid disabling all warnings, I changed warnings.simplefilter("ignore") in @shubhamkulkarni01's above solution to warnings.filterwarnings("ignore", message=r"The feature ([^\s]+) is currently marked under review") before importing pl_bolts. Works pretty well, but this is an incredibly annoying warning. Looks pretty bad first time using this library that just importing raises multiple warning messages, which is greatly exacerbated with multiple workers.

@bkmi
Copy link

bkmi commented Feb 23, 2023

To avoid disabling all warnings, I changed warnings.simplefilter("ignore") in @shubhamkulkarni01's above solution to warnings.filterwarnings("ignore", message=r"The feature ([^\s]+) is currently marked under review") before importing pl_bolts. Works pretty well, but this is an incredibly annoying warning. Looks pretty bad first time using this library that just importing raises multiple warning messages, which is greatly exacerbated with multiple workers.

It is also not so clear how to stop this behavior when using hydra's instantiate function for example.

@Borda
Copy link
Member

Borda commented Jun 30, 2023

hello, is this still present in the latest 0.7.0?

@100jy
Copy link

100jy commented Jul 12, 2023

hello, is this still present in the latest 0.7.0?

"I'm on version 0.7.0, and I'm still having this issue but @shubhamkulkarni01's solution works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed refactoring
Development

No branches or pull requests

8 participants