|
| 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 | + |
| 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 | + |
| 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> |
0 commit comments