From 11e694df6a741340981da2d91c7fb79a14a56c99 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 09:49:19 +0200 Subject: [PATCH 01/45] no cov --- .github/workflows/ci-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 5929209f26c4b..2c6b139c613c4 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -122,8 +122,8 @@ jobs: run: | # tox --sitepackages # flake8 . - coverage run --source pytorch_lightning -m py.test pytorch_lightning tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml - coverage report + python -m pytest pytorch_lightning tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml + # coverage report - name: Upload pytest test results uses: actions/upload-artifact@master From fc8be64ab7bbf6e727511e4e95d7cf210b522ad8 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 10:19:53 +0200 Subject: [PATCH 02/45] no cov --- .github/workflows/ci-testing.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 2c6b139c613c4..f042381485c5e 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -139,6 +139,7 @@ jobs: python setup.py check --metadata --strict python setup.py sdist twine check dist/* + #- name: Try install package # if: ! startsWith(matrix.os, 'windows') # run: | @@ -146,7 +147,7 @@ jobs: # pip install --editable . ; cd .. & python -c "import pytorch_lightning ; print(pytorch_lightning.__version__)" # deactivate ; rm -rf vEnv - - name: Statistics - if: success() - run: | - coverage report + #- name: Statistics + # if: success() + # run: | + # coverage report From 4895cfd4d576c6c505e8a369a0217359a4689182 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 12:24:26 +0200 Subject: [PATCH 03/45] ReduceOp --- .github/workflows/ci-testing.yml | 1 + pytorch_lightning/metrics/converters.py | 18 +++++++++----- pytorch_lightning/metrics/sklearns.py | 31 +++++++++++++++---------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index f042381485c5e..dd251931efb28 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -122,6 +122,7 @@ jobs: run: | # tox --sitepackages # flake8 . + # NOTE: run coverage on tests does not propagare faler status for Win, https://github.com/nedbat/coveragepy/issues/1003 python -m pytest pytorch_lightning tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml # coverage report diff --git a/pytorch_lightning/metrics/converters.py b/pytorch_lightning/metrics/converters.py index 9803500445618..d75e6f18947cc 100644 --- a/pytorch_lightning/metrics/converters.py +++ b/pytorch_lightning/metrics/converters.py @@ -10,8 +10,14 @@ import numpy as np import torch from torch.utils.data._utils.collate import np_str_obj_array_pattern - from pytorch_lightning.utilities.apply_func import apply_to_collection +from pytorch_lightning.utilities import rank_zero_warn + +try: + from torch.distributed import ReduceOp +except ImportError: + ReduceOp = None + rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') def _apply_to_inputs(func_to_apply: Callable, *dec_args, **dec_kwargs) -> Callable: @@ -217,7 +223,7 @@ def _tensor_collection_metric_conversion(func_to_decorate: Callable) -> Callable def _sync_ddp_if_available(result: Union[torch.Tensor], group: Optional[Any] = None, - reduce_op: Optional[torch.distributed.ReduceOp] = None, + reduce_op: Optional[ReduceOp] = None, ) -> torch.Tensor: """ Function to reduce the tensors from several ddp processes to one master process @@ -247,7 +253,7 @@ def _sync_ddp_if_available(result: Union[torch.Tensor], def sync_ddp(group: Optional[Any] = None, - reduce_op: Optional[torch.distributed.ReduceOp] = None) -> Callable: + reduce_op: Optional[ReduceOp] = None) -> Callable: """ This decorator syncs a functions outputs across different processes for DDP. @@ -269,7 +275,7 @@ def decorator_fn(func_to_decorate): def numpy_metric(group: Optional[Any] = None, - reduce_op: Optional[torch.distributed.ReduceOp] = None) -> Callable: + reduce_op: Optional[ReduceOp] = None) -> Callable: """ This decorator shall be used on all function metrics working on numpy arrays. It handles the argument conversion and DDP reduction for metrics working on numpy. @@ -292,7 +298,7 @@ def decorator_fn(func_to_decorate): def tensor_metric(group: Optional[Any] = None, - reduce_op: Optional[torch.distributed.ReduceOp] = None) -> Callable: + reduce_op: Optional[ReduceOp] = None) -> Callable: """ This decorator shall be used on all function metrics working on tensors. It handles the argument conversion and DDP reduction for metrics working on tensors. @@ -314,7 +320,7 @@ def decorator_fn(func_to_decorate): def tensor_collection_metric(group: Optional[Any] = None, - reduce_op: Optional[torch.distributed.ReduceOp] = None) -> Callable: + reduce_op: Optional[ReduceOp] = None) -> Callable: """ This decorator shall be used on all function metrics working on tensors and returning collections that cannot be converted to tensors. diff --git a/pytorch_lightning/metrics/sklearns.py b/pytorch_lightning/metrics/sklearns.py index 5a2ec0bdf6222..607ce1a6b6c8a 100644 --- a/pytorch_lightning/metrics/sklearns.py +++ b/pytorch_lightning/metrics/sklearns.py @@ -5,6 +5,13 @@ from pytorch_lightning import _logger as lightning_logger from pytorch_lightning.metrics.metric import NumpyMetric +from pytorch_lightning.utilities import rank_zero_warn + +try: + from torch.distributed import ReduceOp +except ImportError: + ReduceOp = None + rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') class SklearnMetric(NumpyMetric): @@ -21,7 +28,7 @@ def __init__( self, metric_name: str, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, **kwargs, ): """ @@ -83,7 +90,7 @@ def __init__( self, normalize: bool = True, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -137,7 +144,7 @@ class AUC(SklearnMetric): def __init__( self, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -175,7 +182,7 @@ def __init__( self, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -241,7 +248,7 @@ class ConfusionMatrix(SklearnMetric): def __init__( self, labels: Optional[Sequence] = None, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -305,7 +312,7 @@ def __init__( pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -398,7 +405,7 @@ def __init__( pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -489,7 +496,7 @@ def __init__( pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -577,7 +584,7 @@ def __init__( pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -664,7 +671,7 @@ def __init__( self, pos_label: Union[str, int] = 1, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -738,7 +745,7 @@ def __init__( self, pos_label: Union[str, int] = 1, reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: @@ -796,7 +803,7 @@ def __init__( self, average: Optional[str] = 'macro', reduce_group: Any = torch.distributed.group.WORLD, - reduce_op: Any = torch.distributed.ReduceOp.SUM, + reduce_op: Any = ReduceOp.SUM, ): """ Args: From f36a758a6a313970d321c74ae2c5f51a0143af55 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 13:04:32 +0200 Subject: [PATCH 04/45] group --- pytorch_lightning/metrics/sklearns.py | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pytorch_lightning/metrics/sklearns.py b/pytorch_lightning/metrics/sklearns.py index 607ce1a6b6c8a..ec6ad297b5396 100644 --- a/pytorch_lightning/metrics/sklearns.py +++ b/pytorch_lightning/metrics/sklearns.py @@ -8,9 +8,9 @@ from pytorch_lightning.utilities import rank_zero_warn try: - from torch.distributed import ReduceOp + from torch.distributed import ReduceOp, group except ImportError: - ReduceOp = None + ReduceOp, group = None, None rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') @@ -27,7 +27,7 @@ class SklearnMetric(NumpyMetric): def __init__( self, metric_name: str, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, **kwargs, ): @@ -89,7 +89,7 @@ class Accuracy(SklearnMetric): def __init__( self, normalize: bool = True, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -143,7 +143,7 @@ class AUC(SklearnMetric): """ def __init__( self, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -181,7 +181,7 @@ class AveragePrecision(SklearnMetric): def __init__( self, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -247,7 +247,7 @@ class ConfusionMatrix(SklearnMetric): """ def __init__( self, labels: Optional[Sequence] = None, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -311,7 +311,7 @@ def __init__( self, labels: Optional[Sequence] = None, pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -404,7 +404,7 @@ def __init__( labels: Optional[Sequence] = None, pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -495,7 +495,7 @@ def __init__( labels: Optional[Sequence] = None, pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -583,7 +583,7 @@ def __init__( labels: Optional[Sequence] = None, pos_label: Union[str, int] = 1, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -670,7 +670,7 @@ class PrecisionRecallCurve(SklearnMetric): def __init__( self, pos_label: Union[str, int] = 1, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -744,7 +744,7 @@ class ROC(SklearnMetric): def __init__( self, pos_label: Union[str, int] = 1, - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ @@ -802,7 +802,7 @@ class AUROC(SklearnMetric): def __init__( self, average: Optional[str] = 'macro', - reduce_group: Any = torch.distributed.group.WORLD, + reduce_group: Any = group.WORLD, reduce_op: Any = ReduceOp.SUM, ): """ From 425f7bc09f4646bb56879ac08525df85ee54690a Mon Sep 17 00:00:00 2001 From: Justus Schock <12886177+justusschock@users.noreply.github.com> Date: Thu, 25 Jun 2020 13:39:31 +0200 Subject: [PATCH 05/45] reduce_op.sum --- pytorch_lightning/metrics/converters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/metrics/converters.py b/pytorch_lightning/metrics/converters.py index d75e6f18947cc..2fda19d186aa3 100644 --- a/pytorch_lightning/metrics/converters.py +++ b/pytorch_lightning/metrics/converters.py @@ -16,7 +16,8 @@ try: from torch.distributed import ReduceOp except ImportError: - ReduceOp = None + class ReduceOp: + SUM = None rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') From bd283c9bab4faf76634ed95d0bd35402b99ef142 Mon Sep 17 00:00:00 2001 From: Justus Schock <12886177+justusschock@users.noreply.github.com> Date: Thu, 25 Jun 2020 13:40:34 +0200 Subject: [PATCH 06/45] Update sklearns.py --- pytorch_lightning/metrics/sklearns.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/metrics/sklearns.py b/pytorch_lightning/metrics/sklearns.py index ec6ad297b5396..c2fef58b53d06 100644 --- a/pytorch_lightning/metrics/sklearns.py +++ b/pytorch_lightning/metrics/sklearns.py @@ -10,7 +10,12 @@ try: from torch.distributed import ReduceOp, group except ImportError: - ReduceOp, group = None, None + class ReduceOp: + SUM = None + + + class group: + WORLD = None rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') From ac1dd23a8cc22cbc04619cda73e9707c8da5c0ba Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 16:05:08 +0200 Subject: [PATCH 07/45] formatting --- pytorch_lightning/metrics/sklearns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/metrics/sklearns.py b/pytorch_lightning/metrics/sklearns.py index c2fef58b53d06..567a75a1278e4 100644 --- a/pytorch_lightning/metrics/sklearns.py +++ b/pytorch_lightning/metrics/sklearns.py @@ -13,9 +13,9 @@ class ReduceOp: SUM = None - class group: WORLD = None + rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') From 8e0d0bce831e77b183fda4804bef69d5179decc9 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 16:08:56 +0200 Subject: [PATCH 08/45] horovod --- tests/models/data/horovod/train_default_model.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index 6bf0e3aa9c4b2..a26c81cc82150 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -21,14 +21,20 @@ import os import sys -import horovod.torch as hvd +from pytorch_lightning import Trainer +from pytorch_lightning.callbacks import ModelCheckpoint +from pytorch_lightning.utilities import rank_zero_warn + +try: + import horovod.torch as hvd +except ImportError: + hvd = None + rank_zero_warn('You requested to import Horovod which is missing or not supported for your OS.') PATH_HERE = os.path.abspath(os.path.dirname(__file__)) PATH_ROOT = os.path.join(PATH_HERE, '..', '..', '..', '..') sys.path.insert(0, os.path.abspath(PATH_ROOT)) -from pytorch_lightning import Trainer # noqa: E402 -from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402 from tests.base import EvalModelTemplate # noqa: E402 from tests.base.utils import set_random_master_port, run_model_test # noqa: E402 From 3d3f8660a7ca41bcc9c972aaed9af9907a1a9075 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Thu, 25 Jun 2020 17:48:40 +0200 Subject: [PATCH 09/45] Apply suggestions from code review --- pytorch_lightning/metrics/converters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytorch_lightning/metrics/converters.py b/pytorch_lightning/metrics/converters.py index 2fda19d186aa3..65f69eea2ffc7 100644 --- a/pytorch_lightning/metrics/converters.py +++ b/pytorch_lightning/metrics/converters.py @@ -18,6 +18,7 @@ except ImportError: class ReduceOp: SUM = None + rank_zero_warn('Unsupported `ReduceOp` for distributed computing.') From 2c73e18d50248a89acf2227ef421b867f18b5a41 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 17:49:44 +0200 Subject: [PATCH 10/45] horovod --- tests/models/data/horovod/train_default_model.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index a26c81cc82150..61c882fb37525 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -21,20 +21,18 @@ import os import sys -from pytorch_lightning import Trainer -from pytorch_lightning.callbacks import ModelCheckpoint -from pytorch_lightning.utilities import rank_zero_warn - try: import horovod.torch as hvd except ImportError: hvd = None - rank_zero_warn('You requested to import Horovod which is missing or not supported for your OS.') + raise Warning('You requested to import Horovod which is missing or not supported for your OS.') PATH_HERE = os.path.abspath(os.path.dirname(__file__)) PATH_ROOT = os.path.join(PATH_HERE, '..', '..', '..', '..') sys.path.insert(0, os.path.abspath(PATH_ROOT)) +from pytorch_lightning import Trainer # noqa: E402 +from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402 from tests.base import EvalModelTemplate # noqa: E402 from tests.base.utils import set_random_master_port, run_model_test # noqa: E402 From b62d9006825143c534030048535d843c6c2428f7 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 18:28:26 +0200 Subject: [PATCH 11/45] horovod --- tests/models/data/horovod/train_default_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index 61c882fb37525..63fdf6dd08322 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -23,7 +23,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): hvd = None raise Warning('You requested to import Horovod which is missing or not supported for your OS.') From ff8731f25ee516941a967c00384f0fd1c25a3c5b Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 18:51:10 +0200 Subject: [PATCH 12/45] horovod --- tests/models/data/horovod/train_default_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index 63fdf6dd08322..f0d626733f64d 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -23,8 +23,7 @@ try: import horovod.torch as hvd -except (ModuleNotFoundError, ImportError): - hvd = None +except Exception: raise Warning('You requested to import Horovod which is missing or not supported for your OS.') PATH_HERE = os.path.abspath(os.path.dirname(__file__)) From 62e30153d783469cc8dfa0f319cbf9994a207931 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 19:27:20 +0200 Subject: [PATCH 13/45] horovod --- pytorch_lightning/trainer/data_loading.py | 2 +- pytorch_lightning/trainer/distrib_data_parallel.py | 2 +- pytorch_lightning/trainer/distrib_parts.py | 2 +- pytorch_lightning/trainer/evaluation_loop.py | 2 +- pytorch_lightning/trainer/trainer.py | 2 +- pytorch_lightning/trainer/training_io.py | 2 +- pytorch_lightning/trainer/training_loop.py | 2 +- tests/models/data/horovod/train_default_model.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pytorch_lightning/trainer/data_loading.py b/pytorch_lightning/trainer/data_loading.py index 7400b390c239f..06ab7b316e1c2 100644 --- a/pytorch_lightning/trainer/data_loading.py +++ b/pytorch_lightning/trainer/data_loading.py @@ -35,7 +35,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/distrib_data_parallel.py b/pytorch_lightning/trainer/distrib_data_parallel.py index 8818b899a21cd..8f61c2f2ae227 100644 --- a/pytorch_lightning/trainer/distrib_data_parallel.py +++ b/pytorch_lightning/trainer/distrib_data_parallel.py @@ -139,7 +139,7 @@ def train_fx(trial_hparams, cluster_manager, _): try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/distrib_parts.py b/pytorch_lightning/trainer/distrib_parts.py index 6fecd27f0bf40..acc928db61968 100644 --- a/pytorch_lightning/trainer/distrib_parts.py +++ b/pytorch_lightning/trainer/distrib_parts.py @@ -38,7 +38,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/evaluation_loop.py b/pytorch_lightning/trainer/evaluation_loop.py index 59614c2d5fb39..c1374b8750c86 100644 --- a/pytorch_lightning/trainer/evaluation_loop.py +++ b/pytorch_lightning/trainer/evaluation_loop.py @@ -144,7 +144,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index 9d1736e6eb836..3243d088bbb54 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -52,7 +52,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/training_io.py b/pytorch_lightning/trainer/training_io.py index 605efc0bbcc9c..48f3fc5054def 100644 --- a/pytorch_lightning/trainer/training_io.py +++ b/pytorch_lightning/trainer/training_io.py @@ -114,7 +114,7 @@ try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/pytorch_lightning/trainer/training_loop.py b/pytorch_lightning/trainer/training_loop.py index d9ca689167b70..848a627d5ce09 100644 --- a/pytorch_lightning/trainer/training_loop.py +++ b/pytorch_lightning/trainer/training_loop.py @@ -183,7 +183,7 @@ def training_step(self, batch, batch_idx): try: import horovod.torch as hvd -except ImportError: +except (ModuleNotFoundError, ImportError): HOROVOD_AVAILABLE = False else: HOROVOD_AVAILABLE = True diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index f0d626733f64d..4630e00061f80 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -23,7 +23,7 @@ try: import horovod.torch as hvd -except Exception: +except (ModuleNotFoundError, ImportError): raise Warning('You requested to import Horovod which is missing or not supported for your OS.') PATH_HERE = os.path.abspath(os.path.dirname(__file__)) From 0a47a586d789b8f6200ed88fd6837037725a2d10 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 23:42:56 +0200 Subject: [PATCH 14/45] ci --- .github/workflows/code-formatting.yml | 46 +++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 68696a52c7848..a837e4bcb6b08 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -1,4 +1,4 @@ -name: "Check Formatting - Black" +name: "Check Code Formatting" on: # Trigger the workflow on push or pull request, # but only for the master branch @@ -10,7 +10,7 @@ on: - master jobs: - check_code_formatting: + code-black: name: Check code formatting with Black runs-on: ubuntu-latest steps: @@ -25,3 +25,45 @@ jobs: - name: Run Black run: echo "LGTM" # run black --skip-string-normalization --config=pyproject.toml --check . # TODO, uncomment + + python-types: + name: Python static type checking with Pyright + runs-on: ubuntu-latest + + # Timeout: https://stackoverflow.com/a/59076067/4521646 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Note: This uses an internal pip API and may not always work + # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow + - name: Cache pip + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-pip- + + - name: Install dependencies + run: | + # python -m pip install --upgrade --user pip + pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q + HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q + # pip install tox coverage + python --version + pip --version + pip list + shell: bash + + - name: Set up node + uses: actions/setup-node@v1 + + - name: Install pyright + run: | + npm install pyright + + - name: Run type checking + run: | + $(npm bin)/pyright --project .pyrightconfig.json From b63f0a691ad07fc80fbf3c0d6dd5a2f39720f067 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 25 Jun 2020 23:46:58 +0200 Subject: [PATCH 15/45] print --- tests/models/data/horovod/train_default_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index 4630e00061f80..d1702d282064c 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -24,7 +24,7 @@ try: import horovod.torch as hvd except (ModuleNotFoundError, ImportError): - raise Warning('You requested to import Horovod which is missing or not supported for your OS.') + print('You requested to import Horovod which is missing or not supported for your OS.') PATH_HERE = os.path.abspath(os.path.dirname(__file__)) PATH_ROOT = os.path.join(PATH_HERE, '..', '..', '..', '..') From 6ccdf81df02e38ca40d6a567699a8242ee9ba99f Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 00:00:20 +0200 Subject: [PATCH 16/45] ci --- .github/workflows/ci-testing.yml | 2 +- .github/workflows/code-formatting.yml | 9 ++++++--- .github/workflows/docker-builds.yml | 6 +++++- .github/workflows/pypi-release.yml | 3 +-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index dd251931efb28..f082c38934ddc 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -37,7 +37,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index a837e4bcb6b08..25c8d3fc33e5e 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v1.1.1 + uses: actions/setup-python@v2 with: python-version: 3.8 - name: Install Black @@ -35,6 +35,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 # Note: This uses an internal pip API and may not always work # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow @@ -42,9 +45,9 @@ jobs: uses: actions/cache@v1 with: path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} + key: ${{ runner.os }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip- + ${{ runner.os }}-pip- - name: Install dependencies run: | diff --git a/.github/workflows/docker-builds.yml b/.github/workflows/docker-builds.yml index c5b65d71525ea..6fb7f771d4f0f 100644 --- a/.github/workflows/docker-builds.yml +++ b/.github/workflows/docker-builds.yml @@ -16,7 +16,11 @@ jobs: python_version: [3.6, 3.7, 3.8] pytorch_version: [1.3, 1.4, 1.5] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 - name: Publish Master to Docker # publish master diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 041f67bc05b38..7c8f6b5a793e6 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -19,8 +19,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - uses: actions/setup-python@v2 with: python-version: 3.7 From b575914237d7b6409d636341270aa6c179b49429 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 00:35:06 +0200 Subject: [PATCH 17/45] timeout --- .github/workflows/ci-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index f082c38934ddc..40571f2570197 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: os: macOS-10.15 # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 15 + timeout-minutes: 25 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 859b0c51458097c3a0b1b07e0ca88652a3b1850b Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 00:59:59 +0200 Subject: [PATCH 18/45] timeout --- .github/workflows/ci-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 40571f2570197..99cfb5b324f03 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: os: macOS-10.15 # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 25 + timeout-minutes: 45 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From a747b28537bd1a4be2a73c79e7a489ad3291d05b Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 09:55:51 +0200 Subject: [PATCH 19/45] time --- .github/workflows/ci-testing.yml | 2 +- pytorch_lightning/core/saving.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 99cfb5b324f03..db390d4dbd61b 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: os: macOS-10.15 # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 45 + timeout-minutes: 50 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/pytorch_lightning/core/saving.py b/pytorch_lightning/core/saving.py index 4ff019a20c6ae..9907f1276e0a5 100644 --- a/pytorch_lightning/core/saving.py +++ b/pytorch_lightning/core/saving.py @@ -279,7 +279,7 @@ def load_hparams_from_tags_csv(tags_csv: str) -> Dict[str, Any]: """Load hparams from a file. >>> hparams = Namespace(batch_size=32, learning_rate=0.001, data_root='./any/path/here') - >>> path_csv = './testing-hparams.csv' + >>> path_csv = 'testing-hparams.csv' >>> save_hparams_to_tags_csv(path_csv, hparams) >>> hparams_new = load_hparams_from_tags_csv(path_csv) >>> vars(hparams) == hparams_new From d1728905d8af08ff0e7e7715ac9b7d46080d9de6 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 10:21:30 +0200 Subject: [PATCH 20/45] fix --- pytorch_lightning/core/saving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/core/saving.py b/pytorch_lightning/core/saving.py index 9907f1276e0a5..30ef214b4b493 100644 --- a/pytorch_lightning/core/saving.py +++ b/pytorch_lightning/core/saving.py @@ -279,7 +279,7 @@ def load_hparams_from_tags_csv(tags_csv: str) -> Dict[str, Any]: """Load hparams from a file. >>> hparams = Namespace(batch_size=32, learning_rate=0.001, data_root='./any/path/here') - >>> path_csv = 'testing-hparams.csv' + >>> path_csv = os.path.join('.', 'testing-hparams.csv') >>> save_hparams_to_tags_csv(path_csv, hparams) >>> hparams_new = load_hparams_from_tags_csv(path_csv) >>> vars(hparams) == hparams_new From c4064fdd6781840d1bc3f3748010ff5b15a6172c Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 10:45:19 +0200 Subject: [PATCH 21/45] distributed cpu --- benchmarks/test_parity.py | 2 +- tests/base/{utils.py => develop_utils.py} | 8 +++++++ tests/callbacks/test_callbacks.py | 20 +++++++++++------ tests/callbacks/test_lr.py | 14 +++++++----- tests/callbacks/test_progress_bar.py | 6 +++++ tests/loggers/test_all.py | 9 +++++--- tests/loggers/test_base.py | 8 +++++-- tests/loggers/test_neptune.py | 4 +++- tests/metrics/test_converters.py | 2 +- .../data/horovod/train_default_model.py | 2 +- tests/models/test_amp.py | 4 ++-- tests/models/test_cpu.py | 18 ++++++++++----- tests/models/test_gpu.py | 18 ++++++++------- tests/models/test_grad_norm.py | 4 +++- tests/models/test_hooks.py | 7 +++++- tests/models/test_horovod.py | 4 ++-- tests/models/test_restore.py | 6 +++-- tests/models/test_tpu.py | 2 +- tests/trainer/test_checks.py | 2 +- tests/trainer/test_dataloaders.py | 12 ++++++---- tests/trainer/test_lr_finder.py | 22 ++++++++++++++----- tests/trainer/test_optimizers.py | 22 ++++++++++++++----- tests/trainer/test_trainer.py | 2 +- tests/trainer/test_trainer_cli.py | 2 +- tests/trainer/test_trainer_steps.py | 13 +++++++++-- tests/trainer/test_trainer_tricks.py | 2 +- 26 files changed, 149 insertions(+), 66 deletions(-) rename tests/base/{utils.py => develop_utils.py} (97%) diff --git a/benchmarks/test_parity.py b/benchmarks/test_parity.py index f38cab56dcb17..9a8493dc2b822 100644 --- a/benchmarks/test_parity.py +++ b/benchmarks/test_parity.py @@ -4,7 +4,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer, seed_everything from tests.base.models import ParityModuleRNN, ParityModuleMNIST diff --git a/tests/base/utils.py b/tests/base/develop_utils.py similarity index 97% rename from tests/base/utils.py rename to tests/base/develop_utils.py index 6690b18b804df..6fe70faec058d 100644 --- a/tests/base/utils.py +++ b/tests/base/develop_utils.py @@ -1,4 +1,5 @@ import os +import platform import numpy as np import torch @@ -11,6 +12,13 @@ from tests.base.model_template import EvalModelTemplate +def default_trainer_options(): + opt = {} + if platform.system() == "Windows": + opt.update(distributed_backend='ddp_cpu') + return opt + + def assert_speed_parity_relative(pl_times, pt_times, max_diff: float = 0.1): # assert speeds diffs = np.asarray(pl_times) - np.asarray(pt_times) diff --git a/tests/callbacks/test_callbacks.py b/tests/callbacks/test_callbacks.py index 9405730dc9698..51fc36bcdc133 100644 --- a/tests/callbacks/test_callbacks.py +++ b/tests/callbacks/test_callbacks.py @@ -3,7 +3,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Callback from pytorch_lightning import Trainer, LightningModule from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint @@ -26,6 +26,7 @@ def validation_epoch_end(self, outputs): early_stop_callback=True, overfit_batches=0.20, max_epochs=20, + **tutils.default_trainer_options(), ) result = trainer.fit(model) print(trainer.current_epoch) @@ -165,6 +166,7 @@ def on_test_end(self, trainer, pl_module): limit_val_batches=0.1, limit_train_batches=0.2, progress_bar_refresh_rate=0, + **tutils.default_trainer_options(), ) assert not test_callback.setup_called @@ -282,6 +284,7 @@ def training_step(self, *args, **kwargs): early_stop_callback=stopping, overfit_batches=0.20, max_epochs=2, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -312,11 +315,13 @@ def test_model_checkpoint_with_non_string_input(tmpdir, save_top_k): checkpoint = ModelCheckpoint(filepath=None, save_top_k=save_top_k) - trainer = Trainer(default_root_dir=tmpdir, - checkpoint_callback=checkpoint, - overfit_batches=0.20, - max_epochs=2 - ) + trainer = Trainer( + default_root_dir=tmpdir, + checkpoint_callback=checkpoint, + overfit_batches=0.20, + max_epochs=2, + **tutils.default_trainer_options(), + ) trainer.fit(model) # These should be different if the dirpath has be overridden @@ -337,7 +342,8 @@ def test_model_checkpoint_path(tmpdir, logger_version, expected): default_root_dir=tmpdir, overfit_batches=0.2, max_epochs=2, - logger=logger + logger=logger, + **tutils.default_trainer_options(), ) trainer.fit(model) diff --git a/tests/callbacks/test_lr.py b/tests/callbacks/test_lr.py index 8302e67f05d34..e8cb7f29d7186 100644 --- a/tests/callbacks/test_lr.py +++ b/tests/callbacks/test_lr.py @@ -1,6 +1,6 @@ import pytest -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import LearningRateLogger from tests.base import EvalModelTemplate @@ -19,7 +19,8 @@ def test_lr_logger_single_lr(tmpdir): max_epochs=2, limit_val_batches=0.1, limit_train_batches=0.5, - callbacks=[lr_logger] + callbacks=[lr_logger], + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result @@ -42,7 +43,8 @@ def test_lr_logger_no_lr(tmpdir): max_epochs=2, limit_val_batches=0.1, limit_train_batches=0.5, - callbacks=[lr_logger] + callbacks=[lr_logger], + **tutils.default_trainer_options(), ) with pytest.warns(RuntimeWarning): @@ -63,7 +65,8 @@ def test_lr_logger_multi_lrs(tmpdir): max_epochs=2, limit_val_batches=0.1, limit_train_batches=0.5, - callbacks=[lr_logger] + callbacks=[lr_logger], + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result @@ -90,7 +93,8 @@ def test_lr_logger_param_groups(tmpdir): max_epochs=2, limit_val_batches=0.1, limit_train_batches=0.5, - callbacks=[lr_logger] + callbacks=[lr_logger], + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result diff --git a/tests/callbacks/test_progress_bar.py b/tests/callbacks/test_progress_bar.py index a63fc62585c45..6961dca437752 100644 --- a/tests/callbacks/test_progress_bar.py +++ b/tests/callbacks/test_progress_bar.py @@ -1,5 +1,6 @@ import pytest +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import ProgressBarBase, ProgressBar, ModelCheckpoint from pytorch_lightning.utilities.exceptions import MisconfigurationException @@ -21,6 +22,7 @@ def test_progress_bar_on(callbacks, refresh_rate): progress_bar_refresh_rate=refresh_rate, max_epochs=1, overfit_batches=5, + **tutils.default_trainer_options(), ) progress_bars = [c for c in trainer.callbacks if isinstance(c, ProgressBarBase)] @@ -40,6 +42,7 @@ def test_progress_bar_off(callbacks, refresh_rate): trainer = Trainer( callbacks=callbacks, progress_bar_refresh_rate=refresh_rate, + **tutils.default_trainer_options(), ) progress_bars = [c for c in trainer.callbacks if isinstance(c, ProgressBar)] @@ -63,6 +66,7 @@ def test_progress_bar_totals(): progress_bar_refresh_rate=1, limit_val_batches=1.0, max_epochs=1, + **tutils.default_trainer_options(), ) bar = trainer.progress_bar_callback assert 0 == bar.total_train_batches @@ -110,6 +114,7 @@ def test_progress_bar_fast_dev_run(): trainer = Trainer( fast_dev_run=True, + **tutils.default_trainer_options(), ) progress_bar = trainer.progress_bar_callback @@ -177,6 +182,7 @@ def on_test_batch_end(self, trainer, pl_module): limit_train_batches=1.0, num_sanity_val_steps=2, max_epochs=3, + **tutils.default_trainer_options(), ) assert trainer.progress_bar_callback.refresh_rate == refresh_rate diff --git a/tests/loggers/test_all.py b/tests/loggers/test_all.py index b41ec73226c18..a7b6a745266f8 100644 --- a/tests/loggers/test_all.py +++ b/tests/loggers/test_all.py @@ -3,7 +3,7 @@ import pytest -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.loggers import ( TensorBoardLogger, MLFlowLogger, NeptuneLogger, TestTubeLogger, CometLogger) @@ -55,6 +55,7 @@ def log_metrics(self, metrics, step): limit_train_batches=0.2, limit_val_batches=0.5, fast_dev_run=True, + **tutils.default_trainer_options(), ) trainer.fit(model) @@ -90,7 +91,8 @@ def test_loggers_pickle(tmpdir, monkeypatch, logger_class): trainer = Trainer( max_epochs=1, - logger=logger + logger=logger, + **tutils.default_trainer_options(), ) pkl_bytes = pickle.dumps(trainer) @@ -110,7 +112,8 @@ def test_logger_reset_correctly(tmpdir, extra_params): trainer = Trainer( default_root_dir=tmpdir, - **extra_params + **extra_params, + **tutils.default_trainer_options(), ) logger1 = trainer.logger trainer.fit(model) diff --git a/tests/loggers/test_base.py b/tests/loggers/test_base.py index 083a43af2c68f..1de26d46b7e63 100644 --- a/tests/loggers/test_base.py +++ b/tests/loggers/test_base.py @@ -6,6 +6,7 @@ from pytorch_lightning import Trainer from pytorch_lightning.loggers import LightningLoggerBase, LoggerCollection from pytorch_lightning.utilities import rank_zero_only +import tests.base.develop_utils as tutils from tests.base import EvalModelTemplate @@ -68,7 +69,8 @@ def test_custom_logger(tmpdir): max_epochs=1, limit_train_batches=0.05, logger=logger, - default_root_dir=tmpdir + default_root_dir=tmpdir, + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1, "Training failed" @@ -88,7 +90,8 @@ def test_multiple_loggers(tmpdir): max_epochs=1, limit_train_batches=0.05, logger=[logger1, logger2], - default_root_dir=tmpdir + default_root_dir=tmpdir, + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1, "Training failed" @@ -147,6 +150,7 @@ def decorated(metrics, step): limit_train_batches=0.1, limit_val_batches=0.1, num_sanity_val_steps=0, + **tutils.default_trainer_options(), ) trainer.logger.log_metrics = _log_metrics_decorator( trainer.logger.log_metrics) diff --git a/tests/loggers/test_neptune.py b/tests/loggers/test_neptune.py index 33a17b63819a7..136ce7be798d2 100644 --- a/tests/loggers/test_neptune.py +++ b/tests/loggers/test_neptune.py @@ -2,6 +2,7 @@ import torch +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.loggers import NeptuneLogger from tests.base import EvalModelTemplate @@ -83,7 +84,8 @@ def _run_training(logger): default_root_dir=tmpdir, max_epochs=1, limit_train_batches=0.05, - logger=logger + logger=logger, + **tutils.default_trainer_options(), ) trainer.fit(model) return logger diff --git a/tests/metrics/test_converters.py b/tests/metrics/test_converters.py index b6c102b1fd83b..ec2910e050194 100644 --- a/tests/metrics/test_converters.py +++ b/tests/metrics/test_converters.py @@ -4,7 +4,7 @@ import torch.distributed as dist import torch.multiprocessing as mp -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning.metrics.converters import ( _apply_to_inputs, _apply_to_outputs, diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index d1702d282064c..8da4566cc00ad 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -33,7 +33,7 @@ from pytorch_lightning import Trainer # noqa: E402 from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402 from tests.base import EvalModelTemplate # noqa: E402 -from tests.base.utils import set_random_master_port, run_model_test # noqa: E402 +from tests.base.develop_utils import set_random_master_port, run_model_test # noqa: E402 parser = argparse.ArgumentParser() diff --git a/tests/models/test_amp.py b/tests/models/test_amp.py index 63cdeac45fc43..8561c182dbfbb 100644 --- a/tests/models/test_amp.py +++ b/tests/models/test_amp.py @@ -3,7 +3,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate @@ -45,7 +45,7 @@ def test_amp_multi_gpu(tmpdir, backend): # gpus=2, gpus='0, 1', # test init with gpu string distributed_backend=backend, - precision=16 + precision=16, ) # tutils.run_model_test(trainer_options, model) diff --git a/tests/models/test_cpu.py b/tests/models/test_cpu.py index 31eea37f4350a..baa5de7ee984e 100644 --- a/tests/models/test_cpu.py +++ b/tests/models/test_cpu.py @@ -5,7 +5,7 @@ import torch from packaging.version import parse as version_parse -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import EarlyStopping from pytorch_lightning.callbacks import ModelCheckpoint @@ -27,7 +27,8 @@ def test_cpu_slurm_save_load(tmpdir): logger=logger, limit_train_batches=0.2, limit_val_batches=0.2, - checkpoint_callback=ModelCheckpoint(tmpdir) + checkpoint_callback=ModelCheckpoint(tmpdir), + **tutils.default_trainer_options(), ) result = trainer.fit(model) real_global_step = trainer.global_step @@ -63,6 +64,7 @@ def test_cpu_slurm_save_load(tmpdir): max_epochs=1, logger=logger, checkpoint_callback=ModelCheckpoint(tmpdir), + **tutils.default_trainer_options(), ) model = EvalModelTemplate(**hparams) @@ -122,7 +124,7 @@ def test_multi_cpu_model_ddp(tmpdir): limit_val_batches=0.2, gpus=None, num_processes=2, - distributed_backend='ddp_cpu' + distributed_backend='ddp_cpu', ) model = EvalModelTemplate() @@ -187,7 +189,8 @@ def test_running_test_after_fitting(tmpdir): limit_val_batches=0.2, limit_test_batches=0.2, checkpoint_callback=checkpoint, - logger=logger + logger=logger, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -218,7 +221,8 @@ def test_running_test_no_val(tmpdir): limit_test_batches=0.2, checkpoint_callback=checkpoint, logger=logger, - early_stop_callback=False + early_stop_callback=False, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -240,6 +244,7 @@ def test_simple_cpu(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=20, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -344,7 +349,8 @@ def train_dataloader(self): truncated_bptt_steps=truncated_bptt_steps, limit_val_batches=0, weights_summary=None, - early_stop_callback=False + early_stop_callback=False, + **tutils.default_trainer_options(), ) result = trainer.fit(model) diff --git a/tests/models/test_gpu.py b/tests/models/test_gpu.py index 3db39e0b03156..4acd4b7dba0f8 100644 --- a/tests/models/test_gpu.py +++ b/tests/models/test_gpu.py @@ -3,7 +3,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.core import memory from pytorch_lightning.trainer.distrib_parts import _parse_gpu_ids, determine_root_gpu_device @@ -62,13 +62,15 @@ def test_ddp_all_dataloaders_passed_to_fit(tmpdir): """Make sure DDP works with dataloaders passed to fit()""" tutils.set_random_master_port() - trainer_options = dict(default_root_dir=tmpdir, - progress_bar_refresh_rate=0, - max_epochs=1, - limit_train_batches=0.1, - limit_val_batches=0.1, - gpus=[0, 1], - distributed_backend='ddp') + trainer_options = dict( + default_root_dir=tmpdir, + progress_bar_refresh_rate=0, + max_epochs=1, + limit_train_batches=0.1, + limit_val_batches=0.1, + gpus=[0, 1], + distributed_backend='ddp' + ) model = EvalModelTemplate() fit_options = dict(train_dataloader=model.train_dataloader(), diff --git a/tests/models/test_grad_norm.py b/tests/models/test_grad_norm.py index 7a6659ecfa1d5..3d60a232ffa10 100644 --- a/tests/models/test_grad_norm.py +++ b/tests/models/test_grad_norm.py @@ -1,11 +1,12 @@ import numpy as np import pytest +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.loggers import LightningLoggerBase from pytorch_lightning.utilities import rank_zero_only from tests.base import EvalModelTemplate -from tests.base.utils import reset_seed +from tests.base.develop_utils import reset_seed class OnlyMetricsListLogger(LightningLoggerBase): @@ -88,6 +89,7 @@ def test_grad_tracking(tmpdir, norm_type, rtol=5e-3): logger=logger, track_grad_norm=norm_type, row_log_interval=1, # request grad_norms every batch + **tutils.default_trainer_options(), ) result = trainer.fit(model) diff --git a/tests/models/test_hooks.py b/tests/models/test_hooks.py index 78efbd35ff4da..8b2df43ae0e5e 100644 --- a/tests/models/test_hooks.py +++ b/tests/models/test_hooks.py @@ -3,6 +3,7 @@ import pytest import torch +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate @@ -21,6 +22,7 @@ def on_before_zero_grad(self, optimizer): trainer = Trainer( max_steps=max_steps, num_sanity_val_steps=5, + **tutils.default_trainer_options(), ) assert 0 == model.on_before_zero_grad_called trainer.fit(model) @@ -58,6 +60,7 @@ def training_epoch_end(self, outputs): max_epochs=num_epochs, default_root_dir=tmpdir, overfit_batches=2, + **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1 @@ -97,7 +100,9 @@ def transfer_batch_to_device(self, data, device): model = CurrentTestModel() batch = CustomBatch((torch.zeros(5, 28), torch.ones(5, 1, dtype=torch.long))) - trainer = Trainer() + trainer = Trainer( + **tutils.default_trainer_options(), + ) # running .fit() would require us to implement custom data loaders, we mock the model reference instead trainer.get_model = MagicMock(return_value=model) batch_gpu = trainer.transfer_batch_to_gpu(batch, 0) diff --git a/tests/models/test_horovod.py b/tests/models/test_horovod.py index 82cabceac2631..9c107aab39d75 100644 --- a/tests/models/test_horovod.py +++ b/tests/models/test_horovod.py @@ -8,7 +8,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate from tests.base.models import TestGAN @@ -152,7 +152,7 @@ def test_horovod_multi_optimizer(tmpdir): limit_train_batches=0.4, limit_val_batches=0.2, deterministic=True, - distributed_backend='horovod' + distributed_backend='horovod', ) # fit model diff --git a/tests/models/test_restore.py b/tests/models/test_restore.py index b907bc3c7114a..a6079e044e4f1 100644 --- a/tests/models/test_restore.py +++ b/tests/models/test_restore.py @@ -7,7 +7,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import ModelCheckpoint from tests.base import EvalModelTemplate @@ -82,7 +82,8 @@ def test_running_test_pretrained_model_cpu(tmpdir): limit_train_batches=0.4, limit_val_batches=0.2, checkpoint_callback=checkpoint, - logger=logger + logger=logger, + **tutils.default_trainer_options(), ) # fit model @@ -114,6 +115,7 @@ def test_load_model_from_checkpoint(tmpdir): limit_val_batches=0.2, checkpoint_callback=ModelCheckpoint(tmpdir, save_top_k=-1), default_root_dir=tmpdir, + **tutils.default_trainer_options(), ) # fit model diff --git a/tests/models/test_tpu.py b/tests/models/test_tpu.py index 15d220be7cbd6..141ee90b962f4 100644 --- a/tests/models/test_tpu.py +++ b/tests/models/test_tpu.py @@ -32,7 +32,7 @@ def test_single_tpu_core_model(tmpdir, tpu_cores, expected_device): max_epochs=1, train_percent_check=0.1, val_percent_check=0.1, - tpu_cores=tpu_cores + tpu_cores=tpu_cores, ) trainer.fit(model) assert torch_xla._XLAC._xla_get_default_device() == expected_device diff --git a/tests/trainer/test_checks.py b/tests/trainer/test_checks.py index c3106abc2a94f..7b112ec60a53b 100755 --- a/tests/trainer/test_checks.py +++ b/tests/trainer/test_checks.py @@ -1,6 +1,6 @@ import pytest -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer, LightningModule from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_dataloaders.py b/tests/trainer/test_dataloaders.py index b59abdd4a13ef..769c5abb1e395 100644 --- a/tests/trainer/test_dataloaders.py +++ b/tests/trainer/test_dataloaders.py @@ -5,7 +5,7 @@ from torch.utils.data.dataloader import DataLoader from torch.utils.data.dataset import Subset -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate @@ -97,6 +97,7 @@ def test_multiple_val_dataloader(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=1.0, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -132,7 +133,8 @@ def test_step(self, batch, batch_idx, *args, **kwargs): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) trainer.fit(model) if ckpt_path == 'specific': @@ -160,7 +162,8 @@ def test_train_dataloader_passed_to_fit(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) fit_options = dict(train_dataloader=model.dataloader(train=True)) result = trainer.fit(model, **fit_options) @@ -177,7 +180,8 @@ def test_train_val_dataloaders_passed_to_fit(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) fit_options = dict(train_dataloader=model.dataloader(train=True), val_dataloaders=model.dataloader(train=False)) diff --git a/tests/trainer/test_lr_finder.py b/tests/trainer/test_lr_finder.py index f6604730125c6..53e59acd25c0e 100755 --- a/tests/trainer/test_lr_finder.py +++ b/tests/trainer/test_lr_finder.py @@ -1,6 +1,7 @@ import pytest import torch +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate @@ -15,7 +16,8 @@ def test_error_on_more_than_1_optimizer(tmpdir): # logger file to get meta trainer = Trainer( default_root_dir=tmpdir, - max_epochs=1 + max_epochs=1, + **tutils.default_trainer_options(), ) with pytest.raises(MisconfigurationException): @@ -30,7 +32,8 @@ def test_model_reset_correctly(tmpdir): # logger file to get meta trainer = Trainer( default_root_dir=tmpdir, - max_epochs=1 + max_epochs=1, + **tutils.default_trainer_options(), ) before_state_dict = model.state_dict() @@ -52,7 +55,8 @@ def test_trainer_reset_correctly(tmpdir): # logger file to get meta trainer = Trainer( default_root_dir=tmpdir, - max_epochs=1 + max_epochs=1, + **tutils.default_trainer_options(), ) changed_attributes = ['callbacks', 'logger', 'max_steps', 'auto_lr_find', @@ -83,7 +87,8 @@ def test_trainer_arg_bool(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=2, - auto_lr_find=True + auto_lr_find=True, + **tutils.default_trainer_options(), ) trainer.fit(model) @@ -102,7 +107,8 @@ def test_trainer_arg_str(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=2, - auto_lr_find='my_fancy_lr' + auto_lr_find='my_fancy_lr', + **tutils.default_trainer_options(), ) trainer.fit(model) @@ -122,6 +128,7 @@ def test_call_to_trainer_method(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=2, + **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model, mode='linear') @@ -145,6 +152,7 @@ def test_accumulation_and_early_stopping(tmpdir): trainer = Trainer( default_root_dir=tmpdir, accumulate_grad_batches=2, + **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model, early_stop_threshold=None) @@ -168,6 +176,7 @@ def test_suggestion_parameters_work(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=3, + **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model) @@ -187,7 +196,8 @@ def test_suggestion_with_non_finite_values(tmpdir): # logger file to get meta trainer = Trainer( default_root_dir=tmpdir, - max_epochs=3 + max_epochs=3, + **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model) diff --git a/tests/trainer/test_optimizers.py b/tests/trainer/test_optimizers.py index 222805b2e432d..4c29b6971c400 100644 --- a/tests/trainer/test_optimizers.py +++ b/tests/trainer/test_optimizers.py @@ -1,6 +1,7 @@ import pytest import torch +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate @@ -17,7 +18,8 @@ def test_optimizer_with_scheduling(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -48,7 +50,8 @@ def test_multi_optimizer_with_scheduling(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -83,7 +86,8 @@ def test_multi_optimizer_with_scheduling_stepping(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -122,7 +126,8 @@ def test_reduce_lr_on_plateau_scheduling(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -212,7 +217,8 @@ def test_none_optimizer(tmpdir): default_root_dir=tmpdir, max_epochs=1, limit_val_batches=0.1, - limit_train_batches=0.2 + limit_train_batches=0.2, + **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -234,6 +240,10 @@ def configure_optimizers(self): model = CurrentModel(hparams) # fit model - trainer = Trainer(default_root_dir=tmpdir, max_epochs=1) + trainer = Trainer( + default_root_dir=tmpdir, + max_epochs=1, + **tutils.default_trainer_options(), + ) result = trainer.fit(model) assert result == 1 diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index 84b0525c8b2e7..b5a6d75c4a6ad 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -12,7 +12,7 @@ import torch from omegaconf import OmegaConf -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Callback, LightningModule, Trainer from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint from pytorch_lightning.core.saving import ( diff --git a/tests/trainer/test_trainer_cli.py b/tests/trainer/test_trainer_cli.py index a3981366293ea..c6f2406f1c9a6 100644 --- a/tests/trainer/test_trainer_cli.py +++ b/tests/trainer/test_trainer_cli.py @@ -7,7 +7,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer diff --git a/tests/trainer/test_trainer_steps.py b/tests/trainer/test_trainer_steps.py index 88ff4f8c7a16e..39753d8c47fdc 100644 --- a/tests/trainer/test_trainer_steps.py +++ b/tests/trainer/test_trainer_steps.py @@ -1,3 +1,4 @@ +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base.deterministic_model import DeterministicModel @@ -73,7 +74,11 @@ def test_full_training_loop_dict(tmpdir): model.training_epoch_end = model.training_epoch_end_dict model.val_dataloader = None - trainer = Trainer(max_epochs=1, weights_summary=None) + trainer = Trainer( + max_epochs=1, + weights_summary=None, + **tutils.default_trainer_options(), + ) trainer.fit(model) # make sure correct steps were called @@ -109,7 +114,11 @@ def test_train_step_epoch_end(tmpdir): model.training_epoch_end = model.training_epoch_end_dict model.val_dataloader = None - trainer = Trainer(max_epochs=1, weights_summary=None) + trainer = Trainer( + max_epochs=1, + weights_summary=None, + **tutils.default_trainer_options(), + ) trainer.fit(model) # make sure correct steps were called diff --git a/tests/trainer/test_trainer_tricks.py b/tests/trainer/test_trainer_tricks.py index 25653973fdcbe..b7abe9af1c6e3 100755 --- a/tests/trainer/test_trainer_tricks.py +++ b/tests/trainer/test_trainer_tricks.py @@ -1,7 +1,7 @@ import pytest import torch -import tests.base.utils as tutils +import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate From 2c808ddf4fd6fd44323f682bf218bbd7913a7924 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 10:59:31 +0200 Subject: [PATCH 22/45] pipes --- tests/base/develop_pipelines.py | 104 ++++++++++++++++ tests/base/develop_utils.py | 115 +----------------- .../data/horovod/train_default_model.py | 4 +- tests/models/test_cpu.py | 13 +- tests/models/test_gpu.py | 5 +- tests/models/test_horovod.py | 3 +- tests/models/test_restore.py | 13 +- tests/trainer/test_dataloaders.py | 5 +- 8 files changed, 131 insertions(+), 131 deletions(-) create mode 100644 tests/base/develop_pipelines.py diff --git a/tests/base/develop_pipelines.py b/tests/base/develop_pipelines.py new file mode 100644 index 0000000000000..9ba3dd8d978c0 --- /dev/null +++ b/tests/base/develop_pipelines.py @@ -0,0 +1,104 @@ +import torch + +# from pl_examples import LightningTemplateModel +from pytorch_lightning import Trainer +from tests.base.develop_utils import load_model_from_checkpoint, init_checkpoint_callback, get_default_logger, \ + reset_seed + + +def run_model_test_without_loggers(trainer_options, model, min_acc: float = 0.50): + reset_seed() + + # fit model + trainer = Trainer(**trainer_options) + result = trainer.fit(model) + + # correct result and ok accuracy + assert result == 1, 'amp + ddp model failed to complete' + + # test model loading + pretrained_model = load_model_from_checkpoint( + trainer.logger, + trainer.checkpoint_callback.dirpath, + path_expt=trainer_options.get('default_root_dir'), + ) + + # test new model accuracy + test_loaders = model.test_dataloader() + if not isinstance(test_loaders, list): + test_loaders = [test_loaders] + + for dataloader in test_loaders: + run_prediction(dataloader, pretrained_model, min_acc=min_acc) + + if trainer.use_ddp: + # on hpc this would work fine... but need to hack it for the purpose of the test + trainer.model = pretrained_model + trainer.optimizers, trainer.lr_schedulers = pretrained_model.configure_optimizers() + + +def run_model_test(trainer_options, model, on_gpu: bool = True, version=None, with_hpc: bool = True): + reset_seed() + save_dir = trainer_options['default_root_dir'] + + # logger file to get meta + logger = get_default_logger(save_dir, version=version) + trainer_options.update(logger=logger) + + if 'checkpoint_callback' not in trainer_options: + # logger file to get weights + checkpoint = init_checkpoint_callback(logger) + trainer_options.update(checkpoint_callback=checkpoint) + + # fit model + trainer = Trainer(**trainer_options) + result = trainer.fit(model) + + # correct result and ok accuracy + assert result == 1, 'amp + ddp model failed to complete' + + # test model loading + pretrained_model = load_model_from_checkpoint(logger, trainer.checkpoint_callback.dirpath) + + # test new model accuracy + test_loaders = model.test_dataloader() + if not isinstance(test_loaders, list): + test_loaders = [test_loaders] + + [run_prediction(dataloader, pretrained_model) for dataloader in test_loaders] + + if with_hpc: + if trainer.use_ddp or trainer.use_ddp2: + # on hpc this would work fine... but need to hack it for the purpose of the test + trainer.model = pretrained_model + trainer.optimizers, trainer.lr_schedulers, trainer.optimizer_frequencies = \ + trainer.init_optimizers(pretrained_model) + + # test HPC loading / saving + trainer.hpc_save(save_dir, logger) + trainer.hpc_load(save_dir, on_gpu=on_gpu) + + +def run_prediction(dataloader, trained_model, dp=False, min_acc=0.50): + # run prediction on 1 batch + for batch in dataloader: + break + + x, y = batch + x = x.view(x.size(0), -1) + + if dp: + output = trained_model(batch, 0) + acc = output['val_acc'] + acc = torch.mean(acc).item() + + else: + y_hat = trained_model(x) + + # acc + labels_hat = torch.argmax(y_hat, dim=1) + acc = torch.sum(y == labels_hat).item() / (len(y) * 1.0) + acc = torch.tensor(acc) + acc = acc.item() + + assert acc >= min_acc, f"This model is expected to get > {min_acc} in test set (it got {acc})" diff --git a/tests/base/develop_utils.py b/tests/base/develop_utils.py index 6fe70faec058d..11dc175928436 100644 --- a/tests/base/develop_utils.py +++ b/tests/base/develop_utils.py @@ -2,10 +2,9 @@ import platform import numpy as np -import torch # from pl_examples import LightningTemplateModel -from pytorch_lightning import Trainer, seed_everything +from pytorch_lightning import seed_everything from pytorch_lightning.callbacks import ModelCheckpoint from pytorch_lightning.loggers import TensorBoardLogger from tests import TEMP_PATH, RANDOM_PORTS, RANDOM_SEEDS @@ -37,77 +36,6 @@ def assert_speed_parity_absolute(pl_times, pt_times, nb_epochs, max_diff: float f"lightning {diffs} was slower than PT (threshold {max_diff})" -def run_model_test_without_loggers(trainer_options, model, min_acc: float = 0.50): - reset_seed() - - # fit model - trainer = Trainer(**trainer_options) - result = trainer.fit(model) - - # correct result and ok accuracy - assert result == 1, 'amp + ddp model failed to complete' - - # test model loading - pretrained_model = load_model(trainer.logger, - trainer.checkpoint_callback.dirpath, - path_expt=trainer_options.get('default_root_dir')) - - # test new model accuracy - test_loaders = model.test_dataloader() - if not isinstance(test_loaders, list): - test_loaders = [test_loaders] - - for dataloader in test_loaders: - run_prediction(dataloader, pretrained_model, min_acc=min_acc) - - if trainer.use_ddp: - # on hpc this would work fine... but need to hack it for the purpose of the test - trainer.model = pretrained_model - trainer.optimizers, trainer.lr_schedulers = pretrained_model.configure_optimizers() - - -def run_model_test(trainer_options, model, on_gpu: bool = True, version=None, with_hpc: bool = True): - reset_seed() - save_dir = trainer_options['default_root_dir'] - - # logger file to get meta - logger = get_default_logger(save_dir, version=version) - trainer_options.update(logger=logger) - - if 'checkpoint_callback' not in trainer_options: - # logger file to get weights - checkpoint = init_checkpoint_callback(logger) - trainer_options.update(checkpoint_callback=checkpoint) - - # fit model - trainer = Trainer(**trainer_options) - result = trainer.fit(model) - - # correct result and ok accuracy - assert result == 1, 'amp + ddp model failed to complete' - - # test model loading - pretrained_model = load_model(logger, trainer.checkpoint_callback.dirpath) - - # test new model accuracy - test_loaders = model.test_dataloader() - if not isinstance(test_loaders, list): - test_loaders = [test_loaders] - - [run_prediction(dataloader, pretrained_model) for dataloader in test_loaders] - - if with_hpc: - if trainer.use_ddp or trainer.use_ddp2: - # on hpc this would work fine... but need to hack it for the purpose of the test - trainer.model = pretrained_model - trainer.optimizers, trainer.lr_schedulers, trainer.optimizer_frequencies = \ - trainer.init_optimizers(pretrained_model) - - # test HPC loading / saving - trainer.hpc_save(save_dir, logger) - trainer.hpc_load(save_dir, on_gpu=on_gpu) - - def get_default_logger(save_dir, version=None): # set up logger object without actually saving logs logger = TensorBoardLogger(save_dir, name='lightning_logs', version=version) @@ -135,7 +63,7 @@ def get_data_path(expt_logger, path_dir=None): return path_expt -def load_model(logger, root_weights_dir, module_class=EvalModelTemplate, path_expt=None): +def load_model_from_checkpoint(logger, root_weights_dir, module_class=EvalModelTemplate, path_expt=None): # load trained model path_expt_dir = get_data_path(logger, path_dir=path_expt) hparams_path = os.path.join(path_expt_dir, TensorBoardLogger.NAME_HPARAMS_FILE) @@ -153,45 +81,6 @@ def load_model(logger, root_weights_dir, module_class=EvalModelTemplate, path_ex return trained_model -def load_model_from_checkpoint(root_weights_dir, module_class=EvalModelTemplate): - # load trained model - checkpoints = [x for x in os.listdir(root_weights_dir) if '.ckpt' in x] - weights_dir = os.path.join(root_weights_dir, checkpoints[0]) - - trained_model = module_class.load_from_checkpoint( - checkpoint_path=weights_dir, - ) - - assert trained_model is not None, 'loading model failed' - - return trained_model - - -def run_prediction(dataloader, trained_model, dp=False, min_acc=0.50): - # run prediction on 1 batch - for batch in dataloader: - break - - x, y = batch - x = x.view(x.size(0), -1) - - if dp: - output = trained_model(batch, 0) - acc = output['val_acc'] - acc = torch.mean(acc).item() - - else: - y_hat = trained_model(x) - - # acc - labels_hat = torch.argmax(y_hat, dim=1) - acc = torch.sum(y == labels_hat).item() / (len(y) * 1.0) - acc = torch.tensor(acc) - acc = acc.item() - - assert acc >= min_acc, f"This model is expected to get > {min_acc} in test set (it got {acc})" - - def assert_ok_model_acc(trainer, key='test_acc', thr=0.5): # this model should get 0.80+ acc acc = trainer.progress_bar_dict[key] diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index 8da4566cc00ad..f32df08ca83b2 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -21,6 +21,7 @@ import os import sys + try: import horovod.torch as hvd except (ModuleNotFoundError, ImportError): @@ -33,7 +34,8 @@ from pytorch_lightning import Trainer # noqa: E402 from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402 from tests.base import EvalModelTemplate # noqa: E402 -from tests.base.develop_utils import set_random_master_port, run_model_test # noqa: E402 +from tests.base.develop_pipelines import run_model_test # noqa: E402 +from tests.base.develop_utils import set_random_master_port # noqa: E402 parser = argparse.ArgumentParser() diff --git a/tests/models/test_cpu.py b/tests/models/test_cpu.py index baa5de7ee984e..2a3dabff02573 100644 --- a/tests/models/test_cpu.py +++ b/tests/models/test_cpu.py @@ -5,6 +5,7 @@ import torch from packaging.version import parse as version_parse +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import EarlyStopping @@ -99,7 +100,7 @@ def test_early_stopping_cpu_model(tmpdir): ) model = EvalModelTemplate() - tutils.run_model_test(trainer_options, model, on_gpu=False) + tpipes.run_model_test(trainer_options, model, on_gpu=False) # test freeze on cpu model.freeze() @@ -128,7 +129,7 @@ def test_multi_cpu_model_ddp(tmpdir): ) model = EvalModelTemplate() - tutils.run_model_test(trainer_options, model, on_gpu=False) + tpipes.run_model_test(trainer_options, model, on_gpu=False) def test_lbfgs_cpu_model(tmpdir): @@ -147,7 +148,7 @@ def test_lbfgs_cpu_model(tmpdir): learning_rate=0.004) model = EvalModelTemplate(**hparams) model.configure_optimizers = model.configure_optimizers__lbfgs - tutils.run_model_test_without_loggers(trainer_options, model, min_acc=0.25) + tpipes.run_model_test_without_loggers(trainer_options, model, min_acc=0.25) def test_default_logger_callbacks_cpu_model(tmpdir): @@ -163,7 +164,7 @@ def test_default_logger_callbacks_cpu_model(tmpdir): ) model = EvalModelTemplate() - tutils.run_model_test_without_loggers(trainer_options, model) + tpipes.run_model_test_without_loggers(trainer_options, model) # test freeze on cpu model.freeze() @@ -264,7 +265,7 @@ def test_cpu_model(tmpdir): model = EvalModelTemplate() - tutils.run_model_test(trainer_options, model, on_gpu=False) + tpipes.run_model_test(trainer_options, model, on_gpu=False) def test_all_features_cpu_model(tmpdir): @@ -282,7 +283,7 @@ def test_all_features_cpu_model(tmpdir): ) model = EvalModelTemplate() - tutils.run_model_test(trainer_options, model, on_gpu=False) + tpipes.run_model_test(trainer_options, model, on_gpu=False) def test_tbptt_cpu_model(tmpdir): diff --git a/tests/models/test_gpu.py b/tests/models/test_gpu.py index 4acd4b7dba0f8..382866b625897 100644 --- a/tests/models/test_gpu.py +++ b/tests/models/test_gpu.py @@ -3,6 +3,7 @@ import pytest import torch +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.core import memory @@ -27,7 +28,7 @@ def test_single_gpu_model(tmpdir, gpus): ) model = EvalModelTemplate() - tutils.run_model_test(trainer_options, model) + tpipes.run_model_test(trainer_options, model) @pytest.mark.spawn @@ -96,7 +97,7 @@ def test_multi_gpu_none_backend(tmpdir): model = EvalModelTemplate() with pytest.warns(UserWarning): - tutils.run_model_test(trainer_options, model) + tpipes.run_model_test(trainer_options, model) @pytest.fixture diff --git a/tests/models/test_horovod.py b/tests/models/test_horovod.py index 9c107aab39d75..5f659ade57a38 100644 --- a/tests/models/test_horovod.py +++ b/tests/models/test_horovod.py @@ -8,6 +8,7 @@ import pytest import torch +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate @@ -137,7 +138,7 @@ def validation_step(self, batch, *args, **kwargs): deterministic=True, distributed_backend='horovod' ) - tutils.run_model_test_without_loggers(trainer_options, model) + tpipes.run_model_test_without_loggers(trainer_options, model) @pytest.mark.skipif(sys.version_info >= (3, 8), reason="Horovod not yet supported in Python 3.8") diff --git a/tests/models/test_restore.py b/tests/models/test_restore.py index a6079e044e4f1..b87ce28cc454e 100644 --- a/tests/models/test_restore.py +++ b/tests/models/test_restore.py @@ -7,6 +7,7 @@ import pytest import torch +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import ModelCheckpoint @@ -47,9 +48,9 @@ def test_running_test_pretrained_model_distrib(tmpdir, backend): # correct result and ok accuracy assert result == 1, 'training failed to complete' - pretrained_model = tutils.load_model(logger, - trainer.checkpoint_callback.dirpath, - module_class=EvalModelTemplate) + pretrained_model = tutils.load_model_from_checkpoint(logger, + trainer.checkpoint_callback.dirpath, + module_class=EvalModelTemplate) # run test set new_trainer = Trainer(**trainer_options) @@ -63,7 +64,7 @@ def test_running_test_pretrained_model_distrib(tmpdir, backend): dataloaders = [dataloaders] for dataloader in dataloaders: - tutils.run_prediction(dataloader, pretrained_model) + tpipes.run_prediction(dataloader, pretrained_model) def test_running_test_pretrained_model_cpu(tmpdir): @@ -92,7 +93,7 @@ def test_running_test_pretrained_model_cpu(tmpdir): # correct result and ok accuracy assert result == 1, 'training failed to complete' - pretrained_model = tutils.load_model( + pretrained_model = tutils.load_model_from_checkpoint( logger, trainer.checkpoint_callback.dirpath, module_class=EvalModelTemplate ) @@ -204,7 +205,7 @@ def assert_good_acc(): dp_model.eval() dataloader = trainer.train_dataloader - tutils.run_prediction(dataloader, dp_model, dp=True) + tpipes.run_prediction(dataloader, dp_model, dp=True) # new model model = EvalModelTemplate(**hparams) diff --git a/tests/trainer/test_dataloaders.py b/tests/trainer/test_dataloaders.py index 769c5abb1e395..0682dd1b33ae1 100644 --- a/tests/trainer/test_dataloaders.py +++ b/tests/trainer/test_dataloaders.py @@ -5,6 +5,7 @@ from torch.utils.data.dataloader import DataLoader from torch.utils.data.dataset import Subset +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException @@ -110,7 +111,7 @@ def test_multiple_val_dataloader(tmpdir): # make sure predictions are good for each val set for dataloader in trainer.val_dataloaders: - tutils.run_prediction(dataloader, trainer.model) + tpipes.run_prediction(dataloader, trainer.model) @pytest.mark.parametrize('ckpt_path', [None, 'best', 'specific']) @@ -147,7 +148,7 @@ def test_step(self, batch, batch_idx, *args, **kwargs): # make sure predictions are good for each test set for dataloader in trainer.test_dataloaders: - tutils.run_prediction(dataloader, trainer.model) + tpipes.run_prediction(dataloader, trainer.model) # run the test method trainer.test(ckpt_path=ckpt_path) From b438d5bc219b3f3cdba66b3aba94a802dbda3507 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 11:03:29 +0200 Subject: [PATCH 23/45] time --- .github/workflows/ci-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index db390d4dbd61b..5769425bc851f 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: os: macOS-10.15 # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 50 + timeout-minutes: 30 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 66a729963378fa40595ecd197fb98db35145601a Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 11:42:41 +0200 Subject: [PATCH 24/45] cpu --- pl_examples/basic_examples/gpu_template.py | 3 ++- pytorch_lightning/trainer/trainer.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pl_examples/basic_examples/gpu_template.py b/pl_examples/basic_examples/gpu_template.py index 94818ce7f0b06..2edf89f935f3e 100644 --- a/pl_examples/basic_examples/gpu_template.py +++ b/pl_examples/basic_examples/gpu_template.py @@ -61,7 +61,8 @@ def main(hparams): '--distributed_backend', type=str, default='dp', - help='supports four options dp, ddp, ddp2, ddp_spawn' + help='supports four options dp, ddp, ddp2, ddp_spawn, ...', + choices=['dp', 'ddp', 'ddp2', 'ddp_spawn', 'ddp_cpu'], ) parent_parser.add_argument( '--use_16bit', diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index 3243d088bbb54..e2a7736bac0c4 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -255,7 +255,7 @@ def __init__( Use `row_log_interval` instead. Will remove 0.9.0. - distributed_backend: The distributed backend to use (dp, ddp, ddp2, ddp_spawn) + distributed_backend: The distributed backend to use (dp, ddp, ddp2, ddp_spawn, ddp_cpu) use_amp: .. warning:: .. deprecated:: 0.7.0 @@ -885,7 +885,7 @@ def fit( task = int(os.environ['LOCAL_RANK']) self.ddp_train(task, model) - elif self.distributed_backend == 'cpu_ddp': + elif self.distributed_backend == 'ddp_cpu': self.set_random_port() self.model = model mp.spawn(self.ddp_train, nprocs=self.num_processes, args=(model,)) From 40a677b11967495dcb89aa9699a6e052871d48d6 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 12:13:29 +0200 Subject: [PATCH 25/45] spawn --- tests/base/develop_utils.py | 2 +- tests/models/test_amp.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/base/develop_utils.py b/tests/base/develop_utils.py index 11dc175928436..817d40ed88666 100644 --- a/tests/base/develop_utils.py +++ b/tests/base/develop_utils.py @@ -14,7 +14,7 @@ def default_trainer_options(): opt = {} if platform.system() == "Windows": - opt.update(distributed_backend='ddp_cpu') + opt.update(distributed_backend='ddp_spawn') return opt diff --git a/tests/models/test_amp.py b/tests/models/test_amp.py index 8561c182dbfbb..d8299b89df322 100644 --- a/tests/models/test_amp.py +++ b/tests/models/test_amp.py @@ -3,6 +3,7 @@ import pytest import torch +import tests.base.develop_pipelines as tpipes import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException @@ -133,4 +134,4 @@ def test_cpu_model_with_amp(tmpdir): model = EvalModelTemplate() with pytest.raises((MisconfigurationException, ModuleNotFoundError)): - tutils.run_model_test(trainer_options, model, on_gpu=False) + tpipes.run_model_test(trainer_options, model, on_gpu=False) From d64b19a44ae18b16da9d627701f6f7ed90aff8c5 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 12:36:18 +0200 Subject: [PATCH 26/45] spawn --- .github/workflows/ci-testing.yml | 2 +- .github/workflows/code-formatting.yml | 4 ++-- tests/base/develop_utils.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 5769425bc851f..db390d4dbd61b 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -33,7 +33,7 @@ jobs: os: macOS-10.15 # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 30 + timeout-minutes: 50 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 25c8d3fc33e5e..6e51b2a9bb406 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Set up Python + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: python-version: 3.8 @@ -69,4 +69,4 @@ jobs: - name: Run type checking run: | - $(npm bin)/pyright --project .pyrightconfig.json + npm/pyright --project .pyrightconfig.json diff --git a/tests/base/develop_utils.py b/tests/base/develop_utils.py index 817d40ed88666..11dc175928436 100644 --- a/tests/base/develop_utils.py +++ b/tests/base/develop_utils.py @@ -14,7 +14,7 @@ def default_trainer_options(): opt = {} if platform.system() == "Windows": - opt.update(distributed_backend='ddp_spawn') + opt.update(distributed_backend='ddp_cpu') return opt From a3ddc47353a8b198d24f12987315338ac23c3df9 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:02:20 +0200 Subject: [PATCH 27/45] spawn --- .github/workflows/code-formatting.yml | 2 +- tests/base/develop_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 6e51b2a9bb406..9faa95571f946 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -69,4 +69,4 @@ jobs: - name: Run type checking run: | - npm/pyright --project .pyrightconfig.json + $(npm bin)/pyright --project .pyrightconfig.json diff --git a/tests/base/develop_utils.py b/tests/base/develop_utils.py index 11dc175928436..d9ad24ef5535c 100644 --- a/tests/base/develop_utils.py +++ b/tests/base/develop_utils.py @@ -14,7 +14,7 @@ def default_trainer_options(): opt = {} if platform.system() == "Windows": - opt.update(distributed_backend='ddp_cpu') + opt.update(distributed_backend='dp') return opt From 06a6c59fc1dcccc62db7ed132f6429b458883502 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:15:09 +0200 Subject: [PATCH 28/45] tp --- .pyrightconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.pyrightconfig.json b/.pyrightconfig.json index bb65bfb38141e..74d4c46cfd018 100644 --- a/.pyrightconfig.json +++ b/.pyrightconfig.json @@ -17,6 +17,7 @@ "pytorch_lightning/utilities", "pytorch_lightning/trainer/data_loading.py", "pytorch_lightning/trainer/deprecated_api.py", + "pytorch_lightning/trainer/distrib_data_parallel.py", "pytorch_lightning/trainer/distrib_parts.py", "pytorch_lightning/trainer/evaluation_loop.py", "pytorch_lightning/trainer/logging.py", From 62ad31a74f4a62f8fae0f79b87dac9961501187b Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:23:29 +0200 Subject: [PATCH 29/45] separate --- .github/workflows/code-formatting.yml | 45 --------------------- .github/workflows/code-typing.yml | 56 +++++++++++++++++++++++++++ .pyrightconfig.json | 1 - 3 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/code-typing.yml diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 9faa95571f946..3c36d9f7b7073 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -25,48 +25,3 @@ jobs: - name: Run Black run: echo "LGTM" # run black --skip-string-normalization --config=pyproject.toml --check . # TODO, uncomment - - python-types: - name: Python static type checking with Pyright - runs-on: ubuntu-latest - - # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 15 - steps: - - name: Checkout - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - # Note: This uses an internal pip API and may not always work - # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow - - name: Cache pip - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Install dependencies - run: | - # python -m pip install --upgrade --user pip - pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q - HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q - # pip install tox coverage - python --version - pip --version - pip list - shell: bash - - - name: Set up node - uses: actions/setup-node@v1 - - - name: Install pyright - run: | - npm install pyright - - - name: Run type checking - run: | - $(npm bin)/pyright --project .pyrightconfig.json diff --git a/.github/workflows/code-typing.yml b/.github/workflows/code-typing.yml new file mode 100644 index 0000000000000..8dd62b598d816 --- /dev/null +++ b/.github/workflows/code-typing.yml @@ -0,0 +1,56 @@ +name: "Check Code Typing" +on: + # Trigger the workflow on push or pull request, + # but only for the master branch + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + python-types: + name: Python static type checking with Pyright + runs-on: ubuntu-latest + + # Timeout: https://stackoverflow.com/a/59076067/4521646 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + + # Note: This uses an internal pip API and may not always work + # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow + - name: Cache pip + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + # python -m pip install --upgrade --user pip + pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q + HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q + # pip install tox coverage + python --version + pip --version + pip list + shell: bash + + - name: Set up node + uses: actions/setup-node@v1 + + - name: Install pyright + run: | + npm install pyright + + - name: Run type checking + run: | + $(npm bin)/pyright --project .pyrightconfig.json diff --git a/.pyrightconfig.json b/.pyrightconfig.json index 74d4c46cfd018..bb65bfb38141e 100644 --- a/.pyrightconfig.json +++ b/.pyrightconfig.json @@ -17,7 +17,6 @@ "pytorch_lightning/utilities", "pytorch_lightning/trainer/data_loading.py", "pytorch_lightning/trainer/deprecated_api.py", - "pytorch_lightning/trainer/distrib_data_parallel.py", "pytorch_lightning/trainer/distrib_parts.py", "pytorch_lightning/trainer/evaluation_loop.py", "pytorch_lightning/trainer/logging.py", From b04241614ecab6ea87d51e9a97a5d152c0135cf5 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:31:42 +0200 Subject: [PATCH 30/45] os --- .github/workflows/code-typing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-typing.yml b/.github/workflows/code-typing.yml index 8dd62b598d816..bcc39a39abca1 100644 --- a/.github/workflows/code-typing.yml +++ b/.github/workflows/code-typing.yml @@ -12,7 +12,7 @@ on: jobs: python-types: name: Python static type checking with Pyright - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 # Timeout: https://stackoverflow.com/a/59076067/4521646 timeout-minutes: 15 From 221fbd5417b6ffb84805afc7590fde2465809c82 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:50:57 +0200 Subject: [PATCH 31/45] os --- .github/workflows/code-typing.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/code-typing.yml b/.github/workflows/code-typing.yml index bcc39a39abca1..3c10f33903483 100644 --- a/.github/workflows/code-typing.yml +++ b/.github/workflows/code-typing.yml @@ -46,6 +46,10 @@ jobs: - name: Set up node uses: actions/setup-node@v1 + run: | + rm -rf node_modules package-lock.json + npm install + npm start - name: Install pyright run: | From b4e56223b13dcd5195babb7578d588a8513bc2d9 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 13:59:57 +0200 Subject: [PATCH 32/45] npm --- .github/workflows/code-typing.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/code-typing.yml b/.github/workflows/code-typing.yml index 3c10f33903483..df3e08278c726 100644 --- a/.github/workflows/code-typing.yml +++ b/.github/workflows/code-typing.yml @@ -39,20 +39,15 @@ jobs: pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q # pip install tox coverage - python --version - pip --version - pip list + python --version ; pip --version ; pip list shell: bash - name: Set up node uses: actions/setup-node@v1 - run: | - rm -rf node_modules package-lock.json - npm install - npm start - name: Install pyright run: | + rm -rf node_modules package-lock.json npm install pyright - name: Run type checking From ae869f9649574d391888c76ad047452a61b54e06 Mon Sep 17 00:00:00 2001 From: airium Date: Sat, 20 Jun 2020 15:45:37 +0100 Subject: [PATCH 33/45] Fix load_from_checkpoint() not working with URL on Windows --- pytorch_lightning/utilities/cloud_io.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pytorch_lightning/utilities/cloud_io.py b/pytorch_lightning/utilities/cloud_io.py index de5bd1918e03b..2877163e27d13 100644 --- a/pytorch_lightning/utilities/cloud_io.py +++ b/pytorch_lightning/utilities/cloud_io.py @@ -5,8 +5,7 @@ def load(path_or_url: str, map_location=None): - parsed = urlparse(path_or_url) - if parsed.scheme == '' or Path(path_or_url).is_file(): - # no scheme or local file + if urlparse(path_or_url).scheme == '' or Path(path_or_url).drive: # no scheme or with a drive letter return torch.load(path_or_url, map_location=map_location) - return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location) + else: + return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location) From 40d9f620406e82a38c7c282bbc5232f0c6df6ae0 Mon Sep 17 00:00:00 2001 From: airium Date: Sat, 20 Jun 2020 16:03:38 +0100 Subject: [PATCH 34/45] Update CHANGELOG --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceef737f78cb3..b72b19af9a5ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed number batches in case of multiple dataloaders and `limit_{*}_batches` ([#1920](https://github.com/PyTorchLightning/pytorch-lightning/pull/1920), [#2226](https://github.com/PyTorchLightning/pytorch-lightning/pull/2226)) - Fixed an issue with forward hooks not being removed after model summary ([#2298](https://github.com/PyTorchLightning/pytorch-lightning/pull/2298)) +- Fixed for `load_from_checkpoint()` not working with absolute path on Windows ([#2294](https://github.com/PyTorchLightning/pytorch-lightning/pull/2294)) - Fixed an issue how _has_len handles `NotImplementedError` e.g. raised by `torchtext.data.Iterator` ([#2293](https://github.com/PyTorchLightning/pytorch-lightning/pull/2293)), ([#2307](https://github.com/PyTorchLightning/pytorch-lightning/pull/2307)) @@ -49,7 +50,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - Added `overfit_batches`, `limit_{val|test}_batches` flags (overfit now uses training set for all three) ([#2213](https://github.com/PyTorchLightning/pytorch-lightning/pull/2213)) -- Added metrics +- Added metrics * Base classes ([#1326](https://github.com/PyTorchLightning/pytorch-lightning/pull/1326), [#1877](https://github.com/PyTorchLightning/pytorch-lightning/pull/1877)) * Sklearn metrics classes ([#1327](https://github.com/PyTorchLightning/pytorch-lightning/pull/1327)) * Native torch metrics ([#1488](https://github.com/PyTorchLightning/pytorch-lightning/pull/1488), [#2062](https://github.com/PyTorchLightning/pytorch-lightning/pull/2062)) @@ -59,7 +60,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Allow dataloaders without sampler field present ([#1907](https://github.com/PyTorchLightning/pytorch-lightning/pull/1907)) - Added option `save_last` to save the model at the end of every epoch in `ModelCheckpoint` [(#1908)](https://github.com/PyTorchLightning/pytorch-lightning/pull/1908) - Early stopping checks `on_validation_end` ([#1458](https://github.com/PyTorchLightning/pytorch-lightning/pull/1458)) -- Attribute `best_model_path` to `ModelCheckpoint` for storing and later retrieving the path to the best saved model file ([#1799](https://github.com/PyTorchLightning/pytorch-lightning/pull/1799)) +- Attribute `best_model_path` to `ModelCheckpoint` for storing and later retrieving the path to the best saved model file ([#1799](https://github.com/PyTorchLightning/pytorch-lightning/pull/1799)) - Speed up single-core TPU training by loading data using `ParallelLoader` ([#2033](https://github.com/PyTorchLightning/pytorch-lightning/pull/2033)) - Added a model hook `transfer_batch_to_device` that enables moving custom data structures to the target device ([1756](https://github.com/PyTorchLightning/pytorch-lightning/pull/1756)) - Added [black](https://black.readthedocs.io/en/stable/) formatter for the code with code-checker on pull ([1610](https://github.com/PyTorchLightning/pytorch-lightning/pull/1610)) @@ -74,7 +75,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Allow user to select individual TPU core to train on ([#1729](https://github.com/PyTorchLightning/pytorch-lightning/pull/1729)) - Removed non-finite values from loss in `LRFinder` ([#1862](https://github.com/PyTorchLightning/pytorch-lightning/pull/1862)) -- Allow passing model hyperparameters as complete kwarg list ([#1896](https://github.com/PyTorchLightning/pytorch-lightning/pull/1896)) +- Allow passing model hyperparameters as complete kwarg list ([#1896](https://github.com/PyTorchLightning/pytorch-lightning/pull/1896)) - Renamed `ModelCheckpoint`'s attributes `best` to `best_model_score` and `kth_best_model` to `kth_best_model_path` ([#1799](https://github.com/PyTorchLightning/pytorch-lightning/pull/1799)) - Re-Enable Logger's `ImportError`s ([#1938](https://github.com/PyTorchLightning/pytorch-lightning/pull/1938)) - Changed the default value of the Trainer argument `weights_summary` from `full` to `top` ([#2029](https://github.com/PyTorchLightning/pytorch-lightning/pull/2029)) @@ -107,7 +108,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Run graceful training teardown on interpreter exit ([#1631](https://github.com/PyTorchLightning/pytorch-lightning/pull/1631)) - Fixed user warning when apex was used together with learning rate schedulers ([#1873](https://github.com/PyTorchLightning/pytorch-lightning/pull/1873)) -- Fixed multiple calls of `EarlyStopping` callback ([#1863](https://github.com/PyTorchLightning/pytorch-lightning/pull/1863)) +- Fixed multiple calls of `EarlyStopping` callback ([#1863](https://github.com/PyTorchLightning/pytorch-lightning/pull/1863)) - Fixed an issue with `Trainer.from_argparse_args` when passing in unknown Trainer args ([#1932](https://github.com/PyTorchLightning/pytorch-lightning/pull/1932)) - Fixed bug related to logger not being reset correctly for model after tuner algorithms ([#1933](https://github.com/PyTorchLightning/pytorch-lightning/pull/1933)) - Fixed root node resolution for SLURM cluster with dash in host name ([#1954](https://github.com/PyTorchLightning/pytorch-lightning/pull/1954)) From 8130dfa7fe0d506172513777b1013917e4f07aac Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 23 Jun 2020 07:22:33 +0200 Subject: [PATCH 35/45] Update CHANGELOG.md Co-authored-by: Peter Yu <2057325+yukw777@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b72b19af9a5ff..e02b14c1bed16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed number batches in case of multiple dataloaders and `limit_{*}_batches` ([#1920](https://github.com/PyTorchLightning/pytorch-lightning/pull/1920), [#2226](https://github.com/PyTorchLightning/pytorch-lightning/pull/2226)) - Fixed an issue with forward hooks not being removed after model summary ([#2298](https://github.com/PyTorchLightning/pytorch-lightning/pull/2298)) -- Fixed for `load_from_checkpoint()` not working with absolute path on Windows ([#2294](https://github.com/PyTorchLightning/pytorch-lightning/pull/2294)) +- Fix for `load_from_checkpoint()` not working with absolute path on Windows ([#2294](https://github.com/PyTorchLightning/pytorch-lightning/pull/2294)) - Fixed an issue how _has_len handles `NotImplementedError` e.g. raised by `torchtext.data.Iterator` ([#2293](https://github.com/PyTorchLightning/pytorch-lightning/pull/2293)), ([#2307](https://github.com/PyTorchLightning/pytorch-lightning/pull/2307)) From ddd97f501d0fbc5a0f614213c421b2bf509e8993 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 23 Jun 2020 07:23:17 +0200 Subject: [PATCH 36/45] Apply suggestions from code review --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e02b14c1bed16..32a08b4b8964b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed number batches in case of multiple dataloaders and `limit_{*}_batches` ([#1920](https://github.com/PyTorchLightning/pytorch-lightning/pull/1920), [#2226](https://github.com/PyTorchLightning/pytorch-lightning/pull/2226)) - Fixed an issue with forward hooks not being removed after model summary ([#2298](https://github.com/PyTorchLightning/pytorch-lightning/pull/2298)) + - Fix for `load_from_checkpoint()` not working with absolute path on Windows ([#2294](https://github.com/PyTorchLightning/pytorch-lightning/pull/2294)) - Fixed an issue how _has_len handles `NotImplementedError` e.g. raised by `torchtext.data.Iterator` ([#2293](https://github.com/PyTorchLightning/pytorch-lightning/pull/2293)), ([#2307](https://github.com/PyTorchLightning/pytorch-lightning/pull/2307)) From 41b51e77cc4801ec645b5ba30d45ae5aa1961ca1 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 17:38:56 +0200 Subject: [PATCH 37/45] fix --- tests/base/datasets.py | 12 +++++++++--- tests/base/model_utilities.py | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/base/datasets.py b/tests/base/datasets.py index 35edbfc948497..5eb32656c83a3 100644 --- a/tests/base/datasets.py +++ b/tests/base/datasets.py @@ -136,9 +136,15 @@ class TrialMNIST(MNIST): tensor([100, 100, 100]) """ - def __init__(self, root: str = PATH_DATASETS, train: bool = True, - normalize: tuple = (0.5, 1.0), download: bool = False, - num_samples: int = 100, digits: Optional[Sequence] = (0, 1, 2)): + def __init__( + self, + root: str = PATH_DATASETS, + train: bool = True, + normalize: tuple = (0.5, 1.0), + download: bool = False, + num_samples: int = 100, + digits: Optional[Sequence] = (0, 1, 2), + ): # number of examples per class self.num_samples = num_samples diff --git a/tests/base/model_utilities.py b/tests/base/model_utilities.py index 91dfe8b6f5bb0..cc083d735c0bf 100644 --- a/tests/base/model_utilities.py +++ b/tests/base/model_utilities.py @@ -4,7 +4,6 @@ class ModelTemplateData: - hparams: ... def dataloader(self, train: bool, num_samples: int = 100): dataset = TrialMNIST(root=self.data_root, train=train, num_samples=num_samples, download=True) From 54f04fad4f714d156ab38d684b751a4607aeb9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Fri, 26 Jun 2020 18:05:58 +0200 Subject: [PATCH 38/45] fix meta tags creating empty lines --- pytorch_lightning/core/saving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/core/saving.py b/pytorch_lightning/core/saving.py index 30ef214b4b493..d3085a8bfe6e3 100644 --- a/pytorch_lightning/core/saving.py +++ b/pytorch_lightning/core/saving.py @@ -304,7 +304,7 @@ def save_hparams_to_tags_csv(tags_csv: str, hparams: Union[dict, Namespace]) -> if isinstance(hparams, Namespace): hparams = vars(hparams) - with open(tags_csv, 'w') as fp: + with open(tags_csv, 'w', newline='') as fp: fieldnames = ['key', 'value'] writer = csv.DictWriter(fp, fieldnames=fieldnames) writer.writerow({'key': 'key', 'value': 'value'}) From f0584a0d0af7a50791f0072894bab16431be77f4 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 19:10:37 +0200 Subject: [PATCH 39/45] pyright --- .github/workflows/code-formatting.yml | 45 +++++++++++++++++++++- .github/workflows/code-typing.yml | 55 --------------------------- 2 files changed, 44 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/code-typing.yml diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 3c36d9f7b7073..55f5bdc12fb5f 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -1,4 +1,4 @@ -name: "Check Code Formatting" +name: "Check Code Format" on: # Trigger the workflow on push or pull request, # but only for the master branch @@ -25,3 +25,46 @@ jobs: - name: Run Black run: echo "LGTM" # run black --skip-string-normalization --config=pyproject.toml --check . # TODO, uncomment + + python-types: + name: Python static type checking with Pyright + runs-on: ubuntu-18.04 + + # Timeout: https://stackoverflow.com/a/59076067/4521646 + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + + # Note: This uses an internal pip API and may not always work + # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow + - name: Cache pip + uses: actions/cache@v1 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + # python -m pip install --upgrade --user pip + pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q + HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q + # pip install tox coverage + python --version ; pip --version ; pip list + shell: bash + + - name: Set up node + uses: actions/setup-node@v1 + + - name: Install pyright + run: | + npm install pyright@1.1.45 + + - name: Run type checking + run: | + $(npm bin)/pyright --project .pyrightconfig.json diff --git a/.github/workflows/code-typing.yml b/.github/workflows/code-typing.yml deleted file mode 100644 index df3e08278c726..0000000000000 --- a/.github/workflows/code-typing.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: "Check Code Typing" -on: - # Trigger the workflow on push or pull request, - # but only for the master branch - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - python-types: - name: Python static type checking with Pyright - runs-on: ubuntu-18.04 - - # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 15 - steps: - - name: Checkout - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - # Note: This uses an internal pip API and may not always work - # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow - - name: Cache pip - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Install dependencies - run: | - # python -m pip install --upgrade --user pip - pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q - HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q - # pip install tox coverage - python --version ; pip --version ; pip list - shell: bash - - - name: Set up node - uses: actions/setup-node@v1 - - - name: Install pyright - run: | - rm -rf node_modules package-lock.json - npm install pyright - - - name: Run type checking - run: | - $(npm bin)/pyright --project .pyrightconfig.json From 3f32abce4ef2e8ca693b232608744a54836d9e1c Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 26 Jun 2020 21:04:25 +0200 Subject: [PATCH 40/45] node --- .github/workflows/code-formatting.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 55f5bdc12fb5f..84c56644a70f3 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -60,10 +60,12 @@ jobs: - name: Set up node uses: actions/setup-node@v1 + with: + node-version: '12' - name: Install pyright run: | - npm install pyright@1.1.45 + npm install pyright - name: Run type checking run: | From 431f7d4e3f090c3d508e00262a6427b8ee031363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Sat, 27 Jun 2020 00:03:56 +0200 Subject: [PATCH 41/45] fix httpserver address --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 91312fc848582..8b9786bb2c154 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,7 +48,7 @@ def translate_path(self, path): class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): daemon_threads = True - with ThreadingHTTPServer(('', 0), Handler) as server: + with ThreadingHTTPServer(('localhost', 0), Handler) as server: server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates server_thread.daemon = True From eb102366ff5661f876372cd5ccd8f16bbafea86d Mon Sep 17 00:00:00 2001 From: Jirka Date: Sat, 27 Jun 2020 00:26:45 +0200 Subject: [PATCH 42/45] drop tutils.default_trainer_options --- tests/callbacks/test_callbacks.py | 5 ----- tests/callbacks/test_lr.py | 4 ---- tests/callbacks/test_progress_bar.py | 5 ----- tests/loggers/test_all.py | 3 --- tests/loggers/test_base.py | 3 --- tests/loggers/test_neptune.py | 1 - tests/models/test_cpu.py | 6 ------ tests/models/test_grad_norm.py | 1 - tests/models/test_hooks.py | 6 +----- tests/models/test_restore.py | 2 -- tests/trainer/test_dataloaders.py | 4 ---- tests/trainer/test_lr_finder.py | 9 --------- tests/trainer/test_optimizers.py | 6 ------ tests/trainer/test_trainer_steps.py | 2 -- 14 files changed, 1 insertion(+), 56 deletions(-) diff --git a/tests/callbacks/test_callbacks.py b/tests/callbacks/test_callbacks.py index 51fc36bcdc133..93794b56598ce 100644 --- a/tests/callbacks/test_callbacks.py +++ b/tests/callbacks/test_callbacks.py @@ -26,7 +26,6 @@ def validation_epoch_end(self, outputs): early_stop_callback=True, overfit_batches=0.20, max_epochs=20, - **tutils.default_trainer_options(), ) result = trainer.fit(model) print(trainer.current_epoch) @@ -166,7 +165,6 @@ def on_test_end(self, trainer, pl_module): limit_val_batches=0.1, limit_train_batches=0.2, progress_bar_refresh_rate=0, - **tutils.default_trainer_options(), ) assert not test_callback.setup_called @@ -284,7 +282,6 @@ def training_step(self, *args, **kwargs): early_stop_callback=stopping, overfit_batches=0.20, max_epochs=2, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -320,7 +317,6 @@ def test_model_checkpoint_with_non_string_input(tmpdir, save_top_k): checkpoint_callback=checkpoint, overfit_batches=0.20, max_epochs=2, - **tutils.default_trainer_options(), ) trainer.fit(model) @@ -343,7 +339,6 @@ def test_model_checkpoint_path(tmpdir, logger_version, expected): overfit_batches=0.2, max_epochs=2, logger=logger, - **tutils.default_trainer_options(), ) trainer.fit(model) diff --git a/tests/callbacks/test_lr.py b/tests/callbacks/test_lr.py index e8cb7f29d7186..ff12f98fbf19e 100644 --- a/tests/callbacks/test_lr.py +++ b/tests/callbacks/test_lr.py @@ -20,7 +20,6 @@ def test_lr_logger_single_lr(tmpdir): limit_val_batches=0.1, limit_train_batches=0.5, callbacks=[lr_logger], - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result @@ -44,7 +43,6 @@ def test_lr_logger_no_lr(tmpdir): limit_val_batches=0.1, limit_train_batches=0.5, callbacks=[lr_logger], - **tutils.default_trainer_options(), ) with pytest.warns(RuntimeWarning): @@ -66,7 +64,6 @@ def test_lr_logger_multi_lrs(tmpdir): limit_val_batches=0.1, limit_train_batches=0.5, callbacks=[lr_logger], - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result @@ -94,7 +91,6 @@ def test_lr_logger_param_groups(tmpdir): limit_val_batches=0.1, limit_train_batches=0.5, callbacks=[lr_logger], - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result diff --git a/tests/callbacks/test_progress_bar.py b/tests/callbacks/test_progress_bar.py index 6961dca437752..a7239f254b6ed 100644 --- a/tests/callbacks/test_progress_bar.py +++ b/tests/callbacks/test_progress_bar.py @@ -22,7 +22,6 @@ def test_progress_bar_on(callbacks, refresh_rate): progress_bar_refresh_rate=refresh_rate, max_epochs=1, overfit_batches=5, - **tutils.default_trainer_options(), ) progress_bars = [c for c in trainer.callbacks if isinstance(c, ProgressBarBase)] @@ -42,7 +41,6 @@ def test_progress_bar_off(callbacks, refresh_rate): trainer = Trainer( callbacks=callbacks, progress_bar_refresh_rate=refresh_rate, - **tutils.default_trainer_options(), ) progress_bars = [c for c in trainer.callbacks if isinstance(c, ProgressBar)] @@ -66,7 +64,6 @@ def test_progress_bar_totals(): progress_bar_refresh_rate=1, limit_val_batches=1.0, max_epochs=1, - **tutils.default_trainer_options(), ) bar = trainer.progress_bar_callback assert 0 == bar.total_train_batches @@ -114,7 +111,6 @@ def test_progress_bar_fast_dev_run(): trainer = Trainer( fast_dev_run=True, - **tutils.default_trainer_options(), ) progress_bar = trainer.progress_bar_callback @@ -182,7 +178,6 @@ def on_test_batch_end(self, trainer, pl_module): limit_train_batches=1.0, num_sanity_val_steps=2, max_epochs=3, - **tutils.default_trainer_options(), ) assert trainer.progress_bar_callback.refresh_rate == refresh_rate diff --git a/tests/loggers/test_all.py b/tests/loggers/test_all.py index a7b6a745266f8..1dff6e1dafec7 100644 --- a/tests/loggers/test_all.py +++ b/tests/loggers/test_all.py @@ -55,7 +55,6 @@ def log_metrics(self, metrics, step): limit_train_batches=0.2, limit_val_batches=0.5, fast_dev_run=True, - **tutils.default_trainer_options(), ) trainer.fit(model) @@ -92,7 +91,6 @@ def test_loggers_pickle(tmpdir, monkeypatch, logger_class): trainer = Trainer( max_epochs=1, logger=logger, - **tutils.default_trainer_options(), ) pkl_bytes = pickle.dumps(trainer) @@ -113,7 +111,6 @@ def test_logger_reset_correctly(tmpdir, extra_params): trainer = Trainer( default_root_dir=tmpdir, **extra_params, - **tutils.default_trainer_options(), ) logger1 = trainer.logger trainer.fit(model) diff --git a/tests/loggers/test_base.py b/tests/loggers/test_base.py index 1de26d46b7e63..34c109aedc4e4 100644 --- a/tests/loggers/test_base.py +++ b/tests/loggers/test_base.py @@ -70,7 +70,6 @@ def test_custom_logger(tmpdir): limit_train_batches=0.05, logger=logger, default_root_dir=tmpdir, - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1, "Training failed" @@ -91,7 +90,6 @@ def test_multiple_loggers(tmpdir): limit_train_batches=0.05, logger=[logger1, logger2], default_root_dir=tmpdir, - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1, "Training failed" @@ -150,7 +148,6 @@ def decorated(metrics, step): limit_train_batches=0.1, limit_val_batches=0.1, num_sanity_val_steps=0, - **tutils.default_trainer_options(), ) trainer.logger.log_metrics = _log_metrics_decorator( trainer.logger.log_metrics) diff --git a/tests/loggers/test_neptune.py b/tests/loggers/test_neptune.py index 136ce7be798d2..62ddeb1539494 100644 --- a/tests/loggers/test_neptune.py +++ b/tests/loggers/test_neptune.py @@ -85,7 +85,6 @@ def _run_training(logger): max_epochs=1, limit_train_batches=0.05, logger=logger, - **tutils.default_trainer_options(), ) trainer.fit(model) return logger diff --git a/tests/models/test_cpu.py b/tests/models/test_cpu.py index 2a3dabff02573..808163014adb3 100644 --- a/tests/models/test_cpu.py +++ b/tests/models/test_cpu.py @@ -29,7 +29,6 @@ def test_cpu_slurm_save_load(tmpdir): limit_train_batches=0.2, limit_val_batches=0.2, checkpoint_callback=ModelCheckpoint(tmpdir), - **tutils.default_trainer_options(), ) result = trainer.fit(model) real_global_step = trainer.global_step @@ -65,7 +64,6 @@ def test_cpu_slurm_save_load(tmpdir): max_epochs=1, logger=logger, checkpoint_callback=ModelCheckpoint(tmpdir), - **tutils.default_trainer_options(), ) model = EvalModelTemplate(**hparams) @@ -191,7 +189,6 @@ def test_running_test_after_fitting(tmpdir): limit_test_batches=0.2, checkpoint_callback=checkpoint, logger=logger, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -223,7 +220,6 @@ def test_running_test_no_val(tmpdir): checkpoint_callback=checkpoint, logger=logger, early_stop_callback=False, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -245,7 +241,6 @@ def test_simple_cpu(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=20, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -351,7 +346,6 @@ def train_dataloader(self): limit_val_batches=0, weights_summary=None, early_stop_callback=False, - **tutils.default_trainer_options(), ) result = trainer.fit(model) diff --git a/tests/models/test_grad_norm.py b/tests/models/test_grad_norm.py index 3d60a232ffa10..e2904816db2eb 100644 --- a/tests/models/test_grad_norm.py +++ b/tests/models/test_grad_norm.py @@ -89,7 +89,6 @@ def test_grad_tracking(tmpdir, norm_type, rtol=5e-3): logger=logger, track_grad_norm=norm_type, row_log_interval=1, # request grad_norms every batch - **tutils.default_trainer_options(), ) result = trainer.fit(model) diff --git a/tests/models/test_hooks.py b/tests/models/test_hooks.py index 8b2df43ae0e5e..c102737254ed1 100644 --- a/tests/models/test_hooks.py +++ b/tests/models/test_hooks.py @@ -22,7 +22,6 @@ def on_before_zero_grad(self, optimizer): trainer = Trainer( max_steps=max_steps, num_sanity_val_steps=5, - **tutils.default_trainer_options(), ) assert 0 == model.on_before_zero_grad_called trainer.fit(model) @@ -60,7 +59,6 @@ def training_epoch_end(self, outputs): max_epochs=num_epochs, default_root_dir=tmpdir, overfit_batches=2, - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1 @@ -100,9 +98,7 @@ def transfer_batch_to_device(self, data, device): model = CurrentTestModel() batch = CustomBatch((torch.zeros(5, 28), torch.ones(5, 1, dtype=torch.long))) - trainer = Trainer( - **tutils.default_trainer_options(), - ) + trainer = Trainer() # running .fit() would require us to implement custom data loaders, we mock the model reference instead trainer.get_model = MagicMock(return_value=model) batch_gpu = trainer.transfer_batch_to_gpu(batch, 0) diff --git a/tests/models/test_restore.py b/tests/models/test_restore.py index b87ce28cc454e..c77f7a841f3c3 100644 --- a/tests/models/test_restore.py +++ b/tests/models/test_restore.py @@ -84,7 +84,6 @@ def test_running_test_pretrained_model_cpu(tmpdir): limit_val_batches=0.2, checkpoint_callback=checkpoint, logger=logger, - **tutils.default_trainer_options(), ) # fit model @@ -116,7 +115,6 @@ def test_load_model_from_checkpoint(tmpdir): limit_val_batches=0.2, checkpoint_callback=ModelCheckpoint(tmpdir, save_top_k=-1), default_root_dir=tmpdir, - **tutils.default_trainer_options(), ) # fit model diff --git a/tests/trainer/test_dataloaders.py b/tests/trainer/test_dataloaders.py index 0682dd1b33ae1..70c6268972cf0 100644 --- a/tests/trainer/test_dataloaders.py +++ b/tests/trainer/test_dataloaders.py @@ -98,7 +98,6 @@ def test_multiple_val_dataloader(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=1.0, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -135,7 +134,6 @@ def test_step(self, batch, batch_idx, *args, **kwargs): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) trainer.fit(model) if ckpt_path == 'specific': @@ -164,7 +162,6 @@ def test_train_dataloader_passed_to_fit(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) fit_options = dict(train_dataloader=model.dataloader(train=True)) result = trainer.fit(model, **fit_options) @@ -182,7 +179,6 @@ def test_train_val_dataloaders_passed_to_fit(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) fit_options = dict(train_dataloader=model.dataloader(train=True), val_dataloaders=model.dataloader(train=False)) diff --git a/tests/trainer/test_lr_finder.py b/tests/trainer/test_lr_finder.py index 53e59acd25c0e..4e6bf68d17e4c 100755 --- a/tests/trainer/test_lr_finder.py +++ b/tests/trainer/test_lr_finder.py @@ -17,7 +17,6 @@ def test_error_on_more_than_1_optimizer(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, - **tutils.default_trainer_options(), ) with pytest.raises(MisconfigurationException): @@ -33,7 +32,6 @@ def test_model_reset_correctly(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, - **tutils.default_trainer_options(), ) before_state_dict = model.state_dict() @@ -56,7 +54,6 @@ def test_trainer_reset_correctly(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, - **tutils.default_trainer_options(), ) changed_attributes = ['callbacks', 'logger', 'max_steps', 'auto_lr_find', @@ -88,7 +85,6 @@ def test_trainer_arg_bool(tmpdir): default_root_dir=tmpdir, max_epochs=2, auto_lr_find=True, - **tutils.default_trainer_options(), ) trainer.fit(model) @@ -108,7 +104,6 @@ def test_trainer_arg_str(tmpdir): default_root_dir=tmpdir, max_epochs=2, auto_lr_find='my_fancy_lr', - **tutils.default_trainer_options(), ) trainer.fit(model) @@ -128,7 +123,6 @@ def test_call_to_trainer_method(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=2, - **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model, mode='linear') @@ -152,7 +146,6 @@ def test_accumulation_and_early_stopping(tmpdir): trainer = Trainer( default_root_dir=tmpdir, accumulate_grad_batches=2, - **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model, early_stop_threshold=None) @@ -176,7 +169,6 @@ def test_suggestion_parameters_work(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=3, - **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model) @@ -197,7 +189,6 @@ def test_suggestion_with_non_finite_values(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=3, - **tutils.default_trainer_options(), ) lrfinder = trainer.lr_find(model) diff --git a/tests/trainer/test_optimizers.py b/tests/trainer/test_optimizers.py index 4c29b6971c400..8fb51b243ef4e 100644 --- a/tests/trainer/test_optimizers.py +++ b/tests/trainer/test_optimizers.py @@ -19,7 +19,6 @@ def test_optimizer_with_scheduling(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -51,7 +50,6 @@ def test_multi_optimizer_with_scheduling(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -87,7 +85,6 @@ def test_multi_optimizer_with_scheduling_stepping(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -127,7 +124,6 @@ def test_reduce_lr_on_plateau_scheduling(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) results = trainer.fit(model) assert results == 1 @@ -218,7 +214,6 @@ def test_none_optimizer(tmpdir): max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2, - **tutils.default_trainer_options(), ) result = trainer.fit(model) @@ -243,7 +238,6 @@ def configure_optimizers(self): trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, - **tutils.default_trainer_options(), ) result = trainer.fit(model) assert result == 1 diff --git a/tests/trainer/test_trainer_steps.py b/tests/trainer/test_trainer_steps.py index 39753d8c47fdc..0a627d2442627 100644 --- a/tests/trainer/test_trainer_steps.py +++ b/tests/trainer/test_trainer_steps.py @@ -77,7 +77,6 @@ def test_full_training_loop_dict(tmpdir): trainer = Trainer( max_epochs=1, weights_summary=None, - **tutils.default_trainer_options(), ) trainer.fit(model) @@ -117,7 +116,6 @@ def test_train_step_epoch_end(tmpdir): trainer = Trainer( max_epochs=1, weights_summary=None, - **tutils.default_trainer_options(), ) trainer.fit(model) From a7b7151d84492ca974caad5b65fdc001ec126ca7 Mon Sep 17 00:00:00 2001 From: Jirka Date: Sat, 27 Jun 2020 00:29:54 +0200 Subject: [PATCH 43/45] imports --- tests/base/deterministic_model.py | 5 +++-- tests/base/develop_utils.py | 8 -------- tests/callbacks/test_progress_bar.py | 1 - tests/loggers/test_base.py | 1 - tests/loggers/test_neptune.py | 1 - tests/loggers/test_tensorboard.py | 2 +- tests/metrics/test_sklearn.py | 1 - tests/models/test_grad_norm.py | 1 - tests/models/test_hooks.py | 1 - tests/models/test_tpu.py | 1 + tests/trainer/test_dataloaders.py | 1 - tests/trainer/test_lr_finder.py | 1 - tests/trainer/test_optimizers.py | 1 - tests/trainer/test_trainer.py | 2 +- tests/trainer/test_trainer_steps.py | 1 - tests/trainer/test_trainer_tricks.py | 2 +- 16 files changed, 7 insertions(+), 23 deletions(-) diff --git a/tests/base/deterministic_model.py b/tests/base/deterministic_model.py index 1ca318ef1fac8..dc89e4dd7b1ba 100644 --- a/tests/base/deterministic_model.py +++ b/tests/base/deterministic_model.py @@ -1,7 +1,8 @@ +import numpy as np import torch -from pytorch_lightning.core.lightning import LightningModule from torch.utils.data import Dataset, DataLoader -import numpy as np + +from pytorch_lightning.core.lightning import LightningModule class DeterministicModel(LightningModule): diff --git a/tests/base/develop_utils.py b/tests/base/develop_utils.py index d9ad24ef5535c..6275c5ea67b64 100644 --- a/tests/base/develop_utils.py +++ b/tests/base/develop_utils.py @@ -1,5 +1,4 @@ import os -import platform import numpy as np @@ -11,13 +10,6 @@ from tests.base.model_template import EvalModelTemplate -def default_trainer_options(): - opt = {} - if platform.system() == "Windows": - opt.update(distributed_backend='dp') - return opt - - def assert_speed_parity_relative(pl_times, pt_times, max_diff: float = 0.1): # assert speeds diffs = np.asarray(pl_times) - np.asarray(pt_times) diff --git a/tests/callbacks/test_progress_bar.py b/tests/callbacks/test_progress_bar.py index a7239f254b6ed..a63fc62585c45 100644 --- a/tests/callbacks/test_progress_bar.py +++ b/tests/callbacks/test_progress_bar.py @@ -1,6 +1,5 @@ import pytest -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.callbacks import ProgressBarBase, ProgressBar, ModelCheckpoint from pytorch_lightning.utilities.exceptions import MisconfigurationException diff --git a/tests/loggers/test_base.py b/tests/loggers/test_base.py index 34c109aedc4e4..e330e50e581fe 100644 --- a/tests/loggers/test_base.py +++ b/tests/loggers/test_base.py @@ -6,7 +6,6 @@ from pytorch_lightning import Trainer from pytorch_lightning.loggers import LightningLoggerBase, LoggerCollection from pytorch_lightning.utilities import rank_zero_only -import tests.base.develop_utils as tutils from tests.base import EvalModelTemplate diff --git a/tests/loggers/test_neptune.py b/tests/loggers/test_neptune.py index 62ddeb1539494..3e8bb8c6bfaf2 100644 --- a/tests/loggers/test_neptune.py +++ b/tests/loggers/test_neptune.py @@ -2,7 +2,6 @@ import torch -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.loggers import NeptuneLogger from tests.base import EvalModelTemplate diff --git a/tests/loggers/test_tensorboard.py b/tests/loggers/test_tensorboard.py index 901fe9339dd21..e6df2bbc1c691 100644 --- a/tests/loggers/test_tensorboard.py +++ b/tests/loggers/test_tensorboard.py @@ -1,10 +1,10 @@ import os from argparse import Namespace -from packaging import version import pytest import torch import yaml +from packaging import version from tensorboard.backend.event_processing.event_accumulator import EventAccumulator from pytorch_lightning import Trainer diff --git a/tests/metrics/test_sklearn.py b/tests/metrics/test_sklearn.py index 335d4dc767b42..7b582cb03878b 100644 --- a/tests/metrics/test_sklearn.py +++ b/tests/metrics/test_sklearn.py @@ -1,5 +1,4 @@ import numbers -from collections import Mapping, Sequence from functools import partial import numpy as np diff --git a/tests/models/test_grad_norm.py b/tests/models/test_grad_norm.py index e2904816db2eb..3c0cd9d6c5b97 100644 --- a/tests/models/test_grad_norm.py +++ b/tests/models/test_grad_norm.py @@ -1,7 +1,6 @@ import numpy as np import pytest -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.loggers import LightningLoggerBase from pytorch_lightning.utilities import rank_zero_only diff --git a/tests/models/test_hooks.py b/tests/models/test_hooks.py index c102737254ed1..78efbd35ff4da 100644 --- a/tests/models/test_hooks.py +++ b/tests/models/test_hooks.py @@ -3,7 +3,6 @@ import pytest import torch -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate diff --git a/tests/models/test_tpu.py b/tests/models/test_tpu.py index 141ee90b962f4..d4ab9c340ec5c 100644 --- a/tests/models/test_tpu.py +++ b/tests/models/test_tpu.py @@ -2,6 +2,7 @@ from unittest.mock import patch import pytest + from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_dataloaders.py b/tests/trainer/test_dataloaders.py index 70c6268972cf0..3b44aa69c7164 100644 --- a/tests/trainer/test_dataloaders.py +++ b/tests/trainer/test_dataloaders.py @@ -6,7 +6,6 @@ from torch.utils.data.dataset import Subset import tests.base.develop_pipelines as tpipes -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_lr_finder.py b/tests/trainer/test_lr_finder.py index 4e6bf68d17e4c..69cbc47db52ee 100755 --- a/tests/trainer/test_lr_finder.py +++ b/tests/trainer/test_lr_finder.py @@ -1,7 +1,6 @@ import pytest import torch -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_optimizers.py b/tests/trainer/test_optimizers.py index 8fb51b243ef4e..5d49543705b9e 100644 --- a/tests/trainer/test_optimizers.py +++ b/tests/trainer/test_optimizers.py @@ -1,7 +1,6 @@ import pytest import torch -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index b5a6d75c4a6ad..1a2b3294894f6 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -19,8 +19,8 @@ load_hparams_from_tags_csv, load_hparams_from_yaml, save_hparams_to_tags_csv) from pytorch_lightning.loggers import TensorBoardLogger from pytorch_lightning.trainer.logging import TrainerLoggingMixin -from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.cloud_io import load as pl_load +from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate diff --git a/tests/trainer/test_trainer_steps.py b/tests/trainer/test_trainer_steps.py index 0a627d2442627..70302474bedf4 100644 --- a/tests/trainer/test_trainer_steps.py +++ b/tests/trainer/test_trainer_steps.py @@ -1,4 +1,3 @@ -import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from tests.base.deterministic_model import DeterministicModel diff --git a/tests/trainer/test_trainer_tricks.py b/tests/trainer/test_trainer_tricks.py index b7abe9af1c6e3..32415ffe2e9ac 100755 --- a/tests/trainer/test_trainer_tricks.py +++ b/tests/trainer/test_trainer_tricks.py @@ -1,11 +1,11 @@ import pytest import torch +from torch.utils.data import RandomSampler, SequentialSampler, DataLoader import tests.base.develop_utils as tutils from pytorch_lightning import Trainer from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.base import EvalModelTemplate -from torch.utils.data import RandomSampler, SequentialSampler, DataLoader def test_overfit_batch_limits(tmpdir): From 2e37e26722807ba7ad4cc0afca23aa002debb270 Mon Sep 17 00:00:00 2001 From: AIRIUM <38249940+airium@users.noreply.github.com> Date: Fri, 26 Jun 2020 23:39:37 +0100 Subject: [PATCH 44/45] Better fix for load_from_checkpoint() not working with absolute path on Windows (#2294) * Fix load_from_checkpoint() not working with URL on Windows * Update CHANGELOG * Update CHANGELOG.md Co-authored-by: Peter Yu <2057325+yukw777@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jirka Borovec Co-authored-by: Peter Yu <2057325+yukw777@users.noreply.github.com> From 06c0b6d79fcd32d0adf5943ef155749689078c27 Mon Sep 17 00:00:00 2001 From: Jirka Date: Sat, 27 Jun 2020 00:50:03 +0200 Subject: [PATCH 45/45] drop duplicate --- .github/workflows/python-type-check.yml | 67 ------------------------- 1 file changed, 67 deletions(-) delete mode 100644 .github/workflows/python-type-check.yml diff --git a/.github/workflows/python-type-check.yml b/.github/workflows/python-type-check.yml deleted file mode 100644 index 1616d58f3be30..0000000000000 --- a/.github/workflows/python-type-check.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: "Python static type checking" -on: - # Trigger the workflow on push or pull request, - # but only for the master branch - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - python_type_checking: - name: Python static type checking with Pyright - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-18.04] - python-version: [3.7] - - # Timeout: https://stackoverflow.com/a/59076067/4521646 - timeout-minutes: 15 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - # Note: This uses an internal pip API and may not always work - # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow - - name: Get pip cache - id: pip-cache - run: | - python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)" - - - name: Cache pip - uses: actions/cache@v1 - with: - path: ${{ steps.pip-cache.outputs.dir }} - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/extra.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip- - - - name: Install dependencies - run: | - # python -m pip install --upgrade --user pip - pip install -r requirements/base.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q - HOROVOD_BUILD_ARCH_FLAGS="-mfma" pip install -r ./requirements/devel.txt -q - # pip install tox coverage - python --version - pip --version - pip list - shell: bash - - - name: Set up node - uses: actions/setup-node@v1 - - - name: Install pyright - run: | - npm install pyright@1.1.45 - - - name: Run type checking - run: | - $(npm bin)/pyright --project .pyrightconfig.json