启动开发集群#

SkyPilot 使在 Kubernetes 或云虚拟机上的交互式开发变得容易。它可以帮助您

  1. 启动:通过一条命令快速获取带有 GPU 或其他资源的集群。

  2. 自动停止:在空闲一段时间后自动停止集群以节省成本。

  3. 连接:使用集群名称轻松连接到集群

启动#

要启动一个带有便宜 GPU 的开发集群

# Launch a cluster with 1 NVIDIA GPU and sync the local working directory to the
# cluster.
sky launch -c dev --gpus L4 --workdir .

这可以作为 Pod 在您的 Kubernetes 集群中启动,或者作为 VM 在任何云上启动。

Launch a cluster as a pod in Kubernetes

在 Kubernetes 中将集群作为 Pod 启动#

Launch a cluster as a VM on GCP

在 GCP 上将集群作为 VM 启动#

注意

使用 sky show-gpus 命令查看支持的 GPU。

自动停止#

SkyPilot 允许您在空闲一段时间后自动停止集群以节省成本。您可以通过一条命令设置自动停止时间

# Auto stop the cluster after 5 hours
sky autostop -i 300 dev

或者在启动时添加一个附加标志 -i

# Launch a cluster with auto stop after 5 hours
sky launch -c dev --gpus L4 --workdir . -i 300

有关自动停止的更多详情,请查看:自动停止和自动关闭。此功能旨在防止空闲集群产生不必要的成本,确保您的集群自动停止,无论是隔夜还是整个周末。

连接#

用户可以使用您选择的方法轻松连接到集群

SSH#

SkyPilot 会自动配置集群的 SSH 设置,以便用户可以使用集群名称连接到集群

ssh dev

VSCode#

交互式开发的常见用例是将本地 IDE 连接到远程集群并直接编辑集群上的代码。只需使用集群名称将 VSCode 连接到集群即可支持此功能

  1. 点击顶部栏,输入:> remote-ssh,然后选择 Remote-SSH: Connect Current Window to Host...

  2. 从主机列表中选择集群名称(例如,dev)。

  3. 打开文件夹:sky_workdir 并找到您的代码。

更多详情,请参考 VSCode 文档

Connect to the cluster with VSCode

Jupyter notebooks#

Jupyter notebooks 是进行交互式开发、调试和可视化的有用工具。

连接到机器并转发 jupyter notebook 使用的端口

ssh -L 8888:localhost:8888 dev

在集群内部,您可以运行以下命令启动 Jupyter 会话

pip install jupyter
jupyter notebook

在您的本地浏览器中,您现在应该能够访问 localhost:8888 并看到以下屏幕

Jupyter authentication window

输入密码或令牌,您将被引导至可以创建新 notebook 的页面。

Create a new Jupyter notebook

您可以使用 nvidia-smi 验证此 notebook 是否正在支持 GPU 的实例上运行。

nvidia-smi in notebook

GPU 节点是一个普通的 SkyPilot 集群,因此您可以在其上使用常用的 CLI 命令。例如,运行 sky down/stop 来终止或停止它,以及 sky exec 来执行任务。

SkyPilot 任务中的 Notebooks#

Jupyter notebooks 也可以在 SkyPilot 任务中使用,从而可以使用 SkyPilot 的全部功能,包括 挂载存储自动停止

以下 jupyter.yaml 是一个任务规范示例,可用于使用 SkyPilot 启动 notebooks。

# jupyter.yaml

name: jupyter

resources:
  accelerators: L4:1

file_mounts:
  /covid:
    source: s3://fah-public-data-covid19-cryptic-pockets
    mode: MOUNT

setup: |
  pip install --upgrade pip
  conda init bash
  conda create -n jupyter python=3.9 -y
  conda activate jupyter
  pip install jupyter

run: |
  cd ~/sky_workdir
  conda activate jupyter
  jupyter notebook --port 8888 &

启动支持 GPU 的 Jupyter notebook

sky launch -c jupyter jupyter.yaml

要在本地访问 notebook,请使用 SSH 端口转发。

ssh -L 8888:localhost:8888 jupyter

您可以验证此 notebook 是否可以访问挂载的存储桶。

accessing covid data from notebook

使用集群#

要查看使用集群的典型工作流程,请参考 快速入门