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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor imports of logger dependencies #4860

Merged
merged 41 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dd5bff7
refactor imports of logger dependencies
Borda Nov 25, 2020
6692539
fix
Borda Nov 26, 2020
26fff84
fix
Borda Nov 26, 2020
2e8757a
fix
Borda Nov 26, 2020
2a56e83
name
Borda Nov 26, 2020
e9b3ed2
fix
Borda Nov 26, 2020
027ad89
mocks
Borda Dec 17, 2020
fc9c5e8
fix tests
Dec 17, 2020
2a4e893
fix mlflow
Dec 17, 2020
5d37fa0
fix test tube
Dec 17, 2020
32b81e6
fix wandb import check
Dec 17, 2020
99f13b8
whitespace
Dec 17, 2020
d3ff69c
name
Borda Dec 20, 2020
e113c65
name
Borda Dec 20, 2020
ce2c6c0
hack
Borda Dec 20, 2020
0183cb9
hack
Borda Dec 20, 2020
0d24ce2
rev
Borda Dec 20, 2020
3d3b08b
fix
Borda Dec 20, 2020
43041ce
update mlflow import check
awaelchli Dec 21, 2020
fc2a905
try without installing conda dep
awaelchli Dec 21, 2020
d1ff17b
Merge branch 'master' into refactor/imports-loggers
Borda Dec 29, 2020
6a23db1
Merge branch 'master' into refactor/imports-loggers
Borda Jan 1, 2021
62193fb
.
Borda Jan 1, 2021
ddcdf7a
.
Borda Jan 1, 2021
a6b2582
.
Borda Jan 1, 2021
f567eb2
.
Borda Jan 1, 2021
67f0501
.
Borda Jan 1, 2021
442289f
.
Borda Jan 1, 2021
5130cc2
.
Borda Jan 1, 2021
5faf354
.
Borda Jan 1, 2021
494e51f
.
Borda Jan 1, 2021
7395f0b
Merge branch 'master' into refactor/imports-loggers
tchaton Jan 4, 2021
1fe2f1e
Merge branch 'master' into refactor/imports-loggers
Borda Jan 4, 2021
63b22f4
Merge branch 'master' into refactor/imports-loggers
Borda Jan 5, 2021
7e2664a
Merge branch 'master' into refactor/imports-loggers
Borda Jan 5, 2021
b2cbf7c
flake8
Borda Jan 5, 2021
cda0f87
Merge branch 'master' into refactor/imports-loggers
Borda Jan 5, 2021
9ec8616
try 3.7
Borda Jan 5, 2021
10e4be5
Merge branch 'refactor/imports-loggers' of https://github.com/PyTorch…
Borda Jan 5, 2021
2706064
Merge branch 'master' into refactor/imports-loggers
Borda Jan 5, 2021
87de356
Apply suggestions from code review
Borda Jan 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_test-base.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI base testing
name: CI basic testing
Borda marked this conversation as resolved.
Show resolved Hide resolved

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on: # Trigger the workflow on push or pull request, but only for the master branch
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_test-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
# os: [ubuntu-20.04]
python-version: [3.7]
python-version: [3.6]
Borda marked this conversation as resolved.
Show resolved Hide resolved
pytorch-version: [1.3, 1.4, 1.5, 1.6, 1.7, 1.8]

# Timeout: https://stackoverflow.com/a/59076067/4521646
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Lightning can automatically export to ONNX or TorchScript for those cases.

