Skip to content

Commit 0459da7

Browse files
authored
Deprecate LightningLite (#16314)
1 parent c18a0ec commit 0459da7

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
105105
* Deprecated the `HorovodStrategy` class
106106

107107

108+
- Deprecated `pytorch_lightning.lite.LightningLite` in favor of `lightning.fabric.Fabric` ([#16314](https://github.com/Lightning-AI/lightning/pull/16314))
109+
110+
108111
### Removed
109112

110113
- Removed deprecated `pytorch_lightning.utilities.memory.get_gpu_memory_map` in favor of `pytorch_lightning.accelerators.cuda.get_nvidia_gpu_stats` ([#15617](https://github.com/Lightning-AI/lightning/pull/15617))

src/pytorch_lightning/lite/lite.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
class LightningLite(Fabric, ABC):
6060
"""Lite accelerates your PyTorch training or inference code with minimal changes required.
6161
62+
.. deprecated:: v1.9.0
63+
The `pytorch_lightning.lite.LightningLite` class was deprecated in v1.9.0 and will be renamed to
64+
`lightning.fabric.Fabric` in v2.0.0. It is no longer part of the pure `pytorch_lightning` package, and now
65+
lives in the main `lightning` package.
66+
6267
- Automatic placement of models and data onto the device.
6368
- Automatic support for mixed and double precision (smaller memory footprint).
6469
- Seamless switching between hardware (CPU, GPU, TPU) and distributed training strategies
@@ -102,6 +107,12 @@ def __init__(
102107
tpu_cores: Optional[Union[List[int], str, int]] = None,
103108
) -> None:
104109

110+
rank_zero_deprecation(
111+
"The `pytorch_lightning.lite.LightningLite` class was deprecated in v1.9.0 and will be renamed to"
112+
" `lightning.fabric.Fabric` in v2.0.0. It is no longer part of the pure `pytorch_lightning` package, and"
113+
" now lives in the main `lightning` package."
114+
)
115+
105116
if gpus is not None or tpu_cores is not None:
106117
devices, accelerator = _convert_deprecated_device_flags(
107118
accelerator=accelerator,

tests/tests_pytorch/deprecated_api/test_remove_2-0.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pytorch_lightning import Callback, Trainer
2121
from pytorch_lightning.cli import LightningCLI
2222
from pytorch_lightning.demos.boring_classes import BoringModel
23+
from pytorch_lightning.lite import LightningLite
2324
from tests_pytorch.callbacks.test_callbacks import OldStatefulCallback
2425
from tests_pytorch.helpers.runif import RunIf
2526

@@ -330,3 +331,8 @@ def test_v2_0_0_unsupported_on_init_start_end(callback_class, tmpdir):
330331
def test_lightningCLI_parser_init_params_deprecation_warning(name, value):
331332
with mock.patch("sys.argv", ["any.py"]), pytest.deprecated_call(match=f".*{name!r} init parameter is deprecated.*"):
332333
LightningCLI(BoringModel, run=False, **{name: value})
334+
335+
336+
def test_rename_lightning_lite():
337+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
338+
LightningLite()

tests/tests_pytorch/lite/test_lite.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,39 @@ def test_lite_convert_pl_plugins(cuda_count_2):
3131
"""
3232

3333
# defaults
34-
lite = EmptyLite()
34+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
35+
lite = EmptyLite()
3536
assert isinstance(lite._accelerator, LiteCPUAccelerator)
3637
assert isinstance(lite._precision, LitePrecision)
3738
assert isinstance(lite._strategy, LiteSingleDeviceStrategy)
3839

3940
# accelerator and strategy passed separately
40-
lite = EmptyLite(accelerator=PLCUDAAccelerator(), strategy=PLDDPStrategy())
41+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
42+
lite = EmptyLite(accelerator=PLCUDAAccelerator(), strategy=PLDDPStrategy())
4143
assert isinstance(lite._accelerator, PLCUDAAccelerator)
4244
assert isinstance(lite._precision, LitePrecision)
4345
assert isinstance(lite._strategy, LiteDDPStrategy)
4446

4547
# accelerator passed to strategy
46-
lite = EmptyLite(strategy=PLDDPStrategy(accelerator=PLCUDAAccelerator()))
48+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
49+
lite = EmptyLite(strategy=PLDDPStrategy(accelerator=PLCUDAAccelerator()))
4750
assert isinstance(lite._accelerator, PLCUDAAccelerator)
4851
assert isinstance(lite._strategy, LiteDDPStrategy)
4952

5053
# kwargs passed to strategy
51-
lite = EmptyLite(strategy=PLDDPStrategy(find_unused_parameters=False))
54+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
55+
lite = EmptyLite(strategy=PLDDPStrategy(find_unused_parameters=False))
5256
assert isinstance(lite._strategy, LiteDDPStrategy)
5357
assert lite._strategy._ddp_kwargs == dict(find_unused_parameters=False)
5458

5559
# plugins = instance
56-
lite = EmptyLite(plugins=PLDoublePrecisionPlugin())
60+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
61+
lite = EmptyLite(plugins=PLDoublePrecisionPlugin())
5762
assert isinstance(lite._precision, LiteDoublePrecision)
5863

5964
# plugins = list
60-
lite = EmptyLite(plugins=[PLDoublePrecisionPlugin(), SLURMEnvironment()], devices=2)
65+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
66+
lite = EmptyLite(plugins=[PLDoublePrecisionPlugin(), SLURMEnvironment()], devices=2)
6167
assert isinstance(lite._precision, LiteDoublePrecision)
6268
assert isinstance(lite._strategy.cluster_environment, SLURMEnvironment)
6369

@@ -66,13 +72,16 @@ def test_lite_convert_custom_precision():
6672
class CustomPrecision(PLPrecisionPlugin):
6773
pass
6874

69-
with pytest.raises(TypeError, match=escape("You passed an unsupported plugin as input to Lite(plugins=...)")):
75+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"), pytest.raises(
76+
TypeError, match=escape("You passed an unsupported plugin as input to Lite(plugins=...)")
77+
):
7078
EmptyLite(plugins=CustomPrecision())
7179

7280

7381
@RunIf(deepspeed=True)
7482
def test_lite_convert_pl_strategies_deepspeed():
75-
lite = EmptyLite(strategy=PLDeepSpeedStrategy(stage=2, initial_scale_power=32, loss_scale_window=500))
83+
with pytest.deprecated_call(match="will be renamed to `lightning.fabric.Fabric` in v2.0.0"):
84+
lite = EmptyLite(strategy=PLDeepSpeedStrategy(stage=2, initial_scale_power=32, loss_scale_window=500))
7685
assert isinstance(lite._strategy, LiteDeepSpeedStrategy)
7786
assert lite._strategy.config["zero_optimization"]["stage"] == 2
7887
assert lite._strategy.initial_scale_power == 32

0 commit comments

Comments
 (0)