Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lightning_fabric/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Renamed `Strategy.reduce` to `Strategy.all_reduce` in all strategies ([#16370](https://github.com/Lightning-AI/lightning/issues/16370))

- 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))


## [1.9.0] - 2023-01-12

Expand Down
7 changes: 2 additions & 5 deletions src/lightning_fabric/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,8 @@ def _choose_strategy(self) -> Union[Strategy, str]:
device = "cpu"
# TODO: lazy initialized device, then here could be self._strategy_flag = "single_device"
return SingleDeviceStrategy(device=device) # type: ignore
if len(self._parallel_devices) > 1:
if _IS_INTERACTIVE:
return "ddp_fork"
return "ddp_spawn"

if len(self._parallel_devices) > 1 and _IS_INTERACTIVE:
return "ddp_fork"
return "ddp"

def _check_strategy_and_fallback(self) -> None:
Expand Down
10 changes: 10 additions & 0 deletions tests/tests_fabric/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
XLAStrategy,
)
from lightning_fabric.strategies.ddp import _DDP_FORK_ALIASES
from lightning_fabric.strategies.launchers.subprocess_script import _SubprocessScriptLauncher
from lightning_fabric.utilities.exceptions import MisconfigurationException


Expand Down Expand Up @@ -414,6 +415,15 @@ def test_validate_precision_type(precision):
_Connector(precision=precision)


def test_multi_device_default_strategy():
"""The default strategy when multiple devices are selected is "ddp" with the subprocess launcher."""
connector = _Connector(strategy=None, accelerator="cpu", devices=2)
assert isinstance(connector.accelerator, CPUAccelerator)
assert isinstance(connector.strategy, DDPStrategy)
assert connector.strategy._start_method == "popen"
assert isinstance(connector.strategy.launcher, _SubprocessScriptLauncher)


def test_strategy_choice_ddp_spawn_cpu():
connector = _Connector(strategy="ddp_spawn", accelerator="cpu", devices=2)
assert isinstance(connector.accelerator, CPUAccelerator)
Expand Down