Skip to content

Commit 2e537b7

Browse files
authored
Deprecate DDPPlugin.task_idx (#8203)
1 parent 87b1b86 commit 2e537b7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
264264
- Deprecated the use of `CheckpointConnector.hpc_load()` in favor of `CheckpointConnector.restore()` ([#7652](https://github.com/PyTorchLightning/pytorch-lightning/pull/7652))
265265

266266

267+
- Deprecated `DDPPlugin.task_idx` in favor of `DDPPlugin.local_rank` ([#8203](https://github.com/PyTorchLightning/pytorch-lightning/pull/8203))
268+
269+
267270
- Deprecated the `Trainer.train_loop` property in favor of `Trainer.fit_loop` ([#8025](https://github.com/PyTorchLightning/pytorch-lightning/pull/8025))
268271

269272

pytorch_lightning/plugins/training_type/ddp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(
9494
self.num_processes = len(self.parallel_devices) if self.parallel_devices is not None else 0
9595
self._ddp_kwargs = kwargs
9696
self._has_spawned_children = False
97-
self.task_idx = None
97+
self._task_idx = None
9898
self._ddp_comm_state = ddp_comm_state
9999
self._ddp_comm_hook = ddp_comm_hook
100100
self._ddp_comm_wrapper = ddp_comm_wrapper
@@ -128,6 +128,18 @@ def sync_batchnorm(self) -> bool:
128128
def sync_batchnorm(self, sync_batchnorm: bool) -> None:
129129
self._sync_batchnorm = sync_batchnorm
130130

131+
@property
132+
def task_idx(self) -> Optional[int]:
133+
rank_zero_deprecation(
134+
f'`{self.__class__.__name__}.task_idx` is deprecated in v1.4 and will be removed in v1.6. Use '
135+
f'`{self.__class__.__name__}.local_rank` instead.'
136+
)
137+
return self._task_idx
138+
139+
@task_idx.setter
140+
def task_idx(self, task_idx: int) -> None:
141+
self._task_idx = task_idx
142+
131143
@property
132144
def distributed_sampler_kwargs(self):
133145
distributed_sampler_kwargs = dict(num_replicas=(self.num_nodes * self.num_processes), rank=self.global_rank)

tests/deprecated_api/test_remove_1-6.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,9 @@ def test_v1_6_0_rank_zero_warnings_moved():
243243
rank_zero_warn('test')
244244
with pytest.deprecated_call(match='in v1.3.7 and will be removed in v1.6'):
245245
rank_zero_deprecation('test')
246+
247+
248+
def test_v1_6_0_ddp_plugin_task_idx():
249+
plugin = DDPPlugin()
250+
with pytest.deprecated_call(match='Use `DDPPlugin.local_rank` instead'):
251+
_ = plugin.task_idx

0 commit comments

Comments
 (0)