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 multinode cloud component #15965

Merged
merged 8 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Fixed

-
- Fixed MultiNode Component to use separate cloud computes ([#15965](https://github.com/Lightning-AI/lightning/pull/15965))


## [1.8.4] - 2022-12-08
Expand Down Expand Up @@ -80,6 +80,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed detection of a Lightning App running in debug mode ([#15951](https://github.com/Lightning-AI/lightning/pull/15951))
- Fixed `ImportError` on Multinode if package not present ([#15963](https://github.com/Lightning-AI/lightning/pull/15963))


## [1.8.3] - 2022-11-22

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/lightning_app/components/multi_node/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(
*[
work_cls(
*work_args,
cloud_compute=cloud_compute,
cloud_compute=cloud_compute.clone(),
**work_kwargs,
parallel=True,
)
Expand Down
11 changes: 10 additions & 1 deletion src/lightning_app/utilities/packaging/cloud_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __post_init__(self) -> None:

# All `default` CloudCompute are identified in the same way.
if self._internal_id is None:
self._internal_id = "default" if self.name == "default" else uuid4().hex[:7]
self._internal_id = self._generate_id()

# Internal arguments for now.
self.preemptible = False
Expand Down Expand Up @@ -118,6 +118,15 @@ def id(self) -> Optional[str]:
def is_default(self) -> bool:
return self.name == "default"

def _generate_id(self):
return "default" if self.name == "default" else uuid4().hex[:7]

def clone(self):
new_dict = self.to_dict()
new_dict["_internal_id"] = self._generate_id()

return self.from_dict(new_dict)


def _verify_mount_root_dirs_are_unique(mounts: Union[None, Mount, List[Mount], Tuple[Mount]]) -> None:
if isinstance(mounts, (list, tuple, set)):
Expand Down
12 changes: 12 additions & 0 deletions tests/tests_app/components/multi_node/test_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from re import escape
from unittest import mock

import pytest
from tests_app.helpers.utils import no_warning_call
Expand All @@ -17,3 +18,14 @@ def run(self):

with no_warning_call(UserWarning, match=escape("You set MultiNode(num_nodes=1, ...)` but ")):
MultiNode(Work, num_nodes=1, cloud_compute=CloudCompute("gpu"))


@mock.patch("lightning_app.components.multi_node.base.is_running_in_cloud", mock.Mock(return_value=True))
def test_multi_node_separate_cloud_computes():
class Work(LightningWork):
def run(self):
pass

m = MultiNode(Work, num_nodes=2, cloud_compute=CloudCompute("gpu"))

assert len({w.cloud_compute._internal_id for w in m.ws}) == len(m.ws)
18 changes: 18 additions & 0 deletions tests/tests_app/utilities/packaging/test_cloud_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ def test_cloud_compute_with_non_unique_mount_root_dirs():

with pytest.raises(ValueError, match="Every Mount attached to a work must have a unique"):
CloudCompute("gpu", mounts=[mount_1, mount_2])


def test_cloud_compute_clone():
c1 = CloudCompute("gpu")
c2 = c1.clone()

assert isinstance(c2, CloudCompute)

c1_dict = c1.to_dict()
c2_dict = c2.to_dict()

assert len(c1_dict) == len(c2_dict)

for k in c1_dict.keys():
if k == "_internal_id":
assert c1_dict[k] != c2_dict[k]
else:
assert c1_dict[k] == c2_dict[k]