Skip to content

Commit 3b1e8ff

Browse files
safoinmeactions-usergithub-actions[bot]schustmi
authored
Lightening studio orchestrator (#2931)
* add lightening studio orchestrator * update * fix installing write zenml branch * update the orchestrator * fix pip install * fix req * update mypy * fix machine usage * update setting * update setting * fix deploy * fix get settings * add uv * add async * updated code * update env setting * remove breakpoints * fixes * run using a job * update * fix skypilot change * Auto-update of NLP template * update lightning * Auto-update of Starter template * update code * update lighning orchestrator * remove old wheel code * cleanup imports * fix async mode * update async mode * update lightning * format * chore: Upload code to main studio in lightning orchestrator entrypoint * chore: Update lightning orchestrator entrypoint to upload code to main studio * update ligning * update docs * update async * fix provisoning * add a cat logs for async * ready lightning studio * update based on reviews * update docs and toc and init * spell check * add screenshots * Optimised images with calibre/image-actions * Refactor code utils * Linting * More linting * Add mocked lib for api docs * Some small fixes --------- Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Michael Schuster <[email protected]>
1 parent bda5e88 commit 3b1e8ff

19 files changed

+1569
-56
lines changed
Loading
Loading
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
2+
---
3+
description: Orchestrating your pipelines to run on Lightning AI.
4+
---
5+
6+
7+
# Lightning AI Orchestrator
8+
9+
[Lightning AI Studio](https://lightning.ai/) is a platform that simplifies the development and deployment of AI applications. The Lightning AI orchestrator is an integration provided by ZenML that allows you to run your pipelines on Lightning AI's infrastructure, leveraging its scalable compute resources and managed environment.
10+
11+
12+
{% hint style="warning" %}
13+
This component is only meant to be used within the context of a [remote ZenML deployment scenario](../../getting-started/deploying-zenml/README.md). Usage with a local ZenML deployment may lead to unexpected behavior!
14+
{% endhint %}
15+
16+
17+
## When to use it
18+
19+
* You are looking for a fast and easy way to run your pipelines on GPU instances.
20+
21+
* you're already using Lightning AI for your machine learning projects.
22+
23+
* you want to leverage Lightning AI's managed infrastructure for running your pipelines.
24+
25+
* you're looking for a solution that simplifies the deployment and scaling of your ML workflows.
26+
27+
* you want to take advantage of Lightning AI's optimizations for machine learning workloads.
28+
29+
30+
## How to deploy it
31+
32+
To use the [Lightning AI Studio](https://lightning.ai/) orchestrator, you need to have a Lightning AI account and the necessary credentials. You don't need to deploy any additional infrastructure, as the orchestrator will use Lightning AI's managed resources.
33+
34+
35+
## How it works
36+
37+
The Lightning AI orchestrator is a ZenML orchestrator that runs your pipelines on Lightning AI's infrastructure. When you run a pipeline with the Lightning AI orchestrator, ZenML will archive your current ZenML repository and upload it to the Lightning AI studio. Once the code is archived, using `lightning-sdk`, ZenML will create a new stduio in Lightning AI and upload the code to it. Then ZenML runs list of commands via `studio.run()` to prepare for the pipeline run (e.g. installing dependencies, setting up the environment). Finally, ZenML will run the pipeline on Lightning AI's infrastructure.
38+
39+
* You can always use an already existing studio by specifying the `main_studio_name` in the `LightningOrchestratorSettings`.
40+
* The orchestartor supports a async mode, which means that the pipeline will be run in the background and you can check the status of the run in the ZenML Dashboard or the Lightning AI Studio.
41+
* You can specify a list of custom commands that will be executed before running the pipeline. This can be useful for installing dependencies or setting up the environment.
42+
* The orchestrator supports both CPU and GPU machine types. You can specify the machine type in the `LightningOrchestratorSettings`.
43+
44+
## How to use it
45+
46+
To use the Lightning AI orchestrator, you need:
47+
48+
* The ZenML `lightning` integration installed. If you haven't done so, run
49+
50+
```shell
51+
pip install lightning-sdk
52+
```
53+
54+
* A [remote artifact store](../artifact-stores/artifact-stores.md) as part of your stack.
55+
56+
57+
* [Lightning AI credentials](#lightning-ai-credentials)
58+
59+
60+
### Lightning AI credentials
61+
62+
* `LIGHTNING_USER_ID`: Your Lightning AI user ID
63+
64+
* `LIGHTNING_API_KEY`: Your Lightning AI API key
65+
66+
* `LIGHTNING_USERNAME`: Your Lightning AI username (optional)
67+
68+
* `LIGHTNING_TEAMSPACE`: Your Lightning AI teamspace (optional)
69+
70+
* `LIGHTNING_ORG`: Your Lightning AI organization (optional)
71+
72+
73+
Alternatively, you can configure these credentials when registering the orchestrator.
74+
75+
76+
We can then register the orchestrator and use it in our active stack:
77+
78+
```shell
79+
zenml orchestrator register lightning_orchestrator \
80+
--flavor=lightning \
81+
--user_id=<YOUR_LIGHTNING_USER_ID> \
82+
--api_key=<YOUR_LIGHTNING_API_KEY> \
83+
--username=<YOUR_LIGHTNING_USERNAME> \
84+
--teamspace=<YOUR_LIGHTNING_TEAMSPACE> \
85+
--organization=<YOUR_LIGHTNING_ORGANIZATION>
86+
87+
# Register and activate a stack with the new orchestrator
88+
zenml stack register lightning_stack -o lightning_orchestrator ... --set
89+
```
90+
91+
You can also configure the orchestrator at pipeline level, using the `orchestrator` parameter.
92+
93+
94+
```python
95+
from zenml.integrations.lightning.flavors.lightning_orchestrator_flavor import LightningOrchestratorSettings
96+
97+
98+
lightning_settings = LightningOrchestratorSettings(
99+
main_studio_name="my_studio",
100+
machine_type="cpu",
101+
async_mode=True,
102+
custom_commands=["pip install -r requirements.txt", "do something else"]
103+
)
104+
105+
@pipeline(
106+
settings={
107+
"orchestrator.lightning": lightning_settings
108+
}
109+
)
110+
def my_pipeline():
111+
...
112+
```
113+
114+
115+
{% hint style="info" %}
116+
ZenML will archive the current zenml repository (The code within the path where you run `zenml init`) and upload it to the Lightning AI studio.
117+
For this reason you need make sure that you are running `zenml init` in the same directory where you are running your pipeline.
118+
{% endhint %}
119+
120+
![Lightning AI studio VSCode](../../.gitbook/assets/lightning_studio_vscode.png)
121+
122+
{% hint style="info" %}
123+
The `custom_commands` attribute allows you to specify a list of shell commands that will be executed before running the pipeline. This can be useful for installing dependencies or setting up the environment, The commands will be executed in the root directory of the uploaded and extracted ZenML repository.
124+
{% endhint %}
125+
126+
127+
You can now run any ZenML pipeline using the Lightning AI orchestrator:
128+
129+
```shell
130+
python file_that_runs_a_zenml_pipeline.py
131+
```
132+
133+
134+
### Lightning AI UI
135+
136+
Lightning AI provides its own UI where you can monitor and manage your running applications, including the pipelines orchestrated by ZenML.
137+
![Lightning AI Studio](../../.gitbook/assets/lightning_studio_ui.png)
138+
139+
140+
For any runs executed on Lightning AI, you can get the URL to the Lightning AI UI in Python using the following code snippet:
141+
142+
```python
143+
from zenml.client import Client
144+
145+
pipeline_run = Client().get_pipeline_run("<PIPELINE_RUN_NAME>")
146+
orchestrator_url = pipeline_run.run_metadata["orchestrator_url"].value
147+
```
148+
149+
150+
### Additional configuration
151+
152+
For additional configuration of the Lightning AI orchestrator, you can pass `LightningOrchestratorSettings` which allows you to configure various aspects of the Lightning AI execution environment:
153+
154+
```python
155+
from zenml.integrations.lightning.flavors.lightning_orchestrator_flavor import LightningOrchestratorSettings
156+
157+
lightning_settings = LightningOrchestratorSettings(
158+
main_studio_name="my_studio",
159+
machine_type="cpu",
160+
async_mode=True,
161+
custom_commands=["pip install -r requirements.txt", "do something else"]
162+
)
163+
```
164+
165+
166+
167+
168+
These settings can then be specified on either pipeline-level or step-level:
169+
170+
```python
171+
# Either specify on pipeline-level
172+
@pipeline(
173+
settings={
174+
"orchestrator.lightning": lightning_settings
175+
}
176+
)
177+
def my_pipeline():
178+
...
179+
180+
# OR specify settings on step-level
181+
@step(
182+
settings={
183+
"orchestrator.lightning": lightning_settings
184+
}
185+
)
186+
def my_step():
187+
...
188+
```
189+
190+
Check out the [SDK docs](https://sdkdocs.zenml.io/latest/integration_code_docs/integrations-lightning/#zenml.integrations.lightning.flavors.lightning_orchestrator_flavor.LightningOrchestratorSettings) for a full list of available attributes and [this docs page](../../how-to/use-configuration-files/runtime-configuration.md) for more information on how to specify settings.
191+
192+
193+
To use GPUs with the Lightning AI orchestrator, you need to specify a GPU-enabled machine type in your settings:
194+
195+
```python
196+
lightning_settings = LightningOrchestratorSettings(
197+
machine_type="gpu", # or
198+
)
199+
```
200+
201+
202+
Make sure to check Lightning AI's documentation for the available GPU-enabled machine types and their specifications.
203+
204+
205+
<figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure>

docs/book/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
* [Airflow Orchestrator](component-guide/orchestrators/airflow.md)
204204
* [Skypilot VM Orchestrator](component-guide/orchestrators/skypilot-vm.md)
205205
* [HyperAI Orchestrator](component-guide/orchestrators/hyperai.md)
206+
* [Lightning AI Orchestrator](component-guide/orchestrators/lightning.md)
206207
* [Develop a custom orchestrator](component-guide/orchestrators/custom.md)
207208
* [🏪 Artifact Stores](component-guide/artifact-stores/artifact-stores.md)
208209
* [Local Artifact Store](component-guide/artifact-stores/local.md)

docs/mocked_libs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,6 @@
251251
"IPython.core",
252252
"IPython.core.display",
253253
"IPython.core.display_functions",
254-
"ipywidgets"
254+
"ipywidgets",
255+
"lightning_sdk"
255256
]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ module = [
464464
"huggingface_hub.*",
465465
"label_studio_sdk.*",
466466
"argilla.*",
467+
"lightning_sdk.*",
467468
"peewee.*",
468469
"prodigy.*",
469470
"prodigy.components.*",

src/zenml/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def handle_int_env_var(var: str, default: int = 0) -> int:
172172
)
173173
ENV_ZENML_IGNORE_FAILURE_HOOK = "ZENML_IGNORE_FAILURE_HOOK"
174174
ENV_ZENML_CUSTOM_SOURCE_ROOT = "ZENML_CUSTOM_SOURCE_ROOT"
175+
ENV_ZENML_WHEEL_PACKAGE_NAME = "ZENML_WHEEL_PACKAGE_NAME"
175176

176177
# ZenML Server environment variables
177178
ENV_ZENML_SERVER_PREFIX = "ZENML_SERVER_"

src/zenml/entrypoints/base_entrypoint_configuration.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def download_code_if_necessary(
219219
code_reference=code_reference
220220
)
221221
elif code_path := deployment.code_path:
222-
self.download_code_from_artifact_store(code_path=code_path)
222+
code_utils.download_code_from_artifact_store(code_path=code_path)
223223
else:
224224
raise RuntimeError(
225225
"Code download required but no code reference or path provided."
@@ -261,31 +261,6 @@ def download_code_from_code_repository(
261261
sys.path.insert(0, download_dir)
262262
os.chdir(download_dir)
263263

264-
def download_code_from_artifact_store(self, code_path: str) -> None:
265-
"""Download code from the artifact store.
266-
267-
Args:
268-
code_path: Path where the code is stored.
269-
"""
270-
logger.info(
271-
"Downloading code from artifact store path `%s`.", code_path
272-
)
273-
274-
# Do not remove this line, we need to instantiate the artifact store to
275-
# register the filesystem needed for the file download
276-
_ = Client().active_stack.artifact_store
277-
278-
extract_dir = os.path.abspath("code")
279-
os.makedirs(extract_dir)
280-
281-
code_utils.download_and_extract_code(
282-
code_path=code_path, extract_dir=extract_dir
283-
)
284-
285-
source_utils.set_custom_source_root(extract_dir)
286-
sys.path.insert(0, extract_dir)
287-
os.chdir(extract_dir)
288-
289264
def _should_download_code(
290265
self,
291266
deployment: "PipelineDeploymentResponse",

src/zenml/integrations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from zenml.integrations.great_expectations import ( # noqa
3737
GreatExpectationsIntegration,
3838
)
39+
from zenml.integrations.lightning import LightningIntegration # noqa
3940
from zenml.integrations.huggingface import HuggingfaceIntegration # noqa
4041
from zenml.integrations.hyperai import HyperAIIntegration # noqa
4142
from zenml.integrations.kaniko import KanikoIntegration # noqa

src/zenml/integrations/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@
7373
VERTEX = "vertex"
7474
XGBOOST = "xgboost"
7575
VAULT = "vault"
76+
LIGHTNING = "lightning"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) ZenML GmbH 2024. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
# or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
"""Initialization of the Lightning integration for ZenML."""
15+
16+
from typing import List, Type
17+
18+
from zenml.integrations.constants import (
19+
LIGHTNING,
20+
)
21+
from zenml.integrations.integration import Integration
22+
from zenml.stack import Flavor
23+
24+
LIGHTNING_ORCHESTRATOR_FLAVOR = "lightning"
25+
26+
27+
class LightningIntegration(Integration):
28+
"""Definition of Lightning Integration for ZenML."""
29+
30+
NAME = LIGHTNING
31+
REQUIREMENTS = ["lightning-sdk"]
32+
33+
@classmethod
34+
def flavors(cls) -> List[Type[Flavor]]:
35+
"""Declare the stack component flavors for the Lightning integration.
36+
37+
Returns:
38+
List of stack component flavors for this integration.
39+
"""
40+
from zenml.integrations.lightning.flavors import (
41+
LightningOrchestratorFlavor,
42+
)
43+
44+
return [
45+
LightningOrchestratorFlavor,
46+
]
47+
48+
LightningIntegration.check_installation()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) ZenML GmbH 2024. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
# or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
"""Lightning integration flavors."""
15+
16+
from zenml.integrations.lightning.flavors.lightning_orchestrator_flavor import (
17+
LightningOrchestratorConfig,
18+
LightningOrchestratorFlavor,
19+
)
20+
__all__ = [
21+
"LightningOrchestratorFlavor",
22+
"LightningOrchestratorConfig",
23+
]

0 commit comments

Comments
 (0)