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

101 lines
4.1 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."""
from unittest import mock
import pytest
from pytorch_lightning import Trainer
from pytorch_lightning.core.mixins.device_dtype_mixin import DeviceDtypeModuleMixin
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 pytorch_lightning.strategies.utils import on_colab_kaggle
from pytorch_lightning.utilities.xla_device import inner_f, pl_multi_process, XLADeviceUtils
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())
def test_v1_10_deprecated_on_colab_kaggle_func():
with pytest.deprecated_call(match="The function `on_colab_kaggle` has been deprecated in v1.8.0"):
on_colab_kaggle()
def test_v1_10_deprecated_device_dtype_module_mixin():
class MyModule(DeviceDtypeModuleMixin):
pass
with pytest.deprecated_call(match="mixins.DeviceDtypeModuleMixin` has been deprecated in v1.8.0"):
MyModule()
def test_v1_10_deprecated_xla_device_utilities():
with pytest.deprecated_call(match="xla_device.inner_f` has been deprecated in v1.8.0"):
inner_f(mock.Mock(), mock.Mock())
with pytest.deprecated_call(match="xla_device.pl_multi_process` has been deprecated in v1.8.0"):
pl_multi_process(mock.Mock)
with pytest.deprecated_call(match="xla_device.XLADeviceUtils` has been deprecated in v1.8.0"):
XLADeviceUtils()
with pytest.deprecated_call(match="xla_device.XLADeviceUtils` has been deprecated in v1.8.0"):
XLADeviceUtils.xla_available()
with pytest.deprecated_call(match="xla_device.XLADeviceUtils` has been deprecated in v1.8.0"):
XLADeviceUtils.tpu_device_exists()