Skip to content

Commit 8b76a28

Browse files
authored
Merge branch 'master' into ckpt-fix
2 parents 7799df8 + 384e124 commit 8b76a28

30 files changed

+618
-93
lines changed

.codecov.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Validation check:
33
# $ curl --data-binary @.codecov.yml https://codecov.io/validate
44

5+
6+
# https://docs.codecov.io/docs/codecovyml-reference
57
codecov:
8+
bot: "codecov-io"
9+
strict_yaml_branch: "yaml-config"
10+
require_ci_to_pass: yes
611
notify:
7-
require_ci_to_pass: yes
12+
# after_n_builds: 2
13+
wait_for_ci: yes
814

915
coverage:
1016
precision: 0 # 2 = xx.xx%, 0 = xx%
@@ -16,15 +22,15 @@ coverage:
1622
default:
1723
against: auto
1824
target: 99% # specify the target coverage for each commit status
19-
threshold: 20% # allow this little decrease on project
25+
threshold: 30% # allow this little decrease on project
2026
# https://github.com/codecov/support/wiki/Filtering-Branches
2127
# branches: master
2228
if_ci_failed: error
2329
# https://github.com/codecov/support/wiki/Patch-Status
2430
patch:
2531
default:
2632
against: auto
27-
target: 40% # specify the target "X%" coverage to hit
33+
target: 50% # specify the target "X%" coverage to hit
2834
# threshold: 50% # allow this much decrease on patch
2935
changes: false
3036

.drone.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ name: torch-GPU
77
steps:
88
- name: testing
99
image: nvcr.io/nvidia/pytorch:20.02-py3
10+
environment:
11+
SLURM_LOCALID: 0
12+
CODECOV_TOKEN:
13+
from_secret: codecov_token
1014
commands:
1115
- python --version
1216
- pip install pip -U
1317
- pip --version
1418
- nvidia-smi
1519
#- pip install torch==1.3
1620
- pip install -r requirements.txt --user
17-
- pip install coverage pytest pytest-cov pytest-flake8
21+
- pip install coverage pytest pytest-cov pytest-flake8 codecov
1822
- pip install -r ./tests/requirements.txt --user
1923
- pip list
20-
- export SLURM_LOCALID=0
2124
- python -c "import torch ; print(' & '.join([torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())]) if torch.cuda.is_available() else 'only CPU')"
2225
- coverage run --source pytorch_lightning -m py.test pytorch_lightning tests pl_examples -v --doctest-modules # --flake8
23-
- coverage report
26+
- codecov --token $CODECOV_TOKEN # --pr $DRONE_PULL_REQUEST --build $DRONE_BUILD_NUMBER --branch $DRONE_BRANCH --commit $DRONE_COMMIT --tag $DRONE_TAG

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
88

99
### Added
1010

