Skip to content

Commit 53bf714

Browse files
authored
Remove deperecated code in pl.utilities.meta (#16038)
1 parent ca75e49 commit 53bf714

File tree

3 files changed

+2
-92
lines changed

3 files changed

+2
-92
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
8383
- Removed deprecated `pytorch_lightning.profiler.base.BaseProfiler` in favor of `pytorch_lightning.profilers.profiler.Profiler` ([#15637](https://github.com/Lightning-AI/lightning/pull/15637))
8484

8585

86-
-
86+
- Removed deprecated code in `pytorch_lightning.utilities.meta` ([#16038](https://github.com/Lightning-AI/lightning/pull/16038))
8787

8888

8989
### Fixed

src/pytorch_lightning/utilities/meta.py

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,88 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from contextlib import contextmanager
15-
from typing import Any, Callable, Generator, Mapping, Optional, Set, Type, Union
14+
from typing import Mapping, Optional, Union
1615

1716
from lightning_utilities.core.imports import module_available
1817
from torch import Tensor
1918
from torch.nn import Module, Parameter
2019

21-
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
22-
23-
24-
def is_meta_init() -> bool:
25-
rank_zero_deprecation(
26-
"`pytorch_lightning.utilities.meta.is_meta_init` is deprecated in v1.8 and will be removed in v1.9."
27-
" The function has become a no-op."
28-
" Please check out the `torchdistx` project instead: https://github.com/pytorch/torchdistx"
29-
)
30-
return False
31-
32-
33-
def init_meta(module_fn: Callable[..., Module], *args: Any, **kwargs: Any) -> None:
34-
rank_zero_deprecation(
35-
"`pytorch_lightning.utilities.meta.init_meta` is deprecated in v1.8 and will be removed in v1.9."
36-
" The function has become a no-op."
37-
" Please check out the `torchdistx` project instead: https://github.com/pytorch/torchdistx"
38-
)
39-
40-
41-
def get_all_subclasses(cls: Type) -> Set[Type]:
42-
rank_zero_deprecation(
43-
"`pytorch_lightning.utilities.meta.get_all_subclasses` is deprecated in v1.8 and will be removed in v1.9."
44-
" Please copy its implementation if you have a use for it."
45-
)
46-
from lightning_utilities.core.inheritance import get_all_subclasses as new_get_all_subclasses
47-
48-
return new_get_all_subclasses(cls)
49-
50-
51-
def recursively_setattr(root_module: Any, prefix: str, materialized_module: Module) -> None:
52-
rank_zero_deprecation(
53-
"`pytorch_lightning.utilities.meta.recursively_setattr` is deprecated in v1.8 and will be removed in v1.9."
54-
" Please copy its implementation if you have a use for it."
55-
)
56-
*path, name = prefix.split(".")
57-
for p in path:
58-
root_module = getattr(root_module, p)
59-
60-
try:
61-
index = int(name)
62-
root_module[index] = materialized_module
63-
except ValueError:
64-
setattr(root_module, name, materialized_module)
65-
66-
67-
def materialize_module(root_module: Module) -> None:
68-
rank_zero_deprecation(
69-
"`pytorch_lightning.utilities.meta.materialize_module` is deprecated in v1.8 and will be removed in v1.9."
70-
" The function has become a no-op."
71-
" Please check out the `torchdistx` project instead: https://github.com/pytorch/torchdistx"
72-
)
73-
74-
75-
@contextmanager
76-
def init_meta_context() -> Generator:
77-
rank_zero_deprecation(
78-
"`pytorch_lightning.utilities.meta.init_meta_context` is deprecated in v1.8 and will be removed in v1.9."
79-
" The function has become a no-op."
80-
" Please check out the `torchdistx` project instead: https://github.com/pytorch/torchdistx"
81-
)
82-
yield
83-
84-
85-
def is_on_meta_device(module: Module) -> bool:
86-
rank_zero_deprecation(
87-
"`pytorch_lightning.utilities.meta.is_on_meta_device` is deprecated in v1.8 and will be removed in v1.9."
88-
" Please copy its implementation if you have a use for it."
89-
)
90-
try:
91-
param = next(module.parameters())
92-
return param.is_meta
93-
except StopIteration:
94-
return False
95-
9620

9721
def _is_deferred(module: Optional[Module]) -> bool:
9822
if module is None or not module_available("torchdistx.fake"):

tests/tests_pytorch/deprecated_api/test_remove_1-9.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,3 @@ def test_gpu_accelerator_deprecation_warning():
223223
def test_v1_9_0_deprecated_lightning_deepspeed_module():
224224
with pytest.deprecated_call(match=r"has been deprecated in v1.7.1 and will be removed in v1.9."):
225225
_ = LightningDeepSpeedModule(BoringModel(), 32)
226-
227-
228-
def test_meta_utility_deprecations():
229-
import pytorch_lightning.utilities.meta as meta
230-
231-
pytest.deprecated_call(meta.is_meta_init, match="is_meta_init.*removed in v1.9")
232-
pytest.deprecated_call(meta.init_meta, Mock(), match="init_meta.*removed in v1.9")
233-
pytest.deprecated_call(meta.get_all_subclasses, Mock, match="get_all_subclasses.*removed in v1.9")
234-
pytest.deprecated_call(meta.recursively_setattr, Mock(), "foo", 1, match="recursively_setattr.*removed in v1.9")
235-
pytest.deprecated_call(meta.materialize_module, Mock(), match="materialize_module.*removed in v1.9")
236-
with pytest.deprecated_call(match="init_meta_context.*removed in v1.9"):
237-
with meta.init_meta_context():
238-
pass
239-
pytest.deprecated_call(meta.is_on_meta_device, LightningModule(), match="is_on_meta_device.*removed in v1.9")

0 commit comments

Comments
 (0)