diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bfe08edb1..524540530b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -333,8 +333,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed `is_global_zero` check in `training_epoch_loop` before `logger.save`. If you have a custom logger that implements `save` the Trainer will now call `save` on all ranks by default. To change this behavior add `@rank_zero_only` to your `save` implementation ([#12134](https://github.com/PyTorchLightning/pytorch-lightning/pull/12134)) +- Disabled tuner with distributed strategies ([#12179](https://github.com/PyTorchLightning/pytorch-lightning/pull/12179)) + + - Marked `trainer.logger_connector` as protected ([#12195](https://github.com/PyTorchLightning/pytorch-lightning/pull/12195)) + ### Deprecated - Deprecated `training_type_plugin` property in favor of `strategy` in `Trainer` and updated the references ([#11141](https://github.com/PyTorchLightning/pytorch-lightning/pull/11141)) diff --git a/pytorch_lightning/tuner/tuning.py b/pytorch_lightning/tuner/tuning.py index f64183a92b..b1a38bd276 100644 --- a/pytorch_lightning/tuner/tuning.py +++ b/pytorch_lightning/tuner/tuning.py @@ -17,6 +17,7 @@ import pytorch_lightning as pl from pytorch_lightning.trainer.states import TrainerStatus from pytorch_lightning.tuner.batch_size_scaling import scale_batch_size from pytorch_lightning.tuner.lr_finder import _LRFinder, lr_find +from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.types import EVAL_DATALOADERS, TRAIN_DATALOADERS @@ -43,6 +44,13 @@ class Tuner: self.trainer.strategy.connect(model) + is_tuning = self.trainer.auto_scale_batch_size or self.trainer.auto_lr_find + if self.trainer._accelerator_connector.is_distributed and is_tuning: + raise MisconfigurationException( + "`trainer.tune()` is currently not supported with" + f" `Trainer(strategy={self.trainer.strategy.strategy_name!r})`." + ) + # Run auto batch size scaling if self.trainer.auto_scale_batch_size: if isinstance(self.trainer.auto_scale_batch_size, str): diff --git a/tests/tuner/test_auto_gpu_select.py b/tests/trainer/properties/test_auto_gpu_select.py similarity index 100% rename from tests/tuner/test_auto_gpu_select.py rename to tests/trainer/properties/test_auto_gpu_select.py diff --git a/tests/tuner/test_tuning.py b/tests/tuner/test_tuning.py new file mode 100644 index 0000000000..aadacb6440 --- /dev/null +++ b/tests/tuner/test_tuning.py @@ -0,0 +1,27 @@ +# Copyright The PyTorch Lightning team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +import pytest + +from pytorch_lightning import Trainer +from pytorch_lightning.utilities.exceptions import MisconfigurationException +from tests.helpers.boring_model import BoringModel + + +def test_tuner_with_distributed_strategies(): + """Test that an error is raised when tuner is used with multi-device strategy.""" + trainer = Trainer(auto_scale_batch_size=True, devices=2, strategy="ddp", accelerator="cpu") + model = BoringModel() + + with pytest.raises(MisconfigurationException, match=r"not supported with `Trainer\(strategy='ddp'\)`"): + trainer.tune(model)