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

Validate the combination of CloudCompute and BuildConfig #14929

Merged
merged 16 commits into from
Nov 13, 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
4 changes: 4 additions & 0 deletions src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Add `--secret` option to CLI to allow binding Secrets to app environment variables when running in the cloud ([#14612](https://github.com/Lightning-AI/lightning/pull/14612))


- Added a friendly error message when attempting to run the default cloud compute with a custom base image configured ([#14929](https://github.com/Lightning-AI/lightning/pull/14929))



### Changed

-
Expand Down
11 changes: 11 additions & 0 deletions src/lightning_app/runners/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from lightning_cloud.openapi.rest import ApiException

from lightning_app import LightningWork
from lightning_app.core.app import LightningApp
from lightning_app.core.constants import CLOUD_UPLOAD_WARNING, DISABLE_DEPENDENCY_CACHE
from lightning_app.runners.backends.cloud import CloudBackend
Expand Down Expand Up @@ -112,6 +113,7 @@ def dispatch(
for flow in self.app.flows:
for work in flow.works(recurse=False):
work_requirements = "\n".join(work.cloud_build_config.requirements)
_validate_build_spec_and_compute(work)
build_spec = V1BuildSpec(
commands=work.cloud_build_config.build_commands(),
python_dependencies=V1PythonDependencyInfo(
Expand Down Expand Up @@ -361,3 +363,12 @@ def _project_has_sufficient_credits(self, project: V1Membership, app: Optional[L
balance = 0 # value is missing in some tests

return balance >= 1


def _validate_build_spec_and_compute(work: LightningWork) -> None:
if work.cloud_build_config.image is not None and work.cloud_compute.name == "default":
raise ValueError(
f"You requested a custom base image for the Work with name '{work.name}', but custom images are currently"
" not supported on the default cloud compute instance. Please choose a different configuration, for example"
" `CloudCompute('cpu-medium')`."
)
23 changes: 22 additions & 1 deletion tests/tests_app/runners/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
V1Work,
)

from lightning_app import LightningApp, LightningWork
from lightning_app import BuildConfig, CloudCompute, LightningApp, LightningFlow, LightningWork
from lightning_app.runners import backends, cloud
from lightning_app.runners.cloud import _validate_build_spec_and_compute
from lightning_app.storage import Drive
from lightning_app.utilities.cloud import _get_project
from lightning_app.utilities.dependency_caching import get_hash
Expand Down Expand Up @@ -702,3 +703,23 @@ def test_project_has_sufficient_credits():
for balance, result in credits_and_test_value:
project = V1Membership(name="test-project1", project_id="test-project-id1", balance=balance)
assert cloud_runtime._project_has_sufficient_credits(project) is result


def test_incompatible_cloud_compute_and_build_config():
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
"""Test that an exception is raised when a build config has a custom image defined, but the cloud compute is
the default.

This combination is not supported by the platform.
"""

class Work(LightningWork):
def __init__(self):
super().__init__()
self.cloud_compute = CloudCompute(name="default")
self.cloud_build_config = BuildConfig(image="custom")

def run(self):
pass

with pytest.raises(ValueError, match="You requested a custom base image for the Work with name"):
_validate_build_spec_and_compute(Work())