常见问题#
Git 和 GitHub#
如何在作业中克隆私有 GitHub 仓库?#
目前,SkyPilot 不支持秘密管理或 SSH 代理转发到您的 Sky 集群。您需要使用 file_mounts 同步您的 Github SSH 私钥到您的 Sky 集群。
# your_task.yaml
file_mounts:
~/.ssh/id_rsa: ~/.ssh/your-ssh-private-key
setup: |
chmod 600 ~/.ssh/id_rsa
git clone [email protected]:your-proj/your-repo.git
run: |
cd your-repo
git pull
如何确保工作目录的 .git
与托管 Spot 作业同步?#
目前,根据使用的命令,.git
是否同步存在差异
对于常规的
sky launch
,工作目录的.git
默认同步。对于托管作业
sky jobs launch
,工作目录的.git
默认排除。
在后一种情况下,为确保工作目录的 .git
与托管 Spot 作业同步,您可以明确添加文件挂载来同步它
workdir: .
file_mounts:
~/sky_workdir/.git: .git
如果您的作业使用某些实验跟踪工具,并且这些工具依赖于 .git
目录来跟踪代码更改,这会很有用。
文件挂载 (file_mounts
)#
如何让 SkyPilot 集群使用我的 Weights & Biases 凭据?#
在您的笔记本电脑上安装 wandb 库并通过 wandb login
登录您的账户。然后,在您的任务 yaml 文件中添加以下行
file_mounts:
~/.netrc: ~/.netrc
如何将额外文件挂载到克隆的仓库中?#
如果您想将额外文件挂载到一个将要通过 git clone
克隆的路径(无论是在 setup
还是 run
中),克隆将失败并提示目标路径非空
file_mounts:
~/code-repo/tmp.txt: ~/tmp.txt
setup: |
# Fail! Git will complain the target dir is not empty:
# fatal: destination path 'code-repo' already exists and is not an empty directory.
# This is because file_mounts are processed before `setup`.
git clone [email protected]:your-id/your-repo.git ~/code-repo/
为解决此问题,将文件挂载到不同的路径,然后创建软链接。例如
file_mounts:
/tmp/tmp.txt: ~/tmp.txt
setup: |
git clone [email protected]:your-id/your-repo.git ~/code-repo/
ln -s /tmp/tmp.txt ~/code-repo/
如何在不重新运行 setup
的情况下更新现有集群的 file_mounts
?#
如果您编辑了 file_mounts
部分(例如,添加了一些文件)并希望在现有集群上反映出来,运行 sky launch -c <cluster> ..
可以实现,但这会重新运行 setup
命令。
为了避免重新运行 setup
命令,在 sky launch
中传递 --no-setup
标志。
区域设置#
如何仅在部分区域(例如,仅欧洲)启动虚拟机?#
定义任务时,您可以使用 resources.any_of
字段指定要启动虚拟机的区域集。
例如,要仅在欧洲启动虚拟机(这有助于符合 GDPR 规定),您可以使用以下任务定义
resources:
# SkyPilot will perform cost optimization among the specified regions.
any_of:
# AWS:
- region: eu-central-1
- region: eu-west-1
- region: eu-west-2
- region: eu-west-3
- region: eu-north-1
# GCP:
- region: europe-central2
- region: europe-north1
- region: europe-southwest1
- region: europe-west1
- region: europe-west10
- region: europe-west12
- region: europe-west2
- region: europe-west3
- region: europe-west4
- region: europe-west6
- region: europe-west8
- region: europe-west9
# Or put in other clouds' Europe regions.
有关 resources.any_of
字段的更多详细信息,请参阅此处。
(高级) 如何让 SkyPilot 使用所有全球区域?#
默认情况下,SkyPilot 支持 AWS 上的大多数全球区域,但仅支持 GCP 和 Azure 上的美国区域。如果您想利用所有全球区域,请运行以下命令
version=$(python -c 'import sky; print(sky.clouds.service_catalog.constants.CATALOG_SCHEMA_VERSION)')
mkdir -p ~/.sky/catalogs/${version}
cd ~/.sky/catalogs/${version}
# GCP
pip install lxml
# Fetch U.S. regions for GCP
python -m sky.clouds.service_catalog.data_fetchers.fetch_gcp
# Fetch the specified zones for GCP
python -m sky.clouds.service_catalog.data_fetchers.fetch_gcp --zones northamerica-northeast1-a us-east1-b us-east1-c
# Fetch U.S. zones for GCP, excluding the specified zones
python -m sky.clouds.service_catalog.data_fetchers.fetch_gcp --exclude us-east1-a us-east1-b
# Fetch all regions for GCP
python -m sky.clouds.service_catalog.data_fetchers.fetch_gcp --all-regions
# Run in single-threaded mode. This is useful when multiple processes don't work well with the GCP client due to SSL issues.
python -m sky.clouds.service_catalog.data_fetchers.fetch_gcp --single-threaded
# Azure
# Fetch U.S. regions for Azure
python -m sky.clouds.service_catalog.data_fetchers.fetch_azure
# Fetch all regions for Azure
python -m sky.clouds.service_catalog.data_fetchers.fetch_azure --all-regions
# Run in single-threaded mode. This is useful when multiple processes don't work well with the Azure client due to SSL issues.
python -m sky.clouds.service_catalog.data_fetchers.fetch_azure --single-threaded
# Fetch the specified regions for Azure
python -m sky.clouds.service_catalog.data_fetchers.fetch_azure --regions japaneast australiaeast uksouth
# Fetch U.S. regions for Azure, excluding the specified regions
python -m sky.clouds.service_catalog.data_fetchers.fetch_azure --exclude centralus eastus
要让您的托管 Spot 作业可能使用所有全球区域,请使用 ssh sky-spot-controller-<hash>
登录 Spot 控制器(完整名称可在 sky status
中找到),并运行上述命令。
(高级) 如何编辑或更新 SkyPilot 使用的区域或定价信息?#
SkyPilot 将不同云资源类型的区域和定价信息存储在 CSV 文件中,这些文件被称为“服务目录”。这些目录缓存在 ~/.sky/catalogs/<schema-version>/
目录中。通过运行以下命令查看您的 schema 版本
python -c "from sky.clouds import service_catalog; print(service_catalog.CATALOG_SCHEMA_VERSION)"
您可以根据需要定制目录文件。例如,如果您有权访问 GCP 的特殊区域,请将数据添加到 ~/.sky/catalogs/<schema-version>/gcp.csv
中。此外,您可以通过删除 CSV 文件来更新特定云的目录(例如,rm ~/.sky/catalogs/<schema-version>/gcp.csv
)。SkyPilot 将在下次运行时自动下载最新的目录。
软件包安装#
无法在 SkyPilot 任务中导入 PyTorch。#
对于 PyTorch 安装,如果您使用默认的 SkyPilot 镜像(未传递 –image-id),pip install torch
应该可以工作。
但如果您使用自己的镜像,该镜像具有较旧的 NVIDIA 驱动程序(535.161.08 或更低),并且您安装了默认的 PyTorch,您可能会遇到以下错误
ImportError: /home/azureuser/miniconda3/lib/python3.10/site-packages/torch/lib/../../nvidia/cusparse/lib/libcusparse.so.12: undefined symbol: __nvJitLinkComplete_12_4, version libnvJitLink.so.12
您需要安装与您的 NVIDIA 驱动程序兼容的 PyTorch 版本,例如,pip install torch --index-url https://download.pytorch.org/whl/cu121
。
杂项#
如何使用 SkyPilot 任务定义启动 VS Code Tunnel?#
要使用 SkyPilot 任务定义启动 VS Code Tunnel,您可以使用以下任务定义
setup: |
sudo snap install --classic code
# if `snap` is not available, you can try the following commands instead:
# wget https://go.microsoft.com/fwlink/?LinkID=760868 -O vscode.deb
# sudo apt install ./vscode.deb -y
# rm vscode.deb
run: |
code tunnel --accept-server-license-terms
请注意,您需要使用您的 GitHub 账户进行身份验证才能启动 VS Code Tunnel。
升级 SkyPilot#
由于 SkyPilot 在后台运行 API 服务器,每当您升级 SkyPilot 时,都需要手动停止旧的 API 服务器才能使新版本生效。
sky api stop
从 SkyPilot<=0.8.1
迁移#
在 SkyPilot v0.8.1
之后,SkyPilot 已迁移到新的客户端-服务器架构,该架构更灵活、更强大。它还引入了异步执行模型,这可能会导致使用早期 SkyPilot SDK 的用户程序出现兼容性问题。
异步执行#
所有 SkyPilot SDK(日志相关函数除外:sky.tail_logs
、sky.jobs.tail_logs
、sky.serve.tail_logs
)现在都是异步的,它们返回一个请求 ID,可用于管理请求。
所需操作:将所有 SkyPilot SDK 函数调用包装在 sky.stream_and_get()
中,将使您的程序行为与之前基本相同
SkyPilot<=0.8.1
:
task = sky.Task(run="echo hello SkyPilot")
job_id, handle = sky.launch(task)
sky.tail_logs(job_id)
SkyPilot>0.8.1
:
task = sky.Task(run="echo hello SkyPilot")
job_id, handle = sky.stream_and_get(sky.launch(task))
sky.tail_logs(job_id)
移除的参数:detach_setup
/detach_run
#
sky.launch
中的 detach_setup
/detach_run
在 0.8.1
之后被移除,因为使用 Python SDK 时,setup 和 run 现在默认是分离的。如果您想查看提交到集群的作业的日志,可以如上所示明确调用 sky.tail_logs(job_id)
。