云对象存储#
SkyPilot 任务可以从云对象存储中的存储桶访问数据,例如 AWS S3、Google Cloud Storage (GCS)、Cloudflare R2、OCI Object Storage 或 IBM COS。
存储桶在远程虚拟机上的本地路径中提供给每个任务,因此任务可以像访问本地文件一样访问存储桶对象。
用法#
对象存储通过在SkyPilot任务中的file_mounts字段来指定。
要访问现有的存储桶(例如,通过云 CLI 或其他工具创建的),请指定 source。
# Mount an existing S3 bucket
file_mounts:
/my_data:
source: s3://my-bucket/ # or gs://, https://<azure_storage_account>.blob.core.windows.net/<container>, r2://, cos://<region>/<bucket>, oci://<bucket_name>
mode: MOUNT # Optional: either MOUNT or COPY. Defaults to MOUNT.
这将挂载位于s3://my-bucket/的存储桶内容到远程虚拟机的/my_data目录。
要创建一个空的存储桶,请指定 name。
# Create an empty gcs bucket
file_mounts:
/my_data:
name: my-sky-bucket
store: gcs # Optional: either of s3, gcs, azure, r2, ibm, oci
SkyPilot 将创建一个名为 my-sky-bucket 的空 GCS 存储桶,并将其挂载到 /my_data。
此存储桶可用于直接将检查点、日志或其他输出写入云端。
注意
name 必须是唯一的才能创建一个新的存储桶。如果存储桶已经存在并且是由 SkyPilot 创建的,SkyPilot 将获取并重用该存储桶,因此可以在多次运行中重复使用相同的 YAML。
要创建一个新的存储桶,将本地文件上传到此存储桶并将其附加到任务中,指定 name 和 source,其中 source 是本地路径。
# Create a new S3 bucket and upload local data
file_mounts:
/my_data:
name: my-sky-bucket
source: ~/dataset # Optional: path to local data to upload to the bucket
store: s3 # Optional: either of s3, gcs, azure, r2, ibm, oci
mode: MOUNT # Optional: either MOUNT or COPY. Defaults to MOUNT.
SkyPilot 将创建一个名为 my-sky-bucket 的 S3 存储桶,并将 ~/dataset 的内容上传到其中。然后,该存储桶将被挂载到 /my_data,您的数据将对任务可用。
如果省略了store,SkyPilot 将使用与任务云相同的云提供商。
注意
如果存储桶已经存在并且是由SkyPilot创建的,SkyPilot将获取并重用该存储桶。如果source处的任何文件发生了变化,SkyPilot将在任务开始时自动将新文件同步到存储桶中。
你可以在storage_demo.yaml中找到更详细的使用示例。
存储模式#
云存储可以在MOUNT模式或COPY模式下使用。
MOUNT 模式:存储桶直接“挂载”到远程虚拟机。即,文件在任务访问时进行流式传输,所有写入都会复制到远程存储桶。任何写入也会出现在挂载同一存储桶的其他虚拟机上。这是默认模式。
COPY 模式:文件会预先获取并缓存在本地磁盘上。写入操作仅影响本地副本,不会流回存储桶。
选择存储模式#
在MOUNT和COPY模式之间选择取决于工作负载、其性能要求和数据的大小。
|
|
|
|---|---|---|
最适合 |
写入任务输出(例如,检查点、日志);读取无法存储在磁盘上的非常大的数据。 |
高性能只读访问适合磁盘存储的数据集。 |
性能 |
🟡 读取/写入文件较慢。快速配置。 |
✅ 快速文件访问。初始配置时较慢。 |
写入存储桶 |
🟡 大多数写操作 [1] 都支持。 |
❌ 不支持。只读。 |
磁盘大小 |
✅ 无磁盘大小要求 [2] 。 |
🟡 虚拟机磁盘大小必须大于存储桶的大小。 |
注意
在底层,MOUNT 模式使用 FUSE
为附加的存储桶提供接近开放的一致性模型。这意味着在文件上调用
close() 将会将整个文件上传到存储桶。
任何后续的读取都将看到最新的数据。
注意
SkyPilot 在附加存储桶时不保证文件权限的保留。您可能需要在任务执行期间设置文件权限。
注意
符号链接在file_mounts中的处理方式取决于是否使用了存储桶。
对于存储桶挂载,符号链接不会被复制到远程。
对于直接通过rsync同步到虚拟机的本地file_mounts,符号链接会被直接复制,而不是它们的目标数据。
目标必须单独挂载,否则符号链接可能会失效。
常见模式#
读取数据集#
如果你的数据集已经在云存储桶中,你可以直接将其挂载到你的远程虚拟机。
# Mount an existing S3 bucket containing a dataset
file_mounts:
/my_data:
source: s3://my-dataset/
mode: MOUNT
提示
如果你的数据集可以放在虚拟机的磁盘上,你可以使用mode: COPY来提高任务的I/O性能。更多详情请参见存储模式。
存储任务输出#
您可以通过创建一个新的存储桶并在MOUNT模式下使用它,直接将任务输出写入云存储桶。
💡 示例用例: 编写模型检查点,训练运行的日志。
# Creates an empty bucket. Any writes to /my_data will be replicated to s3://my-sky-bucket
file_mounts:
/my_data:
name: my-sky-bucket
store: s3
您的任务可以将文件写入/my_data,它们将自动上传到云端。
避免每次运行时重新上传数据#
与直接在file_mounts中使用本地路径相比,上传到存储桶可能会更快,因为它是持久的,因此需要从本地机器上传的次数更少。
💡 示例用例:上传本地数据集或文件一次,并在多个任务中使用它。
# Creates a bucket and reuses it in multiple tasks and runs
file_mounts:
/my_data:
name: my-sky-bucket
source: ~/my_local_path
store: s3
注意
如果源数据发生变化,新文件将自动同步到存储桶。
使用SkyPilot存储CLI#
要管理由SkyPilot创建的存储桶,sky CLI提供了两个命令:
sky storage ls 和 sky storage delete。
sky storage ls显示由SkyPilot创建的存储桶。
$ sky storage ls
NAME CREATED STORE COMMAND STATUS
sky-dataset 3 mins ago S3 sky launch -c demo examples/storage_demo.yaml READY
sky storage delete允许你删除由SkyPilot创建的任何存储桶。
$ sky storage delete sky-dataset
Deleting storage object sky-dataset...
I 04-02 19:42:24 storage.py:336] Detected existing storage object, loading Storage: sky-dataset
I 04-02 19:42:26 storage.py:683] Deleting S3 Bucket sky-dataset
注意
sky storage ls 仅显示由 SkyPilot 创建的存储。外部创建的存储桶或公共存储桶不会列在 sky storage ls 中,也无法通过 SkyPilot 进行管理。
存储 YAML 参考#
file_mounts:
/remote_path:
name: str
Identifier for the storage object. Used when creating a new storage
or referencing an existing storage created by SkyPilot. Not required
when using an existing bucket created externally.
source: str
The source attribute specifies the path that must be made available
in the storage object. It can either be:
- A local path
- A list of local paths
- A remote path using one of the following formats:
- s3://<bucket_name>
- gs://<bucket_name>
- https://<azure_storage_account>.blob.core.windows.net/<container_name>
- r2://<bucket_name>
- cos://<region_name>/<bucket_name>
- oci://<bucket_name>
If the source is local, data is uploaded to the cloud to an appropriate
bucket (s3, gcs, azure, r2, oci, or ibm). If source is bucket URI,
the data is copied or mounted directly (see mode flag below).
store: str; either of 's3', 'gcs', 'azure', 'r2', 'ibm', 'oci'
If you wish to force sky.Storage to be backed by a specific cloud object
storage, you can specify it here. If not specified, SkyPilot chooses the
appropriate object storage based on the source path and task's cloud provider.
persistent: bool; default: True.
Whether the remote backing stores in the cloud should be deleted after
execution of the task. Set to True to avoid uploading files again
in subsequent runs (at the cost of storing your data in the cloud). If
files change between runs, new files are synced to the bucket.
mode: str; either of MOUNT or COPY; default: MOUNT
Whether attach the bucket by copying files, or mounting the remote
bucket. With MOUNT mode, files are streamed from the remote bucket
and writes are replicated to the object store (and consequently, to
other workers mounting the same Storage). With COPY mode, files are
copied at VM initialization and any writes to the mount path will
not be replicated on the bucket.