Skip to content

Commit

Permalink
Fix DDPStrategy import in app framework after #14952 (#16029)
Browse files Browse the repository at this point in the history
(cherry picked from commit fcd3195)
  • Loading branch information
awaelchli authored and Borda committed Dec 14, 2022
1 parent dc96640 commit 89e14c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lightning_app/components/multi_node/lite.py
Expand Up @@ -40,8 +40,8 @@ def run(
try:
pkg = importlib.import_module(pkg_name)
lites.append(pkg.LightningLite)
strategies.append(pkg.strategies.DDPSpawnShardedStrategy)
strategies.append(pkg.strategies.DDPSpawnStrategy)
strategies.append(pkg.strategies.DDPShardedStrategy)
strategies.append(pkg.strategies.DDPStrategy)
mps_accelerators.append(pkg.accelerators.MPSAccelerator)
except (ImportError, ModuleNotFoundError):
continue
Expand Down Expand Up @@ -81,7 +81,7 @@ def pre_fn(lite, *args, **kwargs):
strategy = "ddp"
elif strategy == "ddp_sharded_spawn":
strategy = "ddp_sharded"
elif isinstance(strategy, tuple(strategies)):
elif isinstance(strategy, tuple(strategies)) and strategy._start_method in ("spawn", "fork"):
raise ValueError("DDP Spawned strategies aren't supported yet.")

kwargs["strategy"] = strategy
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_app/components/multi_node/test_lite.py
Expand Up @@ -97,7 +97,7 @@ def test_trainer_run_executor_arguments_choices(args_given: dict, args_expected:
@pytest.mark.skipif(not module_available("lightning"), reason="Lightning not available")
def test_lite_run_executor_invalid_strategy_instances():
with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."):
_, _ = _get_args_after_tracer_injection(strategy=ll.strategies.DDPSpawnStrategy())
_, _ = _get_args_after_tracer_injection(strategy=ll.strategies.DDPStrategy(start_method="spawn"))

with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."):
_, _ = _get_args_after_tracer_injection(strategy=ll.strategies.DDPSpawnShardedStrategy())
_, _ = _get_args_after_tracer_injection(strategy=ll.strategies.DDPShardedStrategy(start_method="spawn"))

0 comments on commit 89e14c9

Please sign in to comment.