Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix num_nodes not set for FSDPStrategy #17438

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/lightning/pytorch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Fixed issue where `Model.load_from_checkpoint("checkpoint.ckpt", map_location=map_location)` would always return model on CPU ([#17308](https://github.com/Lightning-AI/lightning/pull/17308))

- Fixed an issue that caused `num_nodes` not to be set correctly for `FSDPStrategy` ([#17438](https://github.com/Lightning-AI/lightning/pull/17438))


## [2.0.1.post0] - 2023-04-11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def _lazy_init_strategy(self) -> None:
else:
self.strategy.parallel_devices = self._parallel_devices
if hasattr(self.strategy, "num_nodes"):
self.strategy._num_nodes = self._num_nodes_flag
self.strategy.num_nodes = self._num_nodes_flag
if hasattr(self.strategy, "_layer_sync"):
self.strategy._layer_sync = self._layer_sync
if hasattr(self.strategy, "set_world_ranks"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,17 @@ def _mock_tpu_available(value):
assert isinstance(connector.strategy.cluster_environment, XLAEnvironment)
assert connector.strategy._start_method == "fork"
assert connector.strategy.launcher.is_interactive_compatible


@pytest.mark.parametrize(
"strategy",
[
"ddp",
"ddp_spawn",
pytest.param("deepspeed", marks=RunIf(deepspeed=True)),
pytest.param("fsdp", marks=RunIf(min_torch="1.12.0")),
],
)
def test_connector_sets_num_nodes(strategy, cuda_count_2):
trainer = Trainer(accelerator="cuda", strategy=strategy, devices=2, num_nodes=2)
assert trainer.strategy.num_nodes == 2