Skip to content

Commit b728f86

Browse files
committed
Merge branch 'release/1.2-dev' of https://github.com/PyTorchLightning/pytorch-lightning into issue3827_test_gpu_and_cpu
2 parents 5c0b31c + d88cf4a commit b728f86

File tree

190 files changed

+4115
-1988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+4115
-1988
lines changed

.github/prepare-nightly_version.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
import os
33
import re
44

5-
PATH_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
5+
# set paths
6+
_PATH_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
7+
_PATH_INIT = os.path.join(_PATH_ROOT, 'pytorch_lightning', '__init__.py')
68

79
# get today date
810
now = datetime.datetime.now()
911
now_date = now.strftime("%Y%m%d")
10-
PATH_INIT = os.path.join(PATH_ROOT, 'pytorch_lightning', '__init__.py')
11-
print(f"prepare init '{PATH_INIT}' - replace version by {now_date}")
12-
with open(PATH_INIT, 'r') as fp:
12+
13+
print(f"prepare init '{_PATH_INIT}' - replace version by {now_date}")
14+
with open(_PATH_INIT, 'r') as fp:
1315
init = fp.read()
14-
init = re.sub(r'__version__ = [\d\.rc\'"]+', f'__version__ = "{now_date}"', init)
15-
with open(PATH_INIT, 'w') as fp:
16+
init = re.sub(r'__version__ = [\d\.\w\'"]+', f'__version__ = "{now_date}"', init)
17+
with open(_PATH_INIT, 'w') as fp:
1618
fp.write(init)

CHANGELOG.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,51 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77

8-
## [unreleased.BugFix] - YYYY-MM-DD
8+
9+
## [unreleased.Features] - YYYY-MM-DD
910

1011
### Added
1112

