lightning/tests/tests_pytorch/deprecated_api/test_remove_1-10.py

66 lines
2.7 KiB
Python
Raw Normal View History

# 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.
"""Test deprecated functionality which will be removed in v1.10.0."""
import pytest
from pytorch_lightning import Trainer
from pytorch_lightning.demos.boring_classes import BoringModel
from pytorch_lightning.overrides import LightningDistributedModule, LightningParallelModule
from pytorch_lightning.overrides.base import unwrap_lightning_module
from pytorch_lightning.overrides.fairscale import LightningShardedDataParallel, unwrap_lightning_module_sharded
from pytorch_lightning.strategies.bagua import LightningBaguaModule
from pytorch_lightning.strategies.deepspeed import LightningDeepSpeedModule
from pytorch_lightning.strategies.ipu import LightningIPUModule
from tests_pytorch.helpers.runif import RunIf
from tests_pytorch.helpers.utils import no_warning_call
def test_deprecated_amp_level():
with pytest.deprecated_call(match="Setting `amp_level` inside the `Trainer` is deprecated in v1.8.0"):
Trainer(amp_level="O3", amp_backend="apex")
@pytest.mark.parametrize(
"wrapper_class",
[
LightningParallelModule,
LightningDistributedModule,
LightningBaguaModule,
LightningDeepSpeedModule,
pytest.param(LightningShardedDataParallel, marks=RunIf(fairscale=True)),
LightningIPUModule,
],
)
def test_v1_10_deprecated_pl_module_init_parameter(wrapper_class):
with no_warning_call(
DeprecationWarning, match=rf"The argument `pl_module` in `{wrapper_class.__name__}` is deprecated in v1.8.0"
):
wrapper_class(BoringModel())
with pytest.deprecated_call(
match=rf"The argument `pl_module` in `{wrapper_class.__name__}` is deprecated in v1.8.0"
):
wrapper_class(pl_module=BoringModel())
def test_v1_10_deprecated_unwrap_lightning_module():
with pytest.deprecated_call(match=r"The function `unwrap_lightning_module` is deprecated in v1.8.0"):
unwrap_lightning_module(BoringModel())
@RunIf(fairscale=True)
def test_v1_10_deprecated_unwrap_lightning_module_sharded():
with pytest.deprecated_call(match=r"The function `unwrap_lightning_module_sharded` is deprecated in v1.8.0"):
unwrap_lightning_module_sharded(BoringModel())