diff --git a/docs/source-pytorch/api_references.rst b/docs/source-pytorch/api_references.rst index fe4b967da15ed..487628c3f67e2 100644 --- a/docs/source-pytorch/api_references.rst +++ b/docs/source-pytorch/api_references.rst @@ -314,7 +314,6 @@ utilities :toctree: api :nosignatures: - apply_func argparse cloud_io deepspeed diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 42e2bd97392af..664b2be8314e6 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -69,6 +69,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed the deprecated code in `pl.utilities.distributed` ([#16390](https://github.com/Lightning-AI/lightning/pull/16390)) +- Removed the deprecated code in `pl.utilities.apply_func` ([#16413](https://github.com/Lightning-AI/lightning/pull/16413)) + - Removed the deprecated code in `pl.utilities.xla_device` ([#16404](https://github.com/Lightning-AI/lightning/pull/16404)) - Removed the deprecated code in `pl.utilities.device_parser` ([#16412](https://github.com/Lightning-AI/lightning/pull/16412)) diff --git a/src/pytorch_lightning/utilities/apply_func.py b/src/pytorch_lightning/utilities/apply_func.py deleted file mode 100644 index 9f3d3fb25a434..0000000000000 --- a/src/pytorch_lightning/utilities/apply_func.py +++ /dev/null @@ -1,92 +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. -"""Utilities used for collections.""" - -from typing import Any - -import torch -from lightning_utilities.core.apply_func import apply_to_collection as new_apply_to_collection -from lightning_utilities.core.apply_func import apply_to_collections as new_apply_to_collections - -from lightning_fabric.utilities import move_data_to_device as new_move_data_to_device -from lightning_fabric.utilities.apply_func import _from_numpy -from lightning_fabric.utilities.apply_func import _TransferableDataType as NewTransferableDataType -from lightning_fabric.utilities.apply_func import convert_to_tensors as new_convert_to_tensors -from pytorch_lightning.utilities import rank_zero_deprecation -from pytorch_lightning.utilities.exceptions import MisconfigurationException - - -def apply_to_collection(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.apply_to_collection` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `lightning_utilities.core.apply_func.apply_to_collection` instead." - ) - try: - return new_apply_to_collection(*args, **kwargs) - except ValueError as e: - # upstream had to change the exception type - raise MisconfigurationException from e - - -def apply_to_collections(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.apply_to_collections` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `lightning_utilities.core.apply_func.apply_to_collections` instead." - ) - try: - return new_apply_to_collections(*args, **kwargs) - except ValueError as e: - # upstream had to change the exception type - raise MisconfigurationException from e - - -def convert_to_tensors(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.convert_to_tensors` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `lightning_fabric.utilities.apply_func.convert_to_tensors` instead." - ) - return new_convert_to_tensors(*args, **kwargs) - - -def from_numpy(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.from_numpy` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `torch.from_numpy().to()` instead." - ) - return _from_numpy(*args, **kwargs) - - -def move_data_to_device(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.move_data_to_device` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `lightning_fabric.utilities.apply_func.move_data_to_device` instead." - ) - return new_move_data_to_device(*args, **kwargs) - - -def to_dtype_tensor(*args: Any, **kwargs: Any) -> Any: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.to_dtype_tensor` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. Please use `torch.tensor` instead." - ) - return torch.tensor(*args, **kwargs) - - -class TransferableDataType(NewTransferableDataType): - def __init__(self) -> None: - rank_zero_deprecation( - "`pytorch_lightning.utilities.apply_func.TransferableDataType` has been deprecated in v1.8.0 and will be" - " removed in v2.0.0. This function is internal but you can copy over its implementation." - ) - super().__init__() diff --git a/tests/tests_pytorch/deprecated_api/test_remove_2-0.py b/tests/tests_pytorch/deprecated_api/test_remove_2-0.py index fc9f372b69268..3a7dc20a43718 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_2-0.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_2-0.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. """Test deprecated functionality which will be removed in v2.0.0.""" - -import numpy import pytest import torch from torch.utils.data import DataLoader @@ -22,15 +20,6 @@ from pytorch_lightning.core.mixins.device_dtype_mixin import DeviceDtypeModuleMixin from pytorch_lightning.demos.boring_classes import RandomDataset from pytorch_lightning.strategies.utils import on_colab_kaggle -from pytorch_lightning.utilities.apply_func import ( - apply_to_collection, - apply_to_collections, - convert_to_tensors, - from_numpy, - move_data_to_device, - to_dtype_tensor, - TransferableDataType, -) from pytorch_lightning.utilities.cloud_io import atomic_save, get_filesystem, load from pytorch_lightning.utilities.data import has_iterable_dataset, has_len from pytorch_lightning.utilities.optimizer import optimizer_to_device, optimizers_to_device @@ -50,32 +39,6 @@ class MyModule(DeviceDtypeModuleMixin): MyModule() -def test_v1_10_deprecated_apply_func_utilities(): - with pytest.deprecated_call(match="apply_func.apply_to_collection` has been deprecated in v1.8.0"): - apply_to_collection([], dtype=object, function=(lambda x: x)) - - with pytest.deprecated_call(match="apply_func.apply_to_collections` has been deprecated in v1.8.0"): - apply_to_collections([], [], dtype=object, function=(lambda x, y: x)) - - with pytest.deprecated_call(match="apply_func.convert_to_tensors` has been deprecated in v1.8.0"): - convert_to_tensors([], torch.device("cpu")) - - with pytest.deprecated_call(match="apply_func.from_numpy` has been deprecated in v1.8.0"): - from_numpy(numpy.zeros(2), torch.device("cpu")) - - with pytest.deprecated_call(match="apply_func.move_data_to_device` has been deprecated in v1.8.0"): - move_data_to_device(torch.tensor(2), torch.device("cpu")) - - with pytest.deprecated_call(match="apply_func.to_dtype_tensor` has been deprecated in v1.8.0"): - to_dtype_tensor(torch.tensor(2), dtype=torch.float32, device=torch.device("cpu")) - - class MyModule(TransferableDataType): - pass - - with pytest.deprecated_call(match="apply_func.TransferableDataType` has been deprecated in v1.8.0"): - MyModule() - - def test_v1_10_deprecated_cloud_io_utilities(tmpdir): with pytest.deprecated_call(match="cloud_io.atomic_save` has been deprecated in v1.8.0"): atomic_save({}, tmpdir / "atomic_save.ckpt")