Pytorch-lightning: PL shouldn't override PYTHONWARNINGS

Created on 16 Nov 2020  ·  4Comments  ·  Source: PyTorchLightning/pytorch-lightning

🐛 Bug

This is bad:

https://github.com/PyTorchLightning/pytorch-lightning/blob/c208ac68c88a23977ae3d156dabb1440a9f1c9f3/pytorch_lightning/trainer/trainer.py#L71

What a user to do if they need to use PYTHONWARNINGS?

Adding to the existing setting is the way, but overriding it is taking away control from the user.

And after removing this override I still can't figure why I'm getting these:

PYTHONWARNINGS=ignore python -c "import pytorch_lightning"
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/util.py:36: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  from collections import namedtuple, Mapping, Sequence
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/vendor/graphql-core-1.1/graphql/type/directives.py:55: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  assert isinstance(locations, collections.Iterable), 'Must provide locations for directive.'

PYTHONWARNINGS=ignore / -W ignore doesn't get rid of those.

There must be yet another override somewhere else.

I reported the deprecations https://github.com/wandb/client/issues/1503, but clearly something in PL or its dependencies is stealing user's control away still.

Thanks.

3rd-party bug / fix help wanted let's do it!

All 4 comments

@teddykoker

This makes sense to me, I'll submit a PR to remove that line. I searched the full codebase and couldn't find any other usage of PYTHONWARNINGS.

Additionally I checked the dependencies in requirements.txt and couldn't find PYTHONWARNINGS. I know some of the logging libraries override code in places, but I can't think of an easy way to recursively search all dependencies for this override.

It has something to do with wandb, I reduced it to:

PYTHONWARNINGS=ignore python -c "import pytorch_lightning.loggers.wandb"
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/util.py:36: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  from collections import namedtuple, Mapping, Sequence
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/vendor/graphql-core-1.1/graphql/type/directives.py:55: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  assert isinstance(locations, collections.Iterable), 'Must provide locations for directive.'

Strangely, the following doesn't emit any warnings:

python -c "import wandb; from wandb.wandb_run import Run"

so there must be some interaction going there, that it happens when invoked from pytorch_lightning.loggers.wandb.

(One can isolate the cause relatively quickly, by commenting out all of __init__.py, and then bisecting, until you find which import causes the problem, then stepping into that module and repeating this process again. Took me probably 5 min to reduce it to wandb - but at times it's a slower process)

nailed it:

PYTHONWARNINGS=ignore python -c "import mlflow, wandb"
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/util.py:36: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
  from collections import namedtuple, Mapping, Sequence
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/wandb/vendor/graphql-core-1.1/graphql/type/directives.py:55: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Pyth

The guilty line is:
https://github.com/mlflow/mlflow/blob/2f5b870d81b92d0e3558c3b36a820f8eaf3cda59/mlflow/__init__.py#L45

warnings.filterwarnings("module", category=DeprecationWarning)

bug report filed: https://github.com/mlflow/mlflow/issues/3704

Was this page helpful?
0 / 5 - 0 ratings

Related issues

awaelchli picture awaelchli  ·  3Comments

williamFalcon picture williamFalcon  ·  3Comments

as754770178 picture as754770178  ·  3Comments

anthonytec2 picture anthonytec2  ·  3Comments

monney picture monney  ·  3Comments