Orchestrating your pipelines to run on VMs using SkyPilot.
The SkyPilot VM Orchestrator is an integration provided by ZenML that allows you to provision and manage virtual machines (VMs) on any cloud provider supported by the SkyPilot framework. This integration is designed to simplify the process of running machine learning workloads on the cloud, offering cost savings, high GPU availability, and managed execution, We recommend using the SkyPilot VM Orchestrator if you need access to GPUs for your workloads, but don't want to deal with the complexities of managing cloud infrastructure or expensive managed solutions.
This component is only meant to be used within the context of a remote ZenML deployment scenario. Usage with a local ZenML deployment may lead to unexpected behavior!
When to use it
You should use the SkyPilot VM Orchestrator if:
you want to maximize cost savings by leveraging spot VMs and auto-picking the cheapest VM/zone/region/cloud.
you want to ensure high GPU availability by provisioning VMs in all zones/regions/clouds you have access to.
you don't need a built-in UI of the orchestrator. (You can still use ZenML's Dashboard to view and monitor your pipelines/artifacts.)
you're not willing to maintain Kubernetes-based solutions or pay for managed solutions like Sagemaker.
How it works
The orchestrator leverages the SkyPilot framework to handle the provisioning and scaling of VMs. It automatically manages the process of launching VMs for your pipelines, with support for both on-demand and managed spot VMs. While you can select the VM type you want to use, the orchestrator also includes an optimizer that automatically selects the cheapest VM/zone/region/cloud for your workloads. Finally, the orchestrator includes an autostop feature that cleans up idle clusters, preventing unnecessary cloud costs.
You can configure the SkyPilot VM Orchestrator to use a specific VM type, and resources for each step of your pipeline can be configured individually. Read more about how to configure step-specific resources here.
The SkyPilot VM Orchestrator does not currently support the ability to schedule pipelines runs
All ZenML pipeline runs are executed using Docker containers within the VMs provisioned by the orchestrator. For that reason, you may need to configure your pipeline settings with docker_run_args=["--gpus=all"] to enable GPU support in the Docker container.
How to deploy it
You don't need to do anything special to deploy the SkyPilot VM Orchestrator. As the SkyPilot integration itself takes care of provisioning VMs, you can simply use the orchestrator as you would any other ZenML orchestrator. However, you will need to ensure that you have the appropriate permissions to provision VMs on your cloud provider of choice and to configure your SkyPilot orchestrator accordingly using the service connectors feature.
The SkyPilot VM Orchestrator currently only supports the AWS, GCP, and Azure cloud platforms.
How to use it
To use the SkyPilot VM Orchestrator, you need:
One of the SkyPilot integrations installed. You can install the SkyPilot integration for your cloud provider of choice using the following command:
# For AWSpipinstall"zenml[connectors-aws]"zenmlintegrationinstallawsskypilot_aws# for GCPpipinstall"zenml[connectors-gcp]"zenmlintegrationinstallgcpskypilot_gcp# for GCP# for Azurepipinstall"zenml[connectors-azure]"zenmlintegrationinstallazureskypilot_azure# for Azure
To provision VMs on AWS, your VM Orchestrator stack component needs to be configured to authenticate with AWS Service Connector. To configure the AWS Service Connector, you need to register a new service connector configured with AWS credentials that have at least the minimum permissions required by SkyPilot as documented here.
First, check that the AWS service connector type is available using the following command:
Next, configure a service connector using the CLI or the dashboard with the AWS credentials. For example, the following command uses the local AWS CLI credentials to auto-configure the service connector:
This will automatically configure the service connector with the appropriate credentials and permissions to provision VMs on AWS. You can then use the service connector to configure your registered VM Orchestrator stack component using the following command:
# Register the orchestratorzenmlorchestratorregister<ORCHESTRATOR_NAME>--flavorvm_aws# Connect the orchestrator to the service connectorzenmlorchestratorconnect<ORCHESTRATOR_NAME>--connectoraws-skypilot-vm# Register and activate a stack with the new orchestratorzenmlstackregister<STACK_NAME>-o<ORCHESTRATOR_NAME>...--set
We need first to install the SkyPilot integration for GCP and the GCP extra for ZenML, using the following two commands:
To provision VMs on GCP, your VM Orchestrator stack component needs to be configured to authenticate with GCP Service Connector
To configure the GCP Service Connector, you need to register a new service connector, but first let's check the available service connectors types using the following command:
For this example we will configure a service connector using the user-account auth method. But before we can do that, we need to login to GCP using the following command:
gcloudauthapplication-defaultlogin
This will open a browser window and ask you to login to your GCP account. Once you have logged in, you can register a new service connector using the following command:
# We want to use --auto-configure to automatically configure the service connector with the appropriate credentials and permissions to provision VMs on GCP.
zenmlservice-connectorregistergcp-skypilot-vm-tgcp--auth-methoduser-account--auto-configure# using generic resource type requires disabling the generation of temporary tokenszenmlservice-connectorupdategcp-skypilot-vm--generate_temporary_tokens=False
This will automatically configure the service connector with the appropriate credentials and permissions to provision VMs on GCP. You can then use the service connector to configure your registered VM Orchestrator stack component using the following commands:
# Register the orchestratorzenmlorchestratorregister<ORCHESTRATOR_NAME>--flavorvm_gcp# Connect the orchestrator to the service connectorzenmlorchestratorconnect<ORCHESTRATOR_NAME>--connectorgcp-skypilot-vm# Register and activate a stack with the new orchestratorzenmlstackregister<STACK_NAME>-o<ORCHESTRATOR_NAME>...--set
We need first to install the SkyPilot integration for Azure and the Azure extra for ZenML, using the following two commands
To provision VMs on Azure, your VM Orchestrator stack component needs to be configured to authenticate with Azure Service Connector
To configure the Azure Service Connector, you need to register a new service connector, but first let's check the available service connectors types using the following command:
This will automatically configure the service connector with the appropriate credentials and permissions to provision VMs on Azure. You can then use the service connector to configure your registered VM Orchestrator stack component using the following commands:
# Register the orchestratorzenmlorchestratorregister<ORCHESTRATOR_NAME>--flavorvm_azure# Connect the orchestrator to the service connectorzenmlorchestratorconnect<ORCHESTRATOR_NAME>--connectorazure-skypilot-vm# Register and activate a stack with the new orchestratorzenmlstackregister<STACK_NAME>-o<ORCHESTRATOR_NAME>...--set
Lambda Labs is a cloud provider that offers GPU instances for machine learning workloads. Unlike the major cloud providers, with Lambda Labs we don't need to configure a service connector to authenticate with the cloud provider. Instead, we can directly use API keys to authenticate with the Lambda Labs API.
zenmlintegrationinstallskypilot_lambda
Once the integration is installed, we can register the orchestrator with the following command:
# For more secure and recommended way, we will register the API key as a secretzenmlsecretcreatelambda_api_key--scopeuser--api_key=<VALUE_1># Register the orchestratorzenmlorchestratorregister<ORCHESTRATOR_NAME>--flavorvm_lambda--api_key={{lambda_api_key.api_key}}# Register and activate a stack with the new orchestratorzenmlstackregister<STACK_NAME>-o<ORCHESTRATOR_NAME>...--set
The Lambda Labs orchestrator does not support some of the features like job_recovery, disk_tier, image_id, zone, idle_minutes_to_autostop, disk_size, use_spot. It is recommended not to use these features with the Lambda Labs orchestrator and not to use step-specific settings.
While testing the orchestrator, we noticed that the Lambda Labs orchestrator does not support the down flag. This means the orchestrator will not automatically tear down the cluster after all jobs finish. We recommend manually tearing down the cluster after all jobs finish to avoid unnecessary costs.
We need first to install the SkyPilot integration for Kubernetes, using the following two commands:
zenmlintegrationinstallskypilot_kubernetes
To provision skypilot on kubernetes cluster, your orchestrator stack components needs to be configured to authenticate with a Service Connector. To configure the Service Connector, you need to register a new service connector configured with the appropriate credentials and permissions to access the K8s cluster. You can then use the service connector to configure your registered the Orchestrator stack component using the following command:
First, check that the Kubernetes service connector type is available using the following command:
Next, configure a service connector using the CLI or the dashboard with the AWS credentials. For example, the following command uses the local AWS CLI credentials to auto-configure the service connector:
This will automatically configure the service connector with the appropriate credentials and permissions to provision VMs on AWS. You can then use the service connector to configure your registered VM Orchestrator stack component using the following command:
# Register the orchestratorzenmlorchestratorregister<ORCHESTRATOR_NAME>--flavorsky_kubernetes# Connect the orchestrator to the service connectorzenmlorchestratorconnect<ORCHESTRATOR_NAME>--connectorkubernetes-skypilot# Register and activate a stack with the new orchestratorzenmlstackregister<STACK_NAME>-o<ORCHESTRATOR_NAME>...--set
Some of the features like job_recovery, disk_tier, image_id, zone, idle_minutes_to_autostop, disk_size, use_spot are not supported by the Kubernetes orchestrator. It is recommended not to use these features with the Kubernetes orchestrator and not to use step-specific settings.
Additional Configuration
For additional configuration of the Skypilot orchestrator, you can pass Settings depending on which cloud you are using which allows you to configure (among others) the following attributes:
instance_type: The instance type to use.
cpus: The number of CPUs required for the task. If a string, must be a string of the form '2' or '2+', where the + indicates that the task requires at least 2 CPUs.
memory: The amount of memory in GiB required. If a string, must be a string of the form '16' or '16+', where the + indicates that the task requires at least 16 GB of memory.
accelerators: The accelerators required. If a string, must be a string of the form 'V100' or 'V100:2', where the :2 indicates that the task requires 2 V100 GPUs. If a dict, must be a dict of the form {'V100': 2} or {'tpu-v2-8': 1}.
accelerator_args: Accelerator-specific arguments. For example, {'tpu_vm': True, 'runtime_version': 'tpu-vm-base'} for TPUs.
use_spot: Whether to use spot instances. If None, defaults to False.
job_recovery: The spot recovery strategy to use for the managed spot to recover the cluster from preemption. Read more about the available strategies here
region: The cloud region to use.
zone: The cloud zone to use within the region.
image_id: The image ID to use. If a string, must be a string of the image id from the cloud, such as AWS: 'ami-1234567890abcdef0', GCP: 'projects/my-project-id/global/images/my-image-name'; Or, a image tag provided by SkyPilot, such as AWS: 'skypilot:gpu-ubuntu-2004'. If a dict, must be a dict mapping from region to image ID.
disk_size: The size of the OS disk in GiB.
disk_tier: The disk performance tier to use. If None, defaults to 'medium'.
cluster_name: Name of the cluster to create/reuse. If None, auto-generate a name. SkyPilot uses term cluster to refer to a group or a single VM that are provisioned to execute the task. The cluster name is used to identify the cluster and to determine whether to reuse an existing cluster or create a new one.
retry_until_up: Whether to retry launching the cluster until it is up.
idle_minutes_to_autostop: Automatically stop the cluster after this many minutes of idleness, i.e., no running or pending jobs in the cluster's job queue. Idleness gets reset whenever setting-up/running/pending jobs are found in the job queue. Setting this flag is equivalent to running sky.launch(..., detach_run=True, ...) and then sky.autostop(idle_minutes=<minutes>). If not set, the cluster will not be autostopped.
down: Tear down the cluster after all jobs finish (successfully or abnormally). If idle_minutes_to_autostop is also set, the cluster will be torn down after the specified idle time. Note that if errors occur during provisioning/data syncing/setting up, the cluster will not be torn down for debugging purposes.
stream_logs: If True, show the logs in the terminal as they are generated while the cluster is running.
docker_run_args: Additional arguments to pass to the docker run command. For example, ['--gpus=all'] to use all GPUs available on the VM.
The following code snippets show how to configure the orchestrator settings for each cloud provider:
One of the key features of the SkyPilot VM Orchestrator is the ability to run each step of a pipeline on a separate VM with its own specific settings. This allows for fine-grained control over the resources allocated to each step, ensuring that each part of your pipeline has the necessary compute power while optimizing for cost and efficiency.
Configuring Step-Specific Resources
The SkyPilot VM Orchestrator allows you to configure resources for each step individually. This means you can specify different VM types, CPU and memory requirements, and even use spot instances for certain steps while using on-demand instances for others.
If no step-specific settings are specified, the orchestrator will use the resources specified in the orchestrator settings for each step and run the entire pipeline in one VM. If step-specific settings are specified, an orchestrator VM will be spun up first, which will subsequently spin out new VMs dependent on the step settings. You can disable this behavior by setting the disable_step_based_settings parameter to True in the orchestrator configuration, using the following command:
Here's an example of how to configure specific resources for a step for the AWS cloud:
from zenml.integrations.skypilot_aws.flavors.skypilot_orchestrator_aws_vm_flavor import SkypilotAWSOrchestratorSettings# Settings for a specific step that requires more resourceshigh_resource_settings =SkypilotAWSOrchestratorSettings( instance_type='t2.2xlarge', cpus=8, memory=32, use_spot=False, region='us-east-1',# ... other settings)@step(settings={"orchestrator": high_resource_settings})defmy_resource_intensive_step():# Step implementationpass
When configuring pipeline or step-specific resources, you can use the settings parameter to specifically target the orchestrator flavor you want to use orchestrator.STACK_COMPONENT_FLAVOR and not orchestrator component name orchestrator.STACK_COMPONENT_NAME. For example, if you want to configure resources for the vm_gcp flavor, you can use settings={"orchestrator": ...}.
By using the settings parameter, you can tailor the resources for each step according to its specific needs. This flexibility allows you to optimize your pipeline execution for both performance and cost.
Check out the SDK docs for a full list of available attributes and this docs page for more information on how to specify settings.