diff --git a/CHANGELOG.md b/CHANGELOG.md index 34eaf6e359257..9330b1e7fdfae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -264,6 +264,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated the use of `CheckpointConnector.hpc_load()` in favor of `CheckpointConnector.restore()` ([#7652](https://github.com/PyTorchLightning/pytorch-lightning/pull/7652)) +- Deprecated `DDPPlugin.task_idx` in favor of `DDPPlugin.local_rank` ([#8203](https://github.com/PyTorchLightning/pytorch-lightning/pull/8203)) + + - Deprecated the `Trainer.train_loop` property in favor of `Trainer.fit_loop` ([#8025](https://github.com/PyTorchLightning/pytorch-lightning/pull/8025)) diff --git a/pytorch_lightning/plugins/training_type/ddp.py b/pytorch_lightning/plugins/training_type/ddp.py index a24bfc34977cc..cf89a41b93408 100644 --- a/pytorch_lightning/plugins/training_type/ddp.py +++ b/pytorch_lightning/plugins/training_type/ddp.py @@ -94,7 +94,7 @@ def __init__( self.num_processes = len(self.parallel_devices) if self.parallel_devices is not None else 0 self._ddp_kwargs = kwargs self._has_spawned_children = False - self.task_idx = None + self._task_idx = None self._ddp_comm_state = ddp_comm_state self._ddp_comm_hook = ddp_comm_hook self._ddp_comm_wrapper = ddp_comm_wrapper @@ -128,6 +128,18 @@ def sync_batchnorm(self) -> bool: def sync_batchnorm(self, sync_batchnorm: bool) -> None: self._sync_batchnorm = sync_batchnorm + @property + def task_idx(self) -> Optional[int]: + rank_zero_deprecation( + f'`{self.__class__.__name__}.task_idx` is deprecated in v1.4 and will be removed in v1.6. Use ' + f'`{self.__class__.__name__}.local_rank` instead.' + ) + return self._task_idx + + @task_idx.setter + def task_idx(self, task_idx: int) -> None: + self._task_idx = task_idx + @property def distributed_sampler_kwargs(self): distributed_sampler_kwargs = dict(num_replicas=(self.num_nodes * self.num_processes), rank=self.global_rank) diff --git a/tests/deprecated_api/test_remove_1-6.py b/tests/deprecated_api/test_remove_1-6.py index e92af2f3926af..5fe6bb210dab7 100644 --- a/tests/deprecated_api/test_remove_1-6.py +++ b/tests/deprecated_api/test_remove_1-6.py @@ -243,3 +243,9 @@ def test_v1_6_0_rank_zero_warnings_moved(): rank_zero_warn('test') with pytest.deprecated_call(match='in v1.3.7 and will be removed in v1.6'): rank_zero_deprecation('test') + + +def test_v1_6_0_ddp_plugin_task_idx(): + plugin = DDPPlugin() + with pytest.deprecated_call(match='Use `DDPPlugin.local_rank` instead'): + _ = plugin.task_idx