Remove deprecated trainer_optimizer_mixin (#14887)
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
This commit is contained in:
parent
dce5644101
commit
8c01e82e26
|
@ -222,7 +222,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
||||||
- Removed the deprecated `Trainer.use_amp` and `LightningModule.use_amp` attributes ([#14832](https://github.com/Lightning-AI/lightning/pull/14832))
|
- Removed the deprecated `Trainer.use_amp` and `LightningModule.use_amp` attributes ([#14832](https://github.com/Lightning-AI/lightning/pull/14832))
|
||||||
|
|
||||||
|
|
||||||
- Removed the deprecated `Trainer.run_stage` in favor of `Trainer.{fit,validate,test,predict}`
|
- Removed the deprecated `Trainer.run_stage` in favor of `Trainer.{fit,validate,test,predict}` ([#14870](https://github.com/Lightning-AI/lightning/pull/14870))
|
||||||
|
|
||||||
|
|
||||||
- Removed the deprecated `SimpleProfiler.profile_iterable` and `AdvancedProfiler.profile_iterable` attributes ([#14864](https://github.com/Lightning-AI/lightning/pull/14864))
|
- Removed the deprecated `SimpleProfiler.profile_iterable` and `AdvancedProfiler.profile_iterable` attributes ([#14864](https://github.com/Lightning-AI/lightning/pull/14864))
|
||||||
|
@ -231,7 +231,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
||||||
- Removed the deprecated `Trainer.verbose_evaluate` ([#14884](https://github.com/Lightning-AI/lightning/pull/14884))
|
- Removed the deprecated `Trainer.verbose_evaluate` ([#14884](https://github.com/Lightning-AI/lightning/pull/14884))
|
||||||
|
|
||||||
|
|
||||||
- Remove the deprecated `Trainer.should_rank_save_checkpoint` ([#14885](https://github.com/Lightning-AI/lightning/pull/14885))
|
- Removed the deprecated `Trainer.should_rank_save_checkpoint` ([#14885](https://github.com/Lightning-AI/lightning/pull/14885))
|
||||||
|
|
||||||
|
|
||||||
|
- Removed the deprecated `TrainerOptimizersMixin` ([#14887](https://github.com/Lightning-AI/lightning/pull/14887))
|
||||||
|
|
||||||
|
|
||||||
- Removed the deprecated `Trainer.lightning_optimizers` ([#14889](https://github.com/Lightning-AI/lightning/pull/14889))
|
- Removed the deprecated `Trainer.lightning_optimizers` ([#14889](https://github.com/Lightning-AI/lightning/pull/14889))
|
||||||
|
|
||||||
|
|
|
@ -1,65 +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.
|
|
||||||
|
|
||||||
from abc import ABC
|
|
||||||
from typing import List, Optional, Tuple
|
|
||||||
|
|
||||||
from torch.optim import Optimizer
|
|
||||||
|
|
||||||
import pytorch_lightning as pl
|
|
||||||
from pytorch_lightning.core.optimizer import _init_optimizers_and_lr_schedulers, LightningOptimizer
|
|
||||||
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
|
|
||||||
|
|
||||||
|
|
||||||
class TrainerOptimizersMixin(ABC):
|
|
||||||
r"""
|
|
||||||
.. deprecated:: v1.6
|
|
||||||
The `TrainerOptimizersMixin` was deprecated in v1.6 and will be removed in v1.8.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def init_optimizers(self, model: Optional["pl.LightningModule"]) -> Tuple[List, List, List]:
|
|
||||||
r"""
|
|
||||||
.. deprecated:: v1.6
|
|
||||||
`TrainerOptimizersMixin.init_optimizers` was deprecated in v1.6 and will be removed in v1.8.
|
|
||||||
"""
|
|
||||||
rank_zero_deprecation(
|
|
||||||
"`TrainerOptimizersMixin.init_optimizers` was deprecated in v1.6 and will be removed in v1.8."
|
|
||||||
)
|
|
||||||
pl_module = self.lightning_module or model
|
|
||||||
assert isinstance(pl_module, pl.LightningModule)
|
|
||||||
return _init_optimizers_and_lr_schedulers(pl_module)
|
|
||||||
|
|
||||||
def convert_to_lightning_optimizers(self) -> None:
|
|
||||||
r"""
|
|
||||||
.. deprecated:: v1.6
|
|
||||||
`TrainerOptimizersMixin.convert_to_lightning_optimizers` was deprecated in v1.6 and will be removed in v1.8.
|
|
||||||
"""
|
|
||||||
rank_zero_deprecation(
|
|
||||||
"`TrainerOptimizersMixin.convert_to_lightning_optimizers` was deprecated in v1.6 and will be removed in "
|
|
||||||
"v1.8."
|
|
||||||
)
|
|
||||||
|
|
||||||
def _convert_to_lightning_optimizer(optimizer: Optimizer) -> LightningOptimizer:
|
|
||||||
if not isinstance(optimizer, LightningOptimizer):
|
|
||||||
optimizer = LightningOptimizer(optimizer) # type: ignore [assignment]
|
|
||||||
optimizer._trainer = self
|
|
||||||
for opt_idx, opt in enumerate(self.optimizers):
|
|
||||||
if opt == optimizer._optimizer:
|
|
||||||
optimizer._optimizer_idx = opt_idx
|
|
||||||
break
|
|
||||||
return optimizer # type: ignore [return-value]
|
|
||||||
|
|
||||||
self.strategy._cached_lightning_optimizers = {
|
|
||||||
idx: _convert_to_lightning_optimizer(opt) for idx, opt in enumerate(self.optimizers)
|
|
||||||
}
|
|
|
@ -74,7 +74,6 @@ from pytorch_lightning.trainer.connectors.data_connector import DataConnector
|
||||||
from pytorch_lightning.trainer.connectors.logger_connector import LoggerConnector
|
from pytorch_lightning.trainer.connectors.logger_connector import LoggerConnector
|
||||||
from pytorch_lightning.trainer.connectors.logger_connector.result import _ResultCollection
|
from pytorch_lightning.trainer.connectors.logger_connector.result import _ResultCollection
|
||||||
from pytorch_lightning.trainer.connectors.signal_connector import SignalConnector
|
from pytorch_lightning.trainer.connectors.signal_connector import SignalConnector
|
||||||
from pytorch_lightning.trainer.optimizers import TrainerOptimizersMixin
|
|
||||||
from pytorch_lightning.trainer.states import RunningStage, TrainerFn, TrainerState, TrainerStatus
|
from pytorch_lightning.trainer.states import RunningStage, TrainerFn, TrainerState, TrainerStatus
|
||||||
from pytorch_lightning.trainer.supporters import CombinedLoader
|
from pytorch_lightning.trainer.supporters import CombinedLoader
|
||||||
from pytorch_lightning.tuner.tuning import _TunerResult, Tuner
|
from pytorch_lightning.tuner.tuning import _TunerResult, Tuner
|
||||||
|
@ -108,9 +107,7 @@ warnings.filterwarnings(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Trainer(
|
class Trainer:
|
||||||
TrainerOptimizersMixin, # TODO: Remove in v1.8
|
|
||||||
):
|
|
||||||
@_defaults_from_env_vars
|
@_defaults_from_env_vars
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -62,24 +62,6 @@ def test_v1_8_0_trainer_ckpt_path_attributes(fn_prefix: str):
|
||||||
setattr(trainer, test_attr, "v")
|
setattr(trainer, test_attr, "v")
|
||||||
|
|
||||||
|
|
||||||
def test_v1_8_0_trainer_optimizers_mixin():
|
|
||||||
trainer = Trainer()
|
|
||||||
model = BoringModel()
|
|
||||||
trainer.strategy.connect(model)
|
|
||||||
trainer.lightning_module.trainer = trainer
|
|
||||||
|
|
||||||
with pytest.deprecated_call(
|
|
||||||
match=r"`TrainerOptimizersMixin.init_optimizers` was deprecated in v1.6 and will be removed in v1.8."
|
|
||||||
):
|
|
||||||
trainer.init_optimizers(model)
|
|
||||||
|
|
||||||
with pytest.deprecated_call(
|
|
||||||
match=r"`TrainerOptimizersMixin.convert_to_lightning_optimizers` was deprecated in v1.6 and will be removed in "
|
|
||||||
"v1.8."
|
|
||||||
):
|
|
||||||
trainer.convert_to_lightning_optimizers()
|
|
||||||
|
|
||||||
|
|
||||||
def test_v_1_8_0_deprecated_device_stats_monitor_prefix_metric_keys():
|
def test_v_1_8_0_deprecated_device_stats_monitor_prefix_metric_keys():
|
||||||
from pytorch_lightning.callbacks.device_stats_monitor import prefix_metric_keys
|
from pytorch_lightning.callbacks.device_stats_monitor import prefix_metric_keys
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue