From be0ae065967e5c06e860c88271a906551da475b9 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Wed, 7 Aug 2024 20:17:36 +0530 Subject: [PATCH] Add `ddp_find_unused_parameters_true` alias in Fabric's DDPStrategy (#20125) --- src/lightning/fabric/strategies/ddp.py | 7 +++++++ tests/tests_fabric/strategies/test_registry.py | 1 + tests/tests_fabric/test_cli.py | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lightning/fabric/strategies/ddp.py b/src/lightning/fabric/strategies/ddp.py index 0ec5df1a6b..c38780655c 100644 --- a/src/lightning/fabric/strategies/ddp.py +++ b/src/lightning/fabric/strategies/ddp.py @@ -200,6 +200,13 @@ class DDPStrategy(ParallelStrategy): description=f"DDP strategy with `start_method={start_method!r}`", start_method=start_method, ) + strategy_registry.register( + "ddp_find_unused_parameters_true", + cls, + description="Alias for `find_unused_parameters_true` and `start_method='popen'`", + find_unused_parameters=True, + start_method="popen", + ) def _setup_distributed(self) -> None: self._set_world_ranks() diff --git a/tests/tests_fabric/strategies/test_registry.py b/tests/tests_fabric/strategies/test_registry.py index 1865328cf5..8efd19541a 100644 --- a/tests/tests_fabric/strategies/test_registry.py +++ b/tests/tests_fabric/strategies/test_registry.py @@ -42,6 +42,7 @@ def test_strategy_registry_with_new_strategy(): def test_available_strategies_in_registry(): expected = { "ddp", + "ddp_find_unused_parameters_true", "deepspeed", "deepspeed_stage_1", "deepspeed_stage_1_offload", diff --git a/tests/tests_fabric/test_cli.py b/tests/tests_fabric/test_cli.py index 0e58acb3c7..a57f413ff6 100644 --- a/tests/tests_fabric/test_cli.py +++ b/tests/tests_fabric/test_cli.py @@ -71,8 +71,9 @@ def test_run_env_vars_strategy(_, strategy, monkeypatch, fake_script): def test_run_get_supported_strategies(): """Test to ensure that when new strategies get added, we must consider updating the list of supported ones in the CLI.""" - assert len(_get_supported_strategies()) == 7 + assert len(_get_supported_strategies()) == 8 assert "fsdp" in _get_supported_strategies() + assert "ddp_find_unused_parameters_true" in _get_supported_strategies() @pytest.mark.parametrize("strategy", ["ddp_spawn", "ddp_fork", "ddp_notebook", "deepspeed_stage_3_offload"])