Skip to content

Commit 285cc53

Browse files
authored
Make subprocess launcher the default in Lite (#16388)
1 parent fa62112 commit 285cc53

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/lightning_fabric/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3535
- Merged the implementation of `DDPSpawnStrategy` into `DDPStrategy` and removed `DDPSpawnStrategy` ([#14952](https://github.com/Lightning-AI/lightning/issues/14952))
3636
- The dataloader wrapper returned from `.setup_dataloaders()` now calls `.set_epoch()` on the distributed sampler if one is used ([#16101](https://github.com/Lightning-AI/lightning/issues/16101))
3737
- Renamed `Strategy.reduce` to `Strategy.all_reduce` in all strategies ([#16370](https://github.com/Lightning-AI/lightning/issues/16370))
38+
- When using multiple devices, the strategy now defaults to "ddp" instead of "ddp_spawn" when none is set ([#16388](https://github.com/Lightning-AI/lightning/issues/16388))
3839

3940
### Removed
4041

src/lightning_fabric/connector.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,8 @@ def _choose_strategy(self) -> Union[Strategy, str]:
383383
device = "cpu"
384384
# TODO: lazy initialized device, then here could be self._strategy_flag = "single_device"
385385
return SingleDeviceStrategy(device=device) # type: ignore
386-
if len(self._parallel_devices) > 1:
387-
if _IS_INTERACTIVE:
388-
return "ddp_fork"
389-
return "ddp_spawn"
390-
386+
if len(self._parallel_devices) > 1 and _IS_INTERACTIVE:
387+
return "ddp_fork"
391388
return "ddp"
392389

393390
def _check_strategy_and_fallback(self) -> None:

tests/tests_fabric/test_connector.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
XLAStrategy,
4747
)
4848
from lightning_fabric.strategies.ddp import _DDP_FORK_ALIASES
49+
from lightning_fabric.strategies.launchers.subprocess_script import _SubprocessScriptLauncher
4950
from lightning_fabric.utilities.exceptions import MisconfigurationException
5051

5152

@@ -414,6 +415,15 @@ def test_validate_precision_type(precision):
414415
_Connector(precision=precision)
415416

416417

418+
def test_multi_device_default_strategy():
419+
"""The default strategy when multiple devices are selected is "ddp" with the subprocess launcher."""
420+
connector = _Connector(strategy=None, accelerator="cpu", devices=2)
421+
assert isinstance(connector.accelerator, CPUAccelerator)
422+
assert isinstance(connector.strategy, DDPStrategy)
423+
assert connector.strategy._start_method == "popen"
424+
assert isinstance(connector.strategy.launcher, _SubprocessScriptLauncher)
425+
426+
417427
def test_strategy_choice_ddp_spawn_cpu():
418428
connector = _Connector(strategy="ddp_spawn", accelerator="cpu", devices=2)
419429
assert isinstance(connector.accelerator, CPUAccelerator)

0 commit comments

Comments
 (0)