13+
- Add Support for multiple train loaders ([#1959](https://github.com/PyTorchLightning/pytorch-lightning/pull/1959))
14+
15+
- `Accuracy` metric now generalizes to Top-k accuracy for (multi-dimensional) multi-class inputs using the `top_k` parameter ([#4838](https://github.com/PyTorchLightning/pytorch-lightning/pull/4838))
16+
17+
- `Accuracy` metric now enables the computation of subset accuracy for multi-label or multi-dimensional multi-class inputs with the `subset_accuracy` parameter ([#4838](https://github.com/PyTorchLightning/pytorch-lightning/pull/4838))
18+
19+
- `HammingDistance` metric to compute the hamming distance (loss) ([#4838](https://github.com/PyTorchLightning/pytorch-lightning/pull/4838))
20+
21+
- Added `max_fpr` parameter to `auroc` metric for computing partial auroc metric ([#3790](https://github.com/PyTorchLightning/pytorch-lightning/pull/3790))
22+
23+
- `StatScores` metric to compute the number of true positives, false positives, true negatives and false negatives ([#4839](https://github.com/PyTorchLightning/pytorch-lightning/pull/4839))
24+
25+
- Added `R2Score` metric ([#5241](https://github.com/PyTorchLightning/pytorch-lightning/pull/5241))
26+
1227

1328
### Changed
1429

30+
- `stat_scores` metric now calculates stat scores over all classes and gains new parameters, in line with the new `StatScores` metric ([#4839](https://github.com/PyTorchLightning/pytorch-lightning/pull/4839))
31+
1532

1633
### Deprecated
1734

35+
- `stat_scores_multiple_classes` is deprecated in favor of `stat_scores` ([#4839](https://github.com/PyTorchLightning/pytorch-lightning/pull/4839))
36+
1837

1938
### Removed
2039

40+
- Removed deprecated checkpoint argument `filepath` ([#5321](https://github.com/PyTorchLightning/pytorch-lightning/pull/5321))
2141

22-
### Fixed
2342

24-
- Fixed trainer by default `None` in `DDPAccelerator` ([#4915](https://github.com/PyTorchLightning/pytorch-lightning/pull/4915))
43+
- Removed deprecated `Fbeta`, `f1_score` and `fbeta_score` metrics ([#5322](https://github.com/PyTorchLightning/pytorch-lightning/pull/5322))
2544

2645

27-
- Fixed `LightningOptimizer` exposes optimizer attributes ([#5095](https://github.com/PyTorchLightning/pytorch-lightning/pull/5095))
46+
- Removed deprecated `TrainResult` ([#5323](https://github.com/PyTorchLightning/pytorch-lightning/pull/5323))
47+
48+
49+
### Fixed
2850

51+
- Fixed distributed setting and `ddp_cpu` only with `num_processes>1` ([#5297](https://github.com/PyTorchLightning/pytorch-lightning/pull/5297))
2952

30-
- Do not warn when the `name` key is used in the `lr_scheduler` dict ([#5057](https://github.com/PyTorchLightning/pytorch-lightning/pull/5057))
3153

3254

3355
## [1.1.0] - 2020-12-09

benchmarks/test_sharded_parity.py

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,90 @@
11
import os
22
import platform
33
import time
4-
from typing import Union
4+
from typing import Type, Union
55

66
import pytest
77
import torch
88

99
from pytorch_lightning import Trainer, seed_everything
1010
from pytorch_lightning.plugins.ddp_plugin import DDPPlugin
1111
from pytorch_lightning.plugins.sharded_plugin import DDPShardedPlugin
12-
from pytorch_lightning.utilities import FAIRSCALE_AVAILABLE, NATIVE_AMP_AVAILABLE
12+
from pytorch_lightning.utilities import _FAIRSCALE_AVAILABLE, _NATIVE_AMP_AVAILABLE
1313
from tests.backends import DDPLauncher
1414
from tests.base.boring_model import BoringModel, RandomDataset
1515

1616

17-
@pytest.mark.skipif(platform.system() == "Windows",
18-
reason="Distributed training is not supported on Windows")
19-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
20-
def test_ddp_sharded_plugin_correctness_one_device():
21-
plugin_parity_test(
22-
accelerator='ddp_cpu',
23-
max_percent_speed_diff=0.15, # slower speed due to one CPU doing additional sequential memory saving calls
24-
plugin=DDPShardedPlugin(),
25-
model_cls=SeedTrainLoaderModel
26-
)
27-
28-
2917
@pytest.mark.skipif(not torch.cuda.is_available(), reason="requires GPU machine")
30-
@pytest.mark.skipif(platform.system() == "Windows",
31-
reason="Distributed training is not supported on Windows")
32-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
18+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
19+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
3320
def test_ddp_sharded_plugin_correctness_one_gpu():
3421
plugin_parity_test(
3522
gpus=1,
3623
accelerator='ddp_spawn',
3724
plugin=DDPShardedPlugin(),
38-
model_cls=SeedTrainLoaderModel
25+
model_cls=SeedTrainLoaderModel,
3926
)
4027

4128

42-
@pytest.mark.skipif(not NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
29+
@pytest.mark.skipif(not _NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
4330
@pytest.mark.skipif(not torch.cuda.is_available(), reason="requires GPU machine")
44-
@pytest.mark.skipif(platform.system() == "Windows",
45-
reason="Distributed training is not supported on Windows")
46-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
31+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
32+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
4733
def test_ddp_sharded_plugin_correctness_amp_one_gpu():
4834
plugin_parity_test(
4935
gpus=1,
5036
precision=16,
5137
accelerator='ddp_spawn',
5238
plugin=DDPShardedPlugin(),
53-
model_cls=SeedTrainLoaderModel
39+
model_cls=SeedTrainLoaderModel,
5440
)
5541

5642

5743
@pytest.mark.skip(reason="Not a critical test, skip till drone CI performance improves.")
5844
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
59-
@pytest.mark.skipif(platform.system() == "Windows",
60-
reason="Distributed training is not supported on Windows")
61-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
45+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
46+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
6247
def test_ddp_sharded_plugin_correctness_multi_gpu():
6348
plugin_parity_test(
6449
gpus=2,
6550
accelerator='ddp_spawn',
6651
plugin=DDPShardedPlugin(),
6752
model_cls=SeedTrainLoaderModel,
68-
max_percent_speed_diff=0.25
53+
max_percent_speed_diff=0.25,
6954
)
7055

7156

72-
@pytest.mark.skipif(not NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
73-
@pytest.mark.skipif(platform.system() == "Windows",
74-
reason="Distributed training is not supported on Windows")
57+
@pytest.mark.skipif(not _NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
58+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
7559
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
76-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
60+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
7761
def test_ddp_sharded_plugin_correctness_amp_multi_gpu():
7862
plugin_parity_test(
7963
gpus=2,
8064
precision=16,
8165
accelerator='ddp_spawn',
8266
plugin=DDPShardedPlugin(),
8367
model_cls=SeedTrainLoaderModel,
84-
max_percent_speed_diff=0.25
68+
max_percent_speed_diff=0.25,
8569
)
8670

8771

88-
@pytest.mark.skipif(not NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
89-
@pytest.mark.skipif(platform.system() == "Windows",
90-
reason="Distributed training is not supported on Windows")
72+
@pytest.mark.skipif(not _NATIVE_AMP_AVAILABLE, reason="Requires native AMP")
73+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
9174
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
92-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
75+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
9376
def test_ddp_string_sharded_plugin_correctness_amp_multi_gpu():
9477
plugin_parity_test(
9578
gpus=2,
9679
precision=16,
9780
accelerator='ddp_spawn',
9881
plugin='ddp_sharded',
9982
model_cls=SeedTrainLoaderModel,
100-
max_percent_speed_diff=0.25
83+
max_percent_speed_diff=0.25,
10184
)
10285

10386

104-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
87+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
10588
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
10689
@pytest.mark.skipif(not os.getenv("PL_RUNNING_SPECIAL_TESTS", '0') == '1',
10790
reason="test should be run outside of pytest")
@@ -116,7 +99,7 @@ def test_ddp_sharded_plugin_correctness_multi_gpu_ddp(tmpdir, args=None):
11699
)
117100

118101

119-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
102+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
120103
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
121104
@pytest.mark.skipif(not os.getenv("PL_RUNNING_SPECIAL_TESTS", '0') == '1',
122105
reason="test should be run outside of pytest")
@@ -133,9 +116,8 @@ def test_ddp_sharded_plugin_correctness_amp_multi_gpu_ddp(tmpdir, args=None):
133116

134117
@pytest.mark.skip(reason="Current issue with multiple optimizers and FairScale.")
135118
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
136-
@pytest.mark.skipif(platform.system() == "Windows",
137-
reason="Distributed training is not supported on Windows")
138-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
119+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
120+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
139121
def test_ddp_sharded_plugin_correctness_multi_gpu_multi_optim():
140122
"""
141123
Ensures same results using multiple optimizers across multiple GPUs
@@ -145,15 +127,14 @@ def test_ddp_sharded_plugin_correctness_multi_gpu_multi_optim():
145127
gpus=2,
146128
accelerator='ddp_spawn',
147129
model_cls=SeedTrainLoaderMultipleOptimizersModel,
148-
max_percent_speed_diff=0.25 # Increase speed diff since only 2 GPUs sharding 2 optimizers
130+
max_percent_speed_diff=0.25, # Increase speed diff since only 2 GPUs sharding 2 optimizers
149131
)
150132

151133

152134
@pytest.mark.skip(reason="Current issue with multiple optimizers and FairScale.")
153135
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
154-
@pytest.mark.skipif(platform.system() == "Windows",
155-
reason="Distributed training is not supported on Windows")
156-
@pytest.mark.skipif(not FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
136+
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
137+
@pytest.mark.skipif(not _FAIRSCALE_AVAILABLE, reason="Fairscale is not available")
157138
def test_ddp_sharded_plugin_correctness_multi_gpu_multi_optim_manual(tmpdir):
158139
"""
159140
Ensures using multiple optimizers across multiple GPUs with manual optimization
@@ -163,7 +144,7 @@ def test_ddp_sharded_plugin_correctness_multi_gpu_multi_optim_manual(tmpdir):
163144
gpus=2,
164145
accelerator='ddp_spawn',
165146
model_cls=SeedTrainLoaderManualModel,
166-
max_percent_speed_diff=0.25 # Increase speed diff since only 2 GPUs sharding 2 optimizers
147+
max_percent_speed_diff=0.25, # Increase speed diff since only 2 GPUs sharding 2 optimizers
167148
)
168149

169150

@@ -259,13 +240,14 @@ def record_ddp_fit_model_stats(trainer, model, use_cuda):
259240

260241

261242
def plugin_parity_test(
262-
model_cls: SeedTrainLoaderModel,
243+
model_cls: Type[SeedTrainLoaderModel],
263244
plugin: Union[str, DDPPlugin],
264245
seed: int = 42,
265246
accelerator: str = 'ddp_spawn',
266247
gpus: int = 0,
267248
precision: int = 32,
268-
max_percent_speed_diff: float = 0.1):
249+
max_percent_speed_diff: float = 0.1,
250+
):
269251
"""
270252
Ensures that the trained model is identical to the standard DDP implementation.
271253
Also checks for speed/memory regressions, we should expect always less memory but performance to fluctuate.

docs/source/amp.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Native torch
3131
When using PyTorch 1.6+ Lightning uses the native amp implementation to support 16-bit.
3232

3333
.. testcode::
34-
:skipif: not APEX_AVAILABLE and not NATIVE_AMP_AVAILABLE
34+
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE
3535

3636
# turn on 16-bit
3737
trainer = Trainer(precision=16)
@@ -73,7 +73,7 @@ Enable 16-bit
7373
^^^^^^^^^^^^^
7474

7575
.. testcode::
76-
:skipif: not APEX_AVAILABLE and not NATIVE_AMP_AVAILABLE
76+
:skipif: not _APEX_AVAILABLE and not _NATIVE_AMP_AVAILABLE
7777

7878
# turn on 16-bit
7979
trainer = Trainer(amp_level='O2', precision=16)
@@ -88,7 +88,7 @@ TPU 16-bit
8888
16-bit on TPUs is much simpler. To use 16-bit with TPUs set precision to 16 when using the TPU flag
8989

9090
.. testcode::
91-
:skipif: not TPU_AVAILABLE
91+
:skipif: not _TPU_AVAILABLE
9292

9393
# DEFAULT
9494
trainer = Trainer(tpu_cores=8, precision=32)

docs/source/conf.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# import m2r
1616
import builtins
1717
import glob
18-
import inspect
1918
import os
2019
import shutil
2120
import sys
@@ -359,12 +358,12 @@ def package_list_from_file(file):
359358
import torch
360359
361360
from pytorch_lightning.utilities import (
362-
NATIVE_AMP_AVAILABLE,
363-
APEX_AVAILABLE,
364-
XLA_AVAILABLE,
365-
TPU_AVAILABLE,
361+
_NATIVE_AMP_AVAILABLE,
362+
_APEX_AVAILABLE,
363+
_XLA_AVAILABLE,
364+
_TPU_AVAILABLE,
366365
)
367-
TORCHVISION_AVAILABLE = importlib.util.find_spec("torchvision") is not None
366+
_TORCHVISION_AVAILABLE = importlib.util.find_spec("torchvision") is not None
368367
369368
370369
"""

docs/source/introduction_guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Data
135135
Lightning operates on pure dataloaders. Here's the PyTorch code for loading MNIST.
136136

137137
.. testcode::
138-
:skipif: not TORCHVISION_AVAILABLE
138+
:skipif: not _TORCHVISION_AVAILABLE
139139

140140
from torch.utils.data import DataLoader, random_split
141141
from torchvision.datasets import MNIST
@@ -153,7 +153,7 @@ Lightning operates on pure dataloaders. Here's the PyTorch code for loading MNIS
153153

154154
.. testoutput::
155155
:hide:
156-
:skipif: os.path.isdir(os.path.join(os.getcwd(), 'MNIST')) or not TORCHVISION_AVAILABLE
156+
:skipif: os.path.isdir(os.path.join(os.getcwd(), 'MNIST')) or not _TORCHVISION_AVAILABLE
157157

158158
Downloading ...
159159
Extracting ...

0 commit comments

Comments
 (0)