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

Mocking loggers (part 1, wandb) #3596

Merged
merged 9 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def package_list_from_file(file):
# mock also base packages when we are on RTD since we don't install them there
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements/base.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements/extra.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements/loggers.txt'))

MOCK_MANUAL_PACKAGES = [
'torchvision',
Expand Down
2 changes: 1 addition & 1 deletion docs/source/experiment_logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ First, install the package:

Then configure the logger and pass it to the :class:`~pytorch_lightning.trainer.trainer.Trainer`:

.. testcode::
.. code-block:: python

from pytorch_lightning.loggers import WandbLogger
wandb_logger = WandbLogger(offline=True)
Expand Down
13 changes: 6 additions & 7 deletions pytorch_lightning/loggers/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
try:
import wandb
from wandb.wandb_run import Run
_WANDB_AVAILABLE = True
except ImportError: # pragma: no-cover
wandb = None
Run = None
_WANDB_AVAILABLE = False

from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
from pytorch_lightning.utilities import rank_zero_only
Expand Down Expand Up @@ -57,10 +55,11 @@ class WandbLogger(LightningLoggerBase):
:func:`wandb.init` can be passed as keyword arguments in this logger.

Example:
>>> from pytorch_lightning.loggers import WandbLogger
>>> from pytorch_lightning import Trainer
>>> wandb_logger = WandbLogger()
>>> trainer = Trainer(logger=wandb_logger)

from pytorch_lightning.loggers import WandbLogger
from pytorch_lightning import Trainer
wandb_logger = WandbLogger()
trainer = Trainer(logger=wandb_logger)

See Also:
- `Tutorial <https://app.wandb.ai/cayush/pytorchlightning/reports/
Expand All @@ -82,7 +81,7 @@ def __init__(
experiment=None,
**kwargs
):
if not _WANDB_AVAILABLE:
if wandb is None:
raise ImportError('You want to use `wandb` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install wandb`.')
super().__init__()
Expand Down
3 changes: 2 additions & 1 deletion requirements/extra.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# extended list of package dependencies to reach full functionality

# TODO: this shall be removed as we mock them in tests
neptune-client>=0.4.109
comet-ml>=3.1.12
mlflow>=1.0.0
test_tube>=0.7.5
wandb>=0.8.21, <0.10.0 # higher version mess with system paths

matplotlib>=3.1.1
# no need to install with [pytorch] as pytorch is already installed and torchvision is required only for Horovod examples
horovod>=0.19.2
Expand Down
6 changes: 6 additions & 0 deletions requirements/loggers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# all supported loggers
neptune-client>=0.4.109
comet-ml>=3.1.12
mlflow>=1.0.0
test_tube>=0.7.5
wandb>=0.8.21
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ def load_long_description():
extras = {
# 'docs': load_requirements(file_name='docs.txt'),
'examples': load_requirements(file_name='examples.txt'),
'loggers': load_requirements(file_name='loggers.txt'),
'extra': load_requirements(file_name='extra.txt'),
'test': load_requirements(file_name='test.txt')
}
extras['dev'] = extras['extra'] + extras['test']
extras['dev'] = extras['extra'] + extras['loggers'] + extras['test']
extras['all'] = extras['dev'] + extras['examples'] # + extras['docs']

# https://packaging.python.org/discussions/install-requires-vs-requirements /
Expand Down
2 changes: 0 additions & 2 deletions tests/models/test_amp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
from unittest.mock import MagicMock

import pytest
import torch
import wandb

import tests.base.develop_pipelines as tpipes
import tests.base.develop_utils as tutils
Expand Down