From 40d952c180f6366f619de28949f00acb06582292 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 23 Mar 2021 16:18:46 +0100 Subject: [PATCH] ... --- pytorch_lightning/accelerators/accelerator.py | 2 +- pytorch_lightning/accelerators/gpu.py | 2 +- pytorch_lightning/trainer/callback_hook.py | 2 +- .../trainer/connectors/callback_connector.py | 7 +------ tests/accelerators/test_cpu.py | 3 +-- tests/accelerators/test_dp.py | 2 +- tests/deprecated_api/test_remove_1-5.py | 7 ++++++- tests/plugins/test_deepspeed_plugin.py | 18 +++++++----------- 8 files changed, 19 insertions(+), 24 deletions(-) diff --git a/pytorch_lightning/accelerators/accelerator.py b/pytorch_lightning/accelerators/accelerator.py index f93e95a14981ec..5afe8b15c2e88a 100644 --- a/pytorch_lightning/accelerators/accelerator.py +++ b/pytorch_lightning/accelerators/accelerator.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, Callable, Iterable, Optional, Union, Sequence +from typing import Any, Callable, Iterable, Optional, Sequence, Union import torch from torch.optim import Optimizer diff --git a/pytorch_lightning/accelerators/gpu.py b/pytorch_lightning/accelerators/gpu.py index af9ce25f902b3e..5c5dc5cc6f5318 100644 --- a/pytorch_lightning/accelerators/gpu.py +++ b/pytorch_lightning/accelerators/gpu.py @@ -1,6 +1,6 @@ import logging import os -from typing import TYPE_CHECKING, Any +from typing import Any, TYPE_CHECKING import torch diff --git a/pytorch_lightning/trainer/callback_hook.py b/pytorch_lightning/trainer/callback_hook.py index 60e9183ac42f7e..d33338055a5b13 100644 --- a/pytorch_lightning/trainer/callback_hook.py +++ b/pytorch_lightning/trainer/callback_hook.py @@ -15,7 +15,7 @@ from abc import ABC from copy import deepcopy from inspect import signature -from typing import List, Dict, Any, Type, Callable +from typing import Any, Callable, Dict, List, Type from pytorch_lightning.callbacks import Callback from pytorch_lightning.core.lightning import LightningModule diff --git a/pytorch_lightning/trainer/connectors/callback_connector.py b/pytorch_lightning/trainer/connectors/callback_connector.py index 14694c8f778116..ee768c05cc8a27 100644 --- a/pytorch_lightning/trainer/connectors/callback_connector.py +++ b/pytorch_lightning/trainer/connectors/callback_connector.py @@ -14,12 +14,7 @@ import os from typing import List, Union -from pytorch_lightning.callbacks import ( - Callback, - ModelCheckpoint, - ProgressBar, - ProgressBarBase, -) +from pytorch_lightning.callbacks import Callback, ModelCheckpoint, ProgressBar, ProgressBarBase from pytorch_lightning.core.lightning import LightningModule from pytorch_lightning.utilities import rank_zero_info, rank_zero_warn from pytorch_lightning.utilities.exceptions import MisconfigurationException diff --git a/tests/accelerators/test_cpu.py b/tests/accelerators/test_cpu.py index 5c97527be048bd..81a5132e473569 100644 --- a/tests/accelerators/test_cpu.py +++ b/tests/accelerators/test_cpu.py @@ -14,8 +14,7 @@ def test_unsupported_precision_plugins(): trainer = Mock() model = Mock() accelerator = CPUAccelerator( - training_type_plugin=SingleDevicePlugin(torch.device("cpu")), - precision_plugin=MixedPrecisionPlugin() + training_type_plugin=SingleDevicePlugin(torch.device("cpu")), precision_plugin=MixedPrecisionPlugin() ) with pytest.raises(MisconfigurationException, match=r"amp \+ cpu is not supported."): accelerator.setup(trainer=trainer, model=model) diff --git a/tests/accelerators/test_dp.py b/tests/accelerators/test_dp.py index 15faf98d94d575..8252aac9e90921 100644 --- a/tests/accelerators/test_dp.py +++ b/tests/accelerators/test_dp.py @@ -23,10 +23,10 @@ from pytorch_lightning.callbacks import EarlyStopping from pytorch_lightning.core import memory from pytorch_lightning.utilities.exceptions import MisconfigurationException +from tests.base import EvalModelTemplate from tests.helpers import BoringModel, RandomDataset from tests.helpers.datamodules import ClassifDataModule from tests.helpers.simple_models import ClassificationModel -from tests.base import EvalModelTemplate class CustomClassificationModelDP(ClassificationModel): diff --git a/tests/deprecated_api/test_remove_1-5.py b/tests/deprecated_api/test_remove_1-5.py index 415f1d040ba705..cb1d4614146038 100644 --- a/tests/deprecated_api/test_remove_1-5.py +++ b/tests/deprecated_api/test_remove_1-5.py @@ -17,7 +17,7 @@ import pytest -from pytorch_lightning import Trainer, Callback +from pytorch_lightning import Callback, Trainer from pytorch_lightning.loggers import WandbLogger from tests.helpers import BoringModel from tests.helpers.utils import no_warning_call @@ -30,7 +30,9 @@ def test_v1_5_0_wandb_unused_sync_step(tmpdir): def test_v1_5_0_old_callback_on_save_checkpoint(tmpdir): + class OldSignature(Callback): + def on_save_checkpoint(self, trainer, pl_module): # noqa ... @@ -49,14 +51,17 @@ def on_save_checkpoint(self, trainer, pl_module): # noqa trainer.save_checkpoint(filepath) class NewSignature(Callback): + def on_save_checkpoint(self, trainer, pl_module, checkpoint): ... class ValidSignature1(Callback): + def on_save_checkpoint(self, trainer, *args): ... class ValidSignature2(Callback): + def on_save_checkpoint(self, *args): ... diff --git a/tests/plugins/test_deepspeed_plugin.py b/tests/plugins/test_deepspeed_plugin.py index cb084734c5565e..7683d0c727198b 100644 --- a/tests/plugins/test_deepspeed_plugin.py +++ b/tests/plugins/test_deepspeed_plugin.py @@ -285,16 +285,8 @@ def on_train_start(self) -> None: raise SystemExit() model = TestModel() - ds = DeepSpeedPlugin( - loss_scale=10, initial_scale_power=10, loss_scale_window=10, hysteresis=10, min_loss_scale=10 - ) - trainer = Trainer( - plugins=[ - ds - ], - precision=16, - gpus=1 - ) + ds = DeepSpeedPlugin(loss_scale=10, initial_scale_power=10, loss_scale_window=10, hysteresis=10, min_loss_scale=10) + trainer = Trainer(plugins=[ds], precision=16, gpus=1) with pytest.raises(SystemExit): trainer.fit(model) @@ -318,7 +310,11 @@ def on_train_start(self) -> None: raise SystemExit() model = TestModel() - trainer = Trainer(plugins=[DeepSpeedPlugin(config=deepspeed_zero_config)], precision=16, gpus=1,) + trainer = Trainer( + plugins=[DeepSpeedPlugin(config=deepspeed_zero_config)], + precision=16, + gpus=1, + ) with pytest.raises(SystemExit): trainer.fit(model)