| System / PyTorch ver. | 1.3 (min. req.)* | 1.4 | 1.5 | 1.6 | 1.7 (latest) | 1.8 (nightly) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| Conda py3.7 [linux] | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) |
Borda marked this conversation as resolved.
Show resolved Hide resolved
| Conda py3.6 [linux] | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) | [![PyTorch & Conda](https://github.com/PyTorchLightning/pytorch-lightning/workflows/PyTorch%20&%20Conda/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22PyTorch+%26+Conda%22+branch%3Amaster) |
Borda marked this conversation as resolved.
Show resolved Hide resolved
| Linux py3.7 [GPUs**] | - | - | - | [![GPUs Status](http://104.154.220.231/api/badges/PyTorchLightning/pytorch-lightning/status.svg)](http://104.154.220.231/PyTorchLightning/pytorch-lightning) | - | - |
| Linux py3.{6,7} [TPUs***] | - | - | - | [![TPU tests](https://github.com/PyTorchLightning/pytorch-lightning/workflows/TPU%20tests/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22TPU+tests%22+branch%3Amaster) | [![TPU tests](https://github.com/PyTorchLightning/pytorch-lightning/workflows/TPU%20tests/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22TPU+tests%22+branch%3Amaster) | - |
| Linux py3.{6,7} | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - | - | - | [![CI complete testing](https://github.com/PyTorchLightning/pytorch-lightning/workflows/CI%20complete%20testing/badge.svg?branch=master&event=push)](https://github.com/PyTorchLightning/pytorch-lightning/actions?query=workflow%3A%22CI+testing%22) | - |
Expand Down
39 changes: 12 additions & 27 deletions pytorch_lightning/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,25 @@
'CSVLogger',
]

try:
# needed to prevent ImportError and duplicated logs.
environ["COMET_DISABLE_AUTO_LOGGING"] = "1"
from pytorch_lightning.loggers.comet import _COMET_AVAILABLE, CometLogger
from pytorch_lightning.loggers.mlflow import _MLFLOW_AVAILABLE, MLFlowLogger
from pytorch_lightning.loggers.neptune import _NEPTUNE_AVAILABLE, NeptuneLogger
from pytorch_lightning.loggers.test_tube import _TESTTUBE_AVAILABLE, TestTubeLogger
from pytorch_lightning.loggers.wandb import _WANDB_AVAILABLE, WandbLogger

from pytorch_lightning.loggers.comet import CometLogger
except ImportError: # pragma: no-cover
del environ["COMET_DISABLE_AUTO_LOGGING"] # pragma: no-cover
else:
if _COMET_AVAILABLE:
__all__.append('CometLogger')
# needed to prevent ImportError and duplicated logs.
environ["COMET_DISABLE_AUTO_LOGGING"] = "1"
Borda marked this conversation as resolved.
Show resolved Hide resolved

try:
from pytorch_lightning.loggers.mlflow import MLFlowLogger
except ImportError: # pragma: no-cover
pass # pragma: no-cover
else:
if _MLFLOW_AVAILABLE:
__all__.append('MLFlowLogger')

try:
from pytorch_lightning.loggers.neptune import NeptuneLogger
except ImportError: # pragma: no-cover
pass # pragma: no-cover
else:
if _NEPTUNE_AVAILABLE:
__all__.append('NeptuneLogger')

try:
from pytorch_lightning.loggers.test_tube import TestTubeLogger
except ImportError: # pragma: no-cover
pass # pragma: no-cover
else:
if _TESTTUBE_AVAILABLE:
__all__.append('TestTubeLogger')

try:
from pytorch_lightning.loggers.wandb import WandbLogger
except ImportError: # pragma: no-cover
pass # pragma: no-cover
else:
if _WANDB_AVAILABLE:
__all__.append('WandbLogger')
34 changes: 16 additions & 18 deletions pytorch_lightning/loggers/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
from argparse import Namespace
from typing import Any, Dict, Optional, Union

try:
import comet_ml
import torch
from torch import is_tensor

except ModuleNotFoundError: # pragma: no-cover
comet_ml = None
CometExperiment = None
CometExistingExperiment = None
CometOfflineExperiment = None
API = None
generate_guid = None
else:
from pytorch_lightning import _logger as log
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only, _module_available
from pytorch_lightning.utilities.exceptions import MisconfigurationException

_COMET_AVAILABLE = _module_available("comet_ml")

if _COMET_AVAILABLE:
import comet_ml
from comet_ml import ExistingExperiment as CometExistingExperiment
from comet_ml import Experiment as CometExperiment
from comet_ml import OfflineExperiment as CometOfflineExperiment
Expand All @@ -41,14 +42,11 @@
except ImportError: # pragma: no-cover
Borda marked this conversation as resolved.
Show resolved Hide resolved
# For more information, see: https://www.comet.ml/docs/python-sdk/releases/#release-300
from comet_ml.papi import API # pragma: no-cover

import torch
from torch import is_tensor

from pytorch_lightning import _logger as log
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only
from pytorch_lightning.utilities.exceptions import MisconfigurationException
else:
# needed for test mocks, these tests shall be updated
comet_ml = None
CometExperiment, CometExistingExperiment, CometOfflineExperiment = None, None, None
API = None


class CometLogger(LightningLoggerBase):
Expand Down
20 changes: 12 additions & 8 deletions pytorch_lightning/loggers/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@
from time import time
from typing import Any, Dict, Optional, Union

try:
import mlflow
from mlflow.tracking import MlflowClient
except ModuleNotFoundError: # pragma: no-cover
mlflow = None
MlflowClient = None


from pytorch_lightning import _logger as log
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only, rank_zero_warn
from pytorch_lightning.utilities import rank_zero_only, rank_zero_warn, _module_available


LOCAL_FILE_URI_PREFIX = "file:"


_MLFLOW_AVAILABLE = _module_available("mlflow")
try:
Borda marked this conversation as resolved.
Show resolved Hide resolved
import mlflow
from mlflow.tracking import MlflowClient
# todo: there seems to be still some remaining import error with Conda env
except ImportError:
_MLFLOW_AVAILABLE = False
mlflow, MlflowClient = None, None
Borda marked this conversation as resolved.
Show resolved Hide resolved


class MLFlowLogger(LightningLoggerBase):
"""
Log using `MLflow <https://mlflow.org>`_.
Expand Down
20 changes: 11 additions & 9 deletions pytorch_lightning/loggers/neptune.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@
--------------
"""
from argparse import Namespace
from typing import Any, Dict, Iterable, List, Optional, Union

try:
import neptune
from neptune.experiments import Experiment
except ImportError: # pragma: no-cover
neptune = None
Experiment = None
from typing import Any, Dict, Iterable, Optional, Union

import torch
from torch import is_tensor

from pytorch_lightning import _logger as log
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only
from pytorch_lightning.utilities import rank_zero_only, _module_available

_NEPTUNE_AVAILABLE = _module_available("neptune")

if _NEPTUNE_AVAILABLE:
import neptune
from neptune.experiments import Experiment
else:
# needed for test mocks, these tests shall be updated
neptune, Experiment = None, None


class NeptuneLogger(LightningLoggerBase):
Expand Down
13 changes: 8 additions & 5 deletions pytorch_lightning/loggers/test_tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
from argparse import Namespace
from typing import Any, Dict, Optional, Union

try:
from test_tube import Experiment
except ImportError: # pragma: no-cover
Experiment = None

from pytorch_lightning.core.lightning import LightningModule
from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import _module_available
from pytorch_lightning.utilities.distributed import rank_zero_only, rank_zero_warn

_TESTTUBE_AVAILABLE = _module_available("test_tube")

if _TESTTUBE_AVAILABLE:
from test_tube import Experiment
else:
Experiment = None


class TestTubeLogger(LightningLoggerBase):
r"""
Expand Down
16 changes: 9 additions & 7 deletions pytorch_lightning/loggers/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

import torch.nn as nn

from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only, _module_available
from pytorch_lightning.utilities.warning_utils import WarningCache

_WANDB_AVAILABLE = _module_available("wandb")
Borda marked this conversation as resolved.
Show resolved Hide resolved

try:
import wandb
from wandb.wandb_run import Run
except ImportError: # pragma: no-cover
wandb = None
Run = None

from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only
from pytorch_lightning.utilities.warning_utils import WarningCache
except ImportError:
# needed for test mocks, these tests shall be updated
wandb, Run = None, None


class WandbLogger(LightningLoggerBase):
Expand Down
13 changes: 9 additions & 4 deletions tests/loggers/test_mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


from pytorch_lightning import Trainer
from pytorch_lightning.loggers import MLFlowLogger
from pytorch_lightning.loggers import _MLFLOW_AVAILABLE, MLFlowLogger
from tests.base import EvalModelTemplate


Expand Down Expand Up @@ -120,7 +120,7 @@ def test_mlflow_log_dir(client, mlflow, tmpdir):

def test_mlflow_logger_dirs_creation(tmpdir):
""" Test that the logger creates the folders and files in the right place. """
if not importlib.util.find_spec('mlflow'):
if not _MLFLOW_AVAILABLE:
pytest.xfail("test for explicit file creation requires mlflow dependency to be installed.")

assert not os.listdir(tmpdir)
Expand All @@ -137,8 +137,13 @@ def test_mlflow_logger_dirs_creation(tmpdir):
assert set(os.listdir(tmpdir / exp_id)) == {run_id, 'meta.yaml'}

model = EvalModelTemplate()
trainer = Trainer(default_root_dir=tmpdir, logger=logger, max_epochs=1, limit_val_batches=3,
log_gpu_memory=True)
trainer = Trainer(
default_root_dir=tmpdir,
logger=logger,
max_epochs=1,
limit_val_batches=3,
log_gpu_memory=True,
Borda marked this conversation as resolved.
Show resolved Hide resolved
)
trainer.fit(model)
assert set(os.listdir(tmpdir / exp_id)) == {run_id, 'meta.yaml'}
assert 'epoch' in os.listdir(tmpdir / exp_id / run_id / 'metrics')
Expand Down