11+
- Added `TrainsLogger` class ([#1122](https://github.com/PyTorchLightning/pytorch-lightning/pull/1122))
1112
- Added type hints to `pytorch_lightning.core` ([#946](https://github.com/PyTorchLightning/pytorch-lightning/pull/946))
1213
- Added support for IterableDataset in validation and testing ([#1104](https://github.com/PyTorchLightning/pytorch-lightning/pull/1104))
14+
- Added support for non-primitive types in hparams for TensorboardLogger ([#1130](https://github.com/PyTorchLightning/pytorch-lightning/pull/1130))
15+
1316

1417
### Changed
1518

@@ -25,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2528

2629
### Fixed
2730

31+
- Fixed bug related to type cheking of `ReduceLROnPlateau` lr schedulers([#1114](https://github.com/PyTorchLightning/pytorch-lightning/issues/1114))
2832
- Fixed a bug to ensure lightning checkpoints to be backward compatible ([#1132](https://github.com/PyTorchLightning/pytorch-lightning/pull/1132))
2933

3034
## [0.7.1] - 2020-03-07
@@ -65,6 +69,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6569

6670
### Changed
6771

72+
- Improved `NeptuneLogger` by adding `close_after_fit` argument to allow logging after training([#908](https://github.com/PyTorchLightning/pytorch-lightning/pull/1084))
6873
- Changed default TQDM to use `tqdm.auto` for prettier outputs in IPython notebooks ([#752](https://github.com/PyTorchLightning/pytorch-lightning/pull/752))
6974
- Changed `pytorch_lightning.logging` to `pytorch_lightning.loggers` ([#767](https://github.com/PyTorchLightning/pytorch-lightning/pull/767))
7075
- Moved the default `tqdm_dict` definition from Trainer to `LightningModule`, so it can be overridden by the user ([#749](https://github.com/PyTorchLightning/pytorch-lightning/pull/749))

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[![PyPI Status](https://badge.fury.io/py/pytorch-lightning.svg)](https://badge.fury.io/py/pytorch-lightning)
1111
[![PyPI Status](https://pepy.tech/badge/pytorch-lightning)](https://pepy.tech/project/pytorch-lightning)
12-
[![Coverage](docs/source/_static/images/coverage.svg)](https://github.com/PytorchLightning/pytorch-lightning/tree/master/tests#running-coverage)
12+
[![codecov](https://codecov.io/gh/PyTorchLightning/pytorch-lightning/branch/master/graph/badge.svg)](https://codecov.io/gh/PyTorchLightning/pytorch-lightning)
1313
[![CodeFactor](https://www.codefactor.io/repository/github/pytorchlightning/pytorch-lightning/badge)](https://www.codefactor.io/repository/github/pytorchlightning/pytorch-lightning)
1414

1515
[![ReadTheDocs](https://readthedocs.org/projects/pytorch-lightning/badge/?version=0.7.1)](https://pytorch-lightning.readthedocs.io/en/0.7.1/)

docs/source/_static/images/coverage.svg

-21
This file was deleted.

docs/source/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ def setup(app):
297297
MOCK_REQUIRE_PACKAGES.append(pkg.rstrip())
298298

299299
# TODO: better parse from package since the import name and package name may differ
300-
MOCK_MANUAL_PACKAGES = ['torch', 'torchvision', 'test_tube', 'mlflow', 'comet_ml', 'wandb', 'neptune']
300+
MOCK_MANUAL_PACKAGES = ['torch', 'torchvision', 'test_tube',
301+
'mlflow', 'comet_ml', 'wandb', 'neptune', 'trains']
301302
autodoc_mock_imports = MOCK_REQUIRE_PACKAGES + MOCK_MANUAL_PACKAGES
302303
# for mod_name in MOCK_REQUIRE_PACKAGES:
303304
# sys.modules[mod_name] = mock.Mock()

docs/source/early_stopping.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Enable Early Stopping
1111
---------------------
1212
There are two ways to enable early stopping.
1313

14-
.. note:: See: :ref:`trainer`
14+
.. seealso:: :ref:`trainer`
1515

1616
.. code-block:: python
1717
@@ -35,4 +35,4 @@ To disable early stopping pass ``False`` to the `early_stop_callback`.
3535
Note that ``None`` will not disable early stopping but will lead to the
3636
default behaviour.
3737

38-
.. note:: See: :ref:`trainer`
38+
.. seealso:: :ref:`trainer`

docs/source/experiment_logging.rst

+33-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Comet.ml
77
`Comet.ml <https://www.comet.ml/site/>`_ is a third-party logger.
88
To use CometLogger as your logger do the following.
99

10-
.. note:: See: :ref:`comet` docs.
10+
.. seealso:: :ref:`comet` docs.
1111

1212
.. code-block:: python
1313
@@ -38,7 +38,7 @@ Neptune.ai
3838
`Neptune.ai <https://neptune.ai/>`_ is a third-party logger.
3939
To use Neptune.ai as your logger do the following.
4040

41-
.. note:: See: :ref:`neptune` docs.
41+
.. seealso:: :ref:`neptune` docs.
4242

4343
.. code-block:: python
4444
@@ -62,12 +62,40 @@ The Neptune.ai is available anywhere except ``__init__`` in your LightningModule
6262
some_img = fake_image()
6363
self.logger.experiment.add_image('generated_images', some_img, 0)
6464
65+
allegro.ai TRAINS
66+
^^^^^^^^^^^^^^^^^
67+
68+
`allegro.ai <https://github.com/allegroai/trains/>`_ is a third-party logger.
69+
To use TRAINS as your logger do the following.
70+
71+
.. seealso:: :ref:`trains` docs.
72+
73+
.. code-block:: python
74+
75+
from pytorch_lightning.loggers import TrainsLogger
76+
77+
trains_logger = TrainsLogger(
78+
project_name="examples",
79+
task_name="pytorch lightning test"
80+
)
81+
trainer = Trainer(logger=trains_logger)
82+
83+
The TrainsLogger is available anywhere in your LightningModule
84+
85+
.. code-block:: python
86+
87+
class MyModule(pl.LightningModule):
88+
89+
def __init__(self, ...):
90+
some_img = fake_image()
91+
self.logger.log_image('debug', 'generated_image_0', some_img, 0)
92+
6593
Tensorboard
6694
^^^^^^^^^^^
6795

6896
To use `Tensorboard <https://pytorch.org/docs/stable/tensorboard.html>`_ as your logger do the following.
6997

70-
.. note:: See: TensorBoardLogger :ref:`tf-logger`
98+
.. seealso:: TensorBoardLogger :ref:`tf-logger`
7199

72100
.. code-block:: python
73101
@@ -93,7 +121,7 @@ Test Tube
93121
`Test Tube <https://github.com/williamFalcon/test-tube>`_ is a tensorboard logger but with nicer file structure.
94122
To use TestTube as your logger do the following.
95123

96-
.. note:: See: TestTube :ref:`testTube`
124+
.. seealso:: TestTube :ref:`testTube`
97125

98126
.. code-block:: python
99127
@@ -118,7 +146,7 @@ Wandb
118146
`Wandb <https://www.wandb.com/>`_ is a third-party logger.
119147
To use Wandb as your logger do the following.
120148

121-
.. note:: See: :ref:`wandb` docs
149+
.. seealso:: :ref:`wandb` docs
122150

123151
.. code-block:: python
124152

docs/source/experiment_reporting.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Control log writing frequency
2222
Writing to a logger can be expensive. In Lightning you can set the interval at which you
2323
want to log using this trainer flag.
2424

25-
.. note:: See: :ref:`trainer`
25+
.. seealso:: :ref:`trainer`
2626

2727
.. code-block:: python
2828
@@ -32,7 +32,7 @@ want to log using this trainer flag.
3232
Log metrics
3333
^^^^^^^^^^^
3434

35-
To plot metrics into whatever logger you passed in (tensorboard, comet, neptune, etc...)
35+
To plot metrics into whatever logger you passed in (tensorboard, comet, neptune, TRAINS, etc...)
3636

3737
1. training_epoch_end, validation_epoch_end, test_epoch_end will all log anything in the "log" key of the return dict.
3838

docs/source/fast_training.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Force training for min or max epochs
1616
-------------------------------------
1717
It can be useful to force training for a minimum number of epochs or limit to a max number.
1818

19-
.. note:: See: :ref:`trainer`
19+
.. seealso:: :ref:`trainer`
2020

2121
.. code-block:: python
2222

docs/source/introduction_guide.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ First, change the runtime to TPU (and reinstall lightning).
472472

473473
Next, install the required xla library (adds support for PyTorch on TPUs)
474474

475-
.. code-block:: python
475+
.. code-block::
476476
477477
import collections
478478
from datetime import datetime, timedelta

docs/source/multi_gpu.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This will make your code scale to any arbitrary number of GPUs or TPUs with Ligh
3838
# with lightning
3939
def forward(self, x):
4040
z = torch.Tensor(2, 3)
41-
z = z.type_as(x.type())
41+
z = z.type_as(x)
4242
4343
Remove samplers
4444
^^^^^^^^^^^^^^^

docs/source/training_tricks.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Accumulate gradients
77
Accumulated gradients runs K small batches of size N before doing a backwards pass.
88
The effect is a large effective batch size of size KxN.
99

10-
.. note:: See: :ref:`trainer`
10+
.. seealso:: :ref:`trainer`
1111

1212
.. code-block:: python
1313
@@ -20,7 +20,7 @@ Gradient Clipping
2020
Gradient clipping may be enabled to avoid exploding gradients. Specifically, this will `clip the gradient
2121
norm <https://pytorch.org/docs/stable/nn.html#torch.nn.utils.clip_grad_norm_>`_ computed over all model parameters together.
2222

23-
.. note:: See: :ref:`trainer`
23+
.. seealso:: :ref:`trainer`
2424

2525
.. code-block:: python
2626

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ dependencies:
3232
- comet_ml>=1.0.56
3333
- wandb>=0.8.21
3434
- neptune-client>=0.4.4
35+
- trains>=0.13.3

pytorch_lightning/core/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def training_step(self, batch, batch_idx):
228228
229229
# put the z on the appropriate gpu or tpu core
230230
z = sample_noise()
231-
z = z.type_as(x.type())
231+
z = z.type_as(x)
232232
233233
----------
234234

pytorch_lightning/core/lightning.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
99

1010
import torch
11-
import torch.distributed as dist
1211
from torch import Tensor
12+
from torch.distributed import init_process_group
1313
from torch.nn.parallel import DistributedDataParallel
1414
from torch.optim import Adam
1515
from torch.optim.optimizer import Optimizer
@@ -859,7 +859,7 @@ def init_ddp_connection(self):
859859

860860
root_node = self.trainer.resolve_root_node_address(root_node)
861861
os.environ['MASTER_ADDR'] = root_node
862-
dist.init_process_group('nccl', rank=proc_rank, world_size=world_size)
862+
init_process_group('nccl', rank=proc_rank, world_size=world_size)
863863

864864
def configure_apex(
865865
self,

pytorch_lightning/loggers/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,9 @@ def any_lightning_module_function_or_hook(...):
119119
__all__.append('WandbLogger')
120120
except ImportError:
121121
pass
122+
123+
try:
124+
from .trains import TrainsLogger
125+
__all__.append('TrainsLogger')
126+
except ImportError:
127+
pass

pytorch_lightning/loggers/base.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from functools import wraps
55
from typing import Union, Optional, Dict, Iterable, Any, Callable, List
66

7+
import torch
8+
79

810
def rank_zero_only(fn: Callable):
911
"""Decorate a logger method to run it only on the process with rank 0.
@@ -42,7 +44,8 @@ def log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None):
4244
"""
4345
pass
4446

45-
def _convert_params(self, params: Union[Dict[str, Any], Namespace]) -> Dict[str, Any]:
47+
@staticmethod
48+
def _convert_params(params: Union[Dict[str, Any], Namespace]) -> Dict[str, Any]:
4649
# in case converting from namespace
4750
if isinstance(params, Namespace):
4851
params = vars(params)
@@ -52,6 +55,29 @@ def _convert_params(self, params: Union[Dict[str, Any], Namespace]) -> Dict[str,
5255

5356
return params
5457

58+
@staticmethod
59+
def _sanitize_params(params: Dict[str, Any]) -> Dict[str, Any]:
60+
"""Returns params with non-primitvies converted to strings for logging
61+
62+
>>> params = {"float": 0.3,
63+
... "int": 1,
64+
... "string": "abc",
65+
... "bool": True,
66+
... "list": [1, 2, 3],
67+
... "namespace": Namespace(foo=3),
68+
... "layer": torch.nn.BatchNorm1d}
69+
>>> import pprint
70+
>>> pprint.pprint(LightningLoggerBase._sanitize_params(params)) # doctest: +NORMALIZE_WHITESPACE
71+
{'bool': True,
72+
'float': 0.3,
73+
'int': 1,
74+
'layer': "<class 'torch.nn.modules.batchnorm.BatchNorm1d'>",
75+
'list': '[1, 2, 3]',
76+
'namespace': 'Namespace(foo=3)',
77+
'string': 'abc'}
78+
"""
79+
return {k: v if type(v) in [bool, int, float, str, torch.Tensor] else str(v) for k, v in params.items()}
80+
5581
@abstractmethod
5682
def log_hyperparams(self, params: argparse.Namespace):
5783
"""Record hyperparameters.

0 commit comments

Comments
 (0)