Skip to content

Commit d459a33

Browse files
authored
Merge branch 'master' into refactor/num_ipus
2 parents ea09db1 + 5d156f4 commit d459a33

File tree

7 files changed

+49
-48
lines changed

7 files changed

+49
-48
lines changed

.github/mergify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pull_request_rules:
5050
- name: Not ready yet
5151
conditions:
5252
- or:
53+
- label="has conflicts"
5354
- "#approved-reviews-by=0" # number of review approvals
5455
- "#changes-requested-reviews-by>=1" # no requested changes
5556
actions:

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
539539
- Deprecated `Trainer.ipus` in favor of `Trainer.num_devices` when IPU is used ([#12386](https://github.com/PyTorchLightning/pytorch-lightning/pull/12386))
540540

541541

542+
- Deprecated `Trainer.num_processes` in favor of `Trainer.num_devices` ([#12388](https://github.com/PyTorchLightning/pytorch-lightning/pull/12388))
543+
544+
542545
### Removed
543546

544547
- Removed deprecated parameter `method` in `pytorch_lightning.utilities.model_helpers.is_overridden` ([#10507](https://github.com/PyTorchLightning/pytorch-lightning/pull/10507))
@@ -729,12 +732,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
729732
- Removed `AcceleratorConnector.root_gpu` property ([#12262](https://github.com/PyTorchLightning/pytorch-lightning/pull/12262))
730733

731734

735+
- Removed `AcceleratorConnector.tpu_id` property ([#12387](https://github.com/PyTorchLightning/pytorch-lightning/pull/12387))
736+
737+
732738
- Removed `AcceleratorConnector.num_gpus` property ([#12384](https://github.com/PyTorchLightning/pytorch-lightning/pull/12384))
733739

734740

735741
- Removed `AcceleratorConnector.num_ipus` property ([#12386](https://github.com/PyTorchLightning/pytorch-lightning/pull/12386))
736742

737743

744+
- Removed `AcceleratorConnector.num_processes` property ([#12388](https://github.com/PyTorchLightning/pytorch-lightning/pull/12388))
745+
746+
738747
### Fixed
739748

740749
- Fixed an issue where `ModelCheckpoint` could delete older checkpoints when `dirpath` has changed during resumed training ([#12045](https://github.com/PyTorchLightning/pytorch-lightning/pull/12045))

pytorch_lightning/trainer/connectors/accelerator_connector.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,6 @@ def _lazy_init_strategy(self) -> None:
784784
def parallel_devices(self) -> List[Union[torch.device, int]]:
785785
return self._parallel_devices
786786

787-
@property
788-
def num_processes(self) -> int:
789-
return self.devices if self.devices is not None else 1
790-
791787
@property
792788
def devices(self) -> int:
793789
if isinstance(self.strategy, SingleDeviceStrategy):
@@ -809,6 +805,12 @@ def tpu_id(self) -> Optional[int]:
809805
return self._tpu_cores[0]
810806
return None
811807

808+
@property
809+
def num_ipus(self) -> int:
810+
if isinstance(self.accelerator, IPUAccelerator):
811+
return self.devices
812+
return 0
813+
812814
@property
813815
def gpus(self) -> Optional[Union[List[int], str, int]]:
814816
return self._gpus

pytorch_lightning/trainer/trainer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,11 @@ def num_devices(self) -> int:
20522052

20532053
@property
20542054
def num_processes(self) -> int:
2055-
return self._accelerator_connector.num_processes
2055+
rank_zero_deprecation(
2056+
"`Trainer.num_processes` is deprecated in v1.6 and will be removed in v1.8. "
2057+
"Please use `Trainer.num_devices` instead."
2058+
)
2059+
return self.num_devices
20562060

20572061
@property
20582062
def root_gpu(self) -> Optional[int]:

tests/accelerators/test_accelerator_connector.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def test_accelerator_cpu_with_devices(devices, plugin):
533533

534534
trainer = Trainer(accelerator="cpu", devices=devices)
535535

536-
assert trainer.num_processes == devices
536+
assert trainer.num_devices == devices
537537
assert isinstance(trainer.strategy, plugin)
538538
assert isinstance(trainer.accelerator, CPUAccelerator)
539539

@@ -545,7 +545,7 @@ def test_accelerator_cpu_with_num_processes_priority():
545545
with pytest.warns(UserWarning, match="The flag `devices=8` will be ignored,"):
546546
trainer = Trainer(accelerator="cpu", devices=8, num_processes=num_processes)
547547

548-
assert trainer.num_processes == num_processes
548+
assert trainer.num_devices == num_processes
549549

550550

551551
@RunIf(min_gpus=2)
@@ -583,7 +583,7 @@ def test_validate_accelerator_and_devices():
583583

584584
trainer = Trainer(accelerator="ddp_cpu", devices=2)
585585
assert isinstance(trainer.accelerator, CPUAccelerator)
586-
assert trainer.num_processes == 2
586+
assert trainer.num_devices == 2
587587

588588

589589
def test_set_devices_if_none_cpu():
@@ -962,7 +962,6 @@ def test_unsupported_ipu_choice(mock_ipu_acc_avail, monkeypatch):
962962
def test_devices_auto_choice_cpu(is_ipu_available_mock, is_tpu_available_mock, is_gpu_available_mock):
963963
trainer = Trainer(accelerator="auto", devices="auto")
964964
assert trainer.num_devices == 1
965-
assert trainer.num_processes == 1
966965

967966

968967
@mock.patch("torch.cuda.is_available", return_value=True)

tests/deprecated_api/test_remove_1-8.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,3 +1005,25 @@ def test_trainer_config_ipus(monkeypatch, trainer_kwargs, expected_ipus):
10051005
" Please use `Trainer.num_devices` instead."
10061006
):
10071007
trainer.ipus == expected_ipus
1008+
1009+
1010+
@pytest.mark.parametrize(
1011+
["trainer_kwargs", "expected_num_processes"],
1012+
[
1013+
({}, 1),
1014+
({"devices": 1}, 1),
1015+
({"devices": 4}, 4),
1016+
({"accelerator": "cpu", "devices": 1}, 0),
1017+
({"accelerator": "gpu", "devices": 4}, 4),
1018+
],
1019+
)
1020+
def test_trainer_num_processes(monkeypatch, trainer_kwargs, expected_num_processes):
1021+
if trainer_kwargs.get("accelerator") == "gpu":
1022+
monkeypatch.setattr(torch.cuda, "is_available", lambda: True)
1023+
monkeypatch.setattr(torch.cuda, "device_count", lambda: 16)
1024+
trainer = Trainer(**trainer_kwargs)
1025+
with pytest.deprecated_call(
1026+
match="`Trainer.num_processes` is deprecated in v1.6 and will be removed in v1.8. "
1027+
"Please use `Trainer.num_devices` instead."
1028+
):
1029+
trainer.num_processes == expected_num_processes

tests/models/test_tpu.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,11 @@ def test_dataloaders_passed_to_fit(tmpdir):
242242
assert trainer.state.finished, f"Training failed with {trainer.state}"
243243

244244

245-
@pytest.mark.parametrize(
246-
["tpu_cores", "expected_tpu_id"],
247-
[(1, None), (8, None), ([1], 1), ([8], 8)],
248-
)
249245
@RunIf(tpu=True)
250-
def test_tpu_id_to_be_as_expected(tpu_cores, expected_tpu_id):
251-
"""Test if trainer.tpu_id is set as expected."""
252-
assert Trainer(tpu_cores=tpu_cores)._accelerator_connector.tpu_id == expected_tpu_id
253-
254-
255-
def test_tpu_misconfiguration():
256-
"""Test if trainer.tpu_id is set as expected."""
246+
@pytest.mark.parametrize("tpu_cores", [[1, 8], "9, ", [9], [0], 2, 10])
247+
def test_tpu_misconfiguration(tpu_cores):
257248
with pytest.raises(MisconfigurationException, match="`tpu_cores` can only be"):
258-
Trainer(tpu_cores=[1, 8])
249+
Trainer(tpu_cores=tpu_cores)
259250

260251

261252
@pytest.mark.skipif(_TPU_AVAILABLE, reason="test requires missing TPU")
@@ -289,33 +280,6 @@ def test_broadcast(rank):
289280
xmp.spawn(test_broadcast, nprocs=8, start_method="fork")
290281

291282

292-
@pytest.mark.parametrize(
293-
["tpu_cores", "expected_tpu_id", "error_expected"],
294-
[
295-
(1, None, False),
296-
(8, None, False),
297-
([1], 1, False),
298-
([8], 8, False),
299-
("1,", 1, False),
300-
("1", None, False),
301-
("9, ", 9, True),
302-
([9], 9, True),
303-
([0], 0, True),
304-
(2, None, True),
305-
(10, None, True),
306-
],
307-
)
308-
@RunIf(tpu=True)
309-
@pl_multi_process_test
310-
def test_tpu_choice(tmpdir, tpu_cores, expected_tpu_id, error_expected):
311-
if error_expected:
312-
with pytest.raises(MisconfigurationException, match=r".*tpu_cores` can only be 1, 8 or [<1-8>]*"):
313-
Trainer(default_root_dir=tmpdir, tpu_cores=tpu_cores)
314-
else:
315-
trainer = Trainer(default_root_dir=tmpdir, tpu_cores=tpu_cores)
316-
assert trainer._accelerator_connector.tpu_id == expected_tpu_id
317-
318-
319283
@pytest.mark.parametrize(
320284
["cli_args", "expected"],
321285
[("--tpu_cores=8", {"tpu_cores": 8}), ("--tpu_cores=1,", {"tpu_cores": "1,"})],

0 commit comments

Comments
 (0)