diff --git a/pytorch_lightning/loggers/comet.py b/pytorch_lightning/loggers/comet.py index 1d24676d..01d0602a 100644 --- a/pytorch_lightning/loggers/comet.py +++ b/pytorch_lightning/loggers/comet.py @@ -16,9 +16,16 @@ try: except ImportError: # pragma: no-cover # For more information, see: https://www.comet.ml/docs/python-sdk/releases/#release-300 from comet_ml.papi import API # pragma: no-cover + + _COMET_AVAILABLE = True except ImportError: # pragma: no-cover - raise ImportError('You want to use `comet_ml` logger which is not installed yet,' # pragma: no-cover - ' install it with `pip install comet-ml`.') + CometExperiment = None + CometExistingExperiment = None + CometOfflineExperiment = None + CometBaseExperiment = None + API = None + _COMET_AVAILABLE = False + import torch from torch import is_tensor @@ -93,6 +100,9 @@ class CometLogger(LightningLoggerBase): experiment_key: Optional[str] = None, **kwargs): + if not _COMET_AVAILABLE: + raise ImportError('You want to use `comet_ml` logger which is not installed yet,' + ' install it with `pip install comet-ml`.') super().__init__() self._experiment = None diff --git a/pytorch_lightning/loggers/mlflow.py b/pytorch_lightning/loggers/mlflow.py index 74c51893..5d060a2d 100644 --- a/pytorch_lightning/loggers/mlflow.py +++ b/pytorch_lightning/loggers/mlflow.py @@ -10,9 +10,11 @@ from typing import Optional, Dict, Any, Union try: import mlflow from mlflow.tracking import MlflowClient + _MLFLOW_AVAILABLE = True except ImportError: # pragma: no-cover - raise ImportError('You want to use `mlflow` logger which is not installed yet,' # pragma: no-cover - ' install it with `pip install mlflow`.') + mlflow = None + MlflowClient = None + _MLFLOW_AVAILABLE = False from pytorch_lightning import _logger as log from pytorch_lightning.loggers.base import LightningLoggerBase @@ -54,11 +56,16 @@ class MLFlowLogger(LightningLoggerBase): tags: A dictionary tags for the experiment. """ + def __init__(self, experiment_name: str = 'default', tracking_uri: Optional[str] = None, tags: Optional[Dict[str, Any]] = None, save_dir: Optional[str] = None): + + if not _MLFLOW_AVAILABLE: + raise ImportError('You want to use `mlflow` logger which is not installed yet,' + ' install it with `pip install mlflow`.') super().__init__() if not tracking_uri and save_dir: tracking_uri = f'file:{os.sep * 2}{save_dir}' diff --git a/pytorch_lightning/loggers/neptune.py b/pytorch_lightning/loggers/neptune.py index 051dbadd..1cffe656 100644 --- a/pytorch_lightning/loggers/neptune.py +++ b/pytorch_lightning/loggers/neptune.py @@ -10,9 +10,11 @@ from PIL.Image import Image try: import neptune from neptune.experiments import Experiment + _NEPTUNE_AVAILABLE = True except ImportError: # pragma: no-cover - raise ImportError('You want to use `neptune` logger which is not installed yet,' # pragma: no-cover - ' install it with `pip install neptune-client`.') + neptune = None + Experiment = None + _NEPTUNE_AVAILABLE = False import torch from torch import is_tensor @@ -179,6 +181,9 @@ class NeptuneLogger(LightningLoggerBase): properties: Optional[Dict[str, Any]] = None, tags: Optional[List[str]] = None, **kwargs): + if not _NEPTUNE_AVAILABLE: + raise ImportError('You want to use `neptune` logger which is not installed yet,' + ' install it with `pip install neptune-client`.') super().__init__() self.api_key = api_key self.project_name = project_name diff --git a/pytorch_lightning/loggers/test_tube.py b/pytorch_lightning/loggers/test_tube.py index 7f382c3f..ae095d85 100644 --- a/pytorch_lightning/loggers/test_tube.py +++ b/pytorch_lightning/loggers/test_tube.py @@ -7,9 +7,10 @@ from typing import Optional, Dict, Any, Union try: from test_tube import Experiment + _TEST_TUBE_AVAILABLE = True except ImportError: # pragma: no-cover - raise ImportError('You want to use `test_tube` logger which is not installed yet,' # pragma: no-cover - ' install it with `pip install test-tube`.') + Experiment = None + _TEST_TUBE_AVAILABLE = False from pytorch_lightning.loggers.base import LightningLoggerBase from pytorch_lightning.utilities.distributed import rank_zero_only @@ -62,6 +63,10 @@ class TestTubeLogger(LightningLoggerBase): debug: bool = False, version: Optional[int] = None, create_git_tag: bool = False): + + if not _TEST_TUBE_AVAILABLE: + raise ImportError('You want to use `test_tube` logger which is not installed yet,' + ' install it with `pip install test-tube`.') super().__init__() self.save_dir = save_dir self._name = name diff --git a/pytorch_lightning/loggers/trains.py b/pytorch_lightning/loggers/trains.py index ca4f38c6..5b0d1aeb 100644 --- a/pytorch_lightning/loggers/trains.py +++ b/pytorch_lightning/loggers/trains.py @@ -14,7 +14,11 @@ from PIL.Image import Image try: import trains from trains import Task + _TRAINS_AVAILABLE = True except ImportError: # pragma: no-cover + trains = None + Task = None + _TRAINS_AVAILABLE = False raise ImportError('You want to use `TRAINS` logger which is not installed yet,' # pragma: no-cover ' install it with `pip install trains`.') @@ -91,6 +95,9 @@ class TrainsLogger(LightningLoggerBase): auto_connect_frameworks: bool = True, auto_resource_monitoring: bool = True ) -> None: + if not _TRAINS_AVAILABLE: + raise ImportError('You want to use `test_tube` logger which is not installed yet,' + ' install it with `pip install test-tube`.') super().__init__() if self.bypass_mode(): self._trains = None diff --git a/pytorch_lightning/loggers/wandb.py b/pytorch_lightning/loggers/wandb.py index 3b15677a..c8841805 100644 --- a/pytorch_lightning/loggers/wandb.py +++ b/pytorch_lightning/loggers/wandb.py @@ -11,9 +11,11 @@ import torch.nn as nn try: import wandb from wandb.wandb_run import Run + _WANDB_AVAILABLE = True except ImportError: # pragma: no-cover - raise ImportError('You want to use `wandb` logger which is not installed yet,' # pragma: no-cover - ' install it with `pip install wandb`.') + wandb = None + Run = None + _WANDB_AVAILABLE = False from pytorch_lightning.loggers.base import LightningLoggerBase from pytorch_lightning.utilities import rank_zero_only @@ -67,6 +69,9 @@ class WandbLogger(LightningLoggerBase): experiment=None, entity=None, group: Optional[str] = None): + if not _WANDB_AVAILABLE: + raise ImportError('You want to use `wandb` logger which is not installed yet,' # pragma: no-cover + ' install it with `pip install wandb`.') super().__init__() self._name = name self._save_dir = save_dir