From 7b26610e64d889385a975053430abcb8fd8cc2d5 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Mon, 2 Aug 2021 16:17:06 +0200 Subject: [PATCH 1/2] Delete deprecated `TrainerTrainingTricksMixin` --- pytorch_lightning/trainer/trainer.py | 2 - pytorch_lightning/trainer/training_tricks.py | 58 -------------------- tests/deprecated_api/test_remove_1-5.py | 12 ---- 3 files changed, 72 deletions(-) delete mode 100644 pytorch_lightning/trainer/training_tricks.py diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index e3a52a09d1bc8..f2ebe8dabd058 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -62,7 +62,6 @@ from pytorch_lightning.trainer.optimizers import TrainerOptimizersMixin from pytorch_lightning.trainer.properties import TrainerProperties from pytorch_lightning.trainer.states import TrainerFn, TrainerState, TrainerStatus -from pytorch_lightning.trainer.training_tricks import TrainerTrainingTricksMixin from pytorch_lightning.tuner.auto_gpu_select import pick_multiple_gpus from pytorch_lightning.tuner.lr_finder import _LRFinder from pytorch_lightning.tuner.tuning import Tuner @@ -96,7 +95,6 @@ class Trainer( TrainerCallbackHookMixin, TrainerModelHooksMixin, TrainerOptimizersMixin, - TrainerTrainingTricksMixin, TrainerDataLoadingMixin, DeprecatedTrainerAttributes, ): diff --git a/pytorch_lightning/trainer/training_tricks.py b/pytorch_lightning/trainer/training_tricks.py deleted file mode 100644 index c1e092a136a3d..0000000000000 --- a/pytorch_lightning/trainer/training_tricks.py +++ /dev/null @@ -1,58 +0,0 @@ -# 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 logging -from abc import ABC - -import torch -from torch import Tensor - -import pytorch_lightning as pl -from pytorch_lightning.utilities import rank_zero_deprecation -from pytorch_lightning.utilities.finite_checks import detect_nan_parameters, print_nan_gradients - -log = logging.getLogger(__name__) - - -class TrainerTrainingTricksMixin(ABC): - """ - TODO: Remove this class in v1.5. - - Use the NaN utilities from ``pytorch_lightning.utilities.finite_checks`` instead. - """ - - # this is just a summary on variables used in this abstract class, - # the proper values/initialisation should be done in child class - lightning_module: "pl.LightningModule" - - def print_nan_gradients(self) -> None: - rank_zero_deprecation( - "Internal: TrainerTrainingTricksMixin.print_nan_gradients is deprecated in v1.3" - " and will be removed in v1.5." - " Use `pytorch_lightning.utilities.finite_checks.print_nan_gradients` instead." - ) - model = self.lightning_module - print_nan_gradients(model) - - def detect_nan_tensors(self, loss: Tensor) -> None: - rank_zero_deprecation( - "Internal: TrainerTrainingTricksMixin.detect_nan_tensors is deprecated in v1.3" - " and will be removed in v1.5." - " Use `pytorch_lightning.utilities.finite_checks.detect_nan_parameters` instead." - ) - # check if loss is nan - if not torch.isfinite(loss).all(): - raise ValueError("The loss returned in `training_step` is nan or inf.") - model = self.lightning_module - detect_nan_parameters(model) diff --git a/tests/deprecated_api/test_remove_1-5.py b/tests/deprecated_api/test_remove_1-5.py index d6adb71de0dac..c8e5097de1a77 100644 --- a/tests/deprecated_api/test_remove_1-5.py +++ b/tests/deprecated_api/test_remove_1-5.py @@ -181,18 +181,6 @@ def test_v1_5_0_profiler_output_filename(tmpdir, cls): assert profiler.filename == "test" -def test_v1_5_0_trainer_training_trick_mixin(tmpdir): - model = BoringModel() - trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, checkpoint_callback=False, logger=False) - trainer.fit(model) - with pytest.deprecated_call(match="is deprecated in v1.3 and will be removed in v1.5"): - trainer.print_nan_gradients() - - dummy_loss = torch.tensor(1.0) - with pytest.deprecated_call(match="is deprecated in v1.3 and will be removed in v1.5"): - trainer.detect_nan_tensors(dummy_loss) - - def test_v1_5_0_auto_move_data(): with pytest.deprecated_call(match="deprecated in v1.3 and will be removed in v1.5.*was applied to `bar`"): From fdec9c01079f37d6dc869f0f67ccbf900c712904 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Mon, 2 Aug 2021 16:19:01 +0200 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2d8491eba9a..1a6ff631f1792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,16 +61,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed the deprecated `outputs` argument in both the `LightningModule.on_train_epoch_end` and `Callback.on_train_epoch_end` hooks ([#8587](https://github.com/PyTorchLightning/pytorch-lightning/pull/8587)) +- Removed the deprecated `TrainerLoggingMixin` class ([#8609](https://github.com/PyTorchLightning/pytorch-lightning/pull/8609)) -- Delete the deprecated `TrainerLoggingMixin` class ([#8609](https://github.com/PyTorchLightning/pytorch-lightning/pull/8609)) +- Removed the deprecated `TrainerTrainingTricksMixin` class ([#8679](https://github.com/PyTorchLightning/pytorch-lightning/pull/8679)) - Removed the deprecated `optimizer_idx` from `training_step` as an accepted argument in manual optimization ([#8576](https://github.com/PyTorchLightning/pytorch-lightning/pull/8576)) - - - ### Fixed - Fixed `trainer.fit_loop.split_idx` always returning `None` ([#8601](https://github.com/PyTorchLightning/pytorch-lightning/pull/8601))