Skip to content

Commit e034cd3

Browse files
Remove add_to_queue and remove_from_queue from LightningModule (#13600)
Co-authored-by: Carlos Mocholí <[email protected]>
1 parent 9468866 commit e034cd3

File tree

8 files changed

+6
-112
lines changed

8 files changed

+6
-112
lines changed

docs/source-pytorch/common/lightning_module.rst

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,15 +1626,3 @@ on_after_batch_transfer
16261626

16271627
.. automethod:: pytorch_lightning.core.module.LightningModule.on_after_batch_transfer
16281628
:noindex:
1629-
1630-
add_to_queue
1631-
~~~~~~~~~~~~
1632-
1633-
.. automethod:: pytorch_lightning.core.module.LightningModule.add_to_queue
1634-
:noindex:
1635-
1636-
get_from_queue
1637-
~~~~~~~~~~~~~~
1638-
1639-
.. automethod:: pytorch_lightning.core.module.LightningModule.get_from_queue
1640-
:noindex:

src/pytorch_lightning/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
174174

175175
### Removed
176176

177+
- Removed the deprecated `LightningModule.add_to_queue` and `LightningModule.get_from_queue` method ([#13600](https://github.com/PyTorchLightning/pytorch-lightning/pull/13600))
178+
179+
177180
- Removed deprecated `pytorch_lightning.core.decorators.parameter_validation` from `decorators` ([#13514](https://github.com/Lightning-AI/lightning/pull/13514))
178181

179182

src/pytorch_lightning/core/module.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,28 +1955,6 @@ def use_amp(self, use_amp: bool) -> None:
19551955
)
19561956
self._use_amp = use_amp
19571957

1958-
def add_to_queue(self, queue: pl.strategies.launchers.spawn._FakeQueue) -> None:
1959-
"""Appends the :attr:`trainer.callback_metrics` dictionary to the given queue. To avoid issues with memory
1960-
sharing, we cast the data to numpy.
1961-
1962-
Args:
1963-
queue: the instance of the queue to append the data.
1964-
1965-
.. deprecated:: v1.5
1966-
This method was deprecated in v1.5 and will be removed in v1.7.
1967-
"""
1968-
1969-
def get_from_queue(self, queue: pl.strategies.launchers.spawn._FakeQueue) -> None:
1970-
"""Retrieve the :attr:`trainer.callback_metrics` dictionary from the given queue. To preserve consistency,
1971-
we cast back the data to ``torch.Tensor``.
1972-
1973-
Args:
1974-
queue: the instance of the queue from where to get the data.
1975-
1976-
.. deprecated:: v1.5
1977-
This method was deprecated in v1.5 and will be removed in v1.7.
1978-
"""
1979-
19801958
@contextmanager
19811959
def _prevent_trainer_and_dataloaders_deepcopy(self) -> None:
19821960
self._should_prevent_trainer_and_dataloaders_deepcopy = True

src/pytorch_lightning/strategies/launchers/spawn.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from pytorch_lightning.strategies.strategy import Strategy
2727
from pytorch_lightning.trainer.states import TrainerFn, TrainerState
2828
from pytorch_lightning.utilities.apply_func import apply_to_collection, move_data_to_device
29-
from pytorch_lightning.utilities.model_helpers import is_overridden
3029
from pytorch_lightning.utilities.rank_zero import rank_zero_debug
3130
from pytorch_lightning.utilities.types import _PATH
3231

@@ -122,10 +121,6 @@ def _recover_results_in_main_process(self, spawn_output: "_SpawnOutput", trainer
122121
trainer.state = spawn_output.trainer_state
123122

124123
# get the `callback_metrics` and set it to the trainer
125-
if is_overridden("get_from_queue", trainer.lightning_module):
126-
# only in case the user does not override it.
127-
# TODO: Remove the if in v1.7
128-
trainer.lightning_module.get_from_queue(spawn_output.extra)
129124
self.get_from_queue(trainer, spawn_output.extra)
130125

131126
def _collect_rank_zero_results(self, trainer: "pl.Trainer", results: Any) -> Optional["_SpawnOutput"]:
@@ -151,9 +146,6 @@ def _collect_rank_zero_results(self, trainer: "pl.Trainer", results: Any) -> Opt
151146

152147
# adds the `callback_metrics` to the queue
153148
extra = _FakeQueue()
154-
if is_overridden("add_to_queue", trainer.lightning_module):
155-
# TODO: Remove the if in v1.7
156-
trainer.lightning_module.add_to_queue(extra)
157149
self.add_to_queue(trainer, extra)
158150

159151
return _SpawnOutput(best_model_path, weights_path, trainer.state, results, extra)

src/pytorch_lightning/strategies/launchers/xla_spawn.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from pytorch_lightning.trainer.states import TrainerFn
2424
from pytorch_lightning.utilities import _TPU_AVAILABLE
2525
from pytorch_lightning.utilities.apply_func import move_data_to_device
26-
from pytorch_lightning.utilities.model_helpers import is_overridden
2726
from pytorch_lightning.utilities.rank_zero import rank_zero_debug
2827

2928
if _TPU_AVAILABLE:
@@ -136,9 +135,6 @@ def _collect_rank_zero_results(self, trainer: "pl.Trainer", results: Any) -> Opt
136135

137136
# adds the `callback_metrics` to the queue
138137
extra = _FakeQueue()
139-
if is_overridden("add_to_queue", trainer.lightning_module):
140-
# TODO: Remove the if in v1.7
141-
trainer.lightning_module.add_to_queue(extra)
142138
self.add_to_queue(trainer, extra)
143139

144140
return _SpawnOutput(best_model_path, weights_path, trainer.state, results, extra)

src/pytorch_lightning/trainer/configuration_validator.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def verify_loop_configurations(trainer: "pl.Trainer") -> None:
4646
__verify_eval_loop_configuration(trainer, model, "predict")
4747

4848
__verify_dp_batch_transfer_support(trainer, model)
49-
_check_add_get_queue(model)
5049
# TODO: Delete _check_on_post_move_to_device in v1.7
5150
_check_on_post_move_to_device(model)
5251
_check_deprecated_callback_hooks(trainer)
@@ -218,23 +217,6 @@ def __check_training_step_requires_dataloader_iter(model: "pl.LightningModule")
218217
)
219218

220219

221-
def _check_add_get_queue(model: "pl.LightningModule") -> None:
222-
r"""
223-
Checks if add_to_queue or get_from_queue is overridden and sends a deprecation warning.
224-
225-
Args:
226-
model: The lightning module
227-
"""
228-
if is_overridden("add_to_queue", model):
229-
rank_zero_deprecation(
230-
"The `LightningModule.add_to_queue` method was deprecated in v1.5 and will be removed in v1.7."
231-
)
232-
if is_overridden("get_from_queue", model):
233-
rank_zero_deprecation(
234-
"The `LightningModule.get_from_queue` method was deprecated in v1.5 and will be removed in v1.7."
235-
)
236-
237-
238220
# TODO: Delete _check_on_hpc_hooks in v1.8
239221
def _check_on_hpc_hooks(model: "pl.LightningModule") -> None:
240222
if is_overridden("on_hpc_save", model):

tests/tests_pytorch/deprecated_api/test_remove_1-7.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,6 @@
3434
from tests_pytorch.plugins.environments.test_lsf_environment import _make_rankfile
3535

3636

37-
class BoringCallbackDDPSpawnModel(BoringModel):
38-
def add_to_queue(self, queue):
39-
...
40-
41-
def get_from_queue(self, queue):
42-
...
43-
44-
45-
def test_v1_7_0_deprecate_add_get_queue(tmpdir):
46-
model = BoringCallbackDDPSpawnModel()
47-
trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True)
48-
49-
with pytest.deprecated_call(match=r"`LightningModule.add_to_queue` method was deprecated in v1.5"):
50-
trainer.fit(model)
51-
52-
with pytest.deprecated_call(match=r"`LightningModule.get_from_queue` method was deprecated in v1.5"):
53-
trainer.fit(model)
54-
55-
5637
def test_v1_7_0_deprecate_lightning_distributed(tmpdir):
5738
with pytest.deprecated_call(match="LightningDistributed is deprecated in v1.5 and will be removed in v1.7."):
5839
from pytorch_lightning.distributed.dist import LightningDistributed

tests/tests_pytorch/strategies/test_ddp_spawn_strategy.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ def validation_step(self, batch, batch_idx):
4444
self.log(self.name, self.val)
4545
return super().validation_step(batch, batch_idx)
4646

47-
def add_to_queue(self, queue) -> None:
48-
queue.put("test_val")
49-
return super().add_to_queue(queue)
50-
51-
def get_from_queue(self, queue) -> None:
52-
self.test_val = queue.get()
53-
return super().get_from_queue(queue)
54-
5547

5648
@RunIf(skip_windows=True)
5749
def test_ddp_cpu():
@@ -67,31 +59,13 @@ def test_ddp_cpu():
6759
trainer.fit(model)
6860

6961

70-
@RunIf(min_cuda_gpus=2)
71-
def test_ddp_spawn_extra_parameters(tmpdir):
72-
"""Tests if device is set correctly when training for DDPSpawnStrategy and tests add_to_queue/get_from_queue
73-
with Lightning Module (deprecated way)."""
74-
trainer = Trainer(default_root_dir=tmpdir, fast_dev_run=True, accelerator="gpu", devices=2, strategy="ddp_spawn")
75-
76-
assert isinstance(trainer.strategy, DDPSpawnStrategy)
77-
assert trainer.strategy.root_device == torch.device("cuda:0")
78-
79-
val: float = 1.0
80-
val_name: str = "val_acc"
81-
model = BoringCallbackDDPSpawnModel(val_name, val)
82-
dm = BoringDataModule()
83-
trainer.fit(model, datamodule=dm)
84-
assert trainer.callback_metrics[val_name] == torch.tensor(val)
85-
assert model.test_val == "test_val"
86-
87-
8862
class CustomSpawnLauncher(_SpawnLauncher):
8963
def add_to_queue(self, trainer, queue) -> None:
90-
queue.put("new_test_val")
64+
queue.put("test_val")
9165
return super().add_to_queue(trainer, queue)
9266

9367
def get_from_queue(self, trainer: Trainer, queue) -> None:
94-
trainer.strategy.new_test_val = queue.get()
68+
trainer.strategy.test_val = queue.get()
9569
return super().get_from_queue(trainer, queue)
9670

9771

@@ -115,7 +89,7 @@ def test_ddp_spawn_add_get_queue(tmpdir):
11589
dm = BoringDataModule()
11690
trainer.fit(model, datamodule=dm)
11791
assert trainer.callback_metrics[val_name] == torch.tensor(val)
118-
assert ddp_spawn_strategy.new_test_val == "new_test_val"
92+
assert ddp_spawn_strategy.test_val == "test_val"
11993

12094

12195
class BoringModelDDP(BoringModel):

0 commit comments

Comments
 (0)