Coiled#

您可以使用 Coiled 在带 GPU 的云虚拟机上部署 RAPIDS。Coiled 是一个为您管理云虚拟机的软件平台。它管理软件环境,可以启动 Python 脚本、Jupyter Notebook 服务器、Dask 集群,甚至单个 Python 函数。远程机器按需启动,闲置或不使用时关闭。

通过使用 coiled Python 库,您可以在 GCP 或 AWS 等云计算环境中设置和管理带有 GPU 和 RAPIDS 的 Dask 集群。

设置#

前往 Coiled 注册一个账户。

账户设置完成后,安装 coiled Python 库/CLI 工具。

pip install coiled

然后您可以使用您的 Coiled 账户进行身份验证。

coiled login

更多信息请参阅 Coiled 入门文档

Notebook 快速入门#

在 Coiled 上开始使用 RAPIDS 的最简单方法是使用 RAPIDS notebook 容器启动 Jupyter notebook 服务器。

coiled notebook start --gpu --container nvcr.io/nvidia/rapidsai/notebooks:25.04-cuda12.8-py3.12

Screenshot of Jupyterlab running on Coiled executing some cudf GPU code

软件环境#

默认情况下,当运行远程操作时,Coiled 会尝试创建您本地软件环境的副本,并将其加载到远程虚拟机上。虽然这是一个出色的功能,但您本地可能没有安装所有您希望使用的 GPU 软件库。在这种情况下,我们需要告诉 Coiled 使用哪个软件环境。

容器镜像#

所有 Coiled 命令都可以传递一个要使用的容器镜像。该容器将在启动时拉取到远程虚拟机上。

coiled notebook start --gpu --container nvcr.io/nvidia/rapidsai/notebooks:25.04-cuda12.8-py3.12

这通常是尝试现有软件环境最便捷的方式,但由于容器镜像的解包方式,通常不是最高效的方式。

Coiled 软件环境#

您也可以提前创建 Coiled 软件环境。这些环境在云端构建并缓存,可以非常快速地拉取到新的虚拟机上。

您可以使用 conda environment.yaml 文件或 pip requirements.txt 文件创建 RAPIDS 软件环境。

Conda 示例#

创建一个包含 RAPIDS 包的环境文件

# rapids-environment.yaml
name: rapidsai-notebooks
channels:
  - rapidsai
  - conda-forge
  - nvidia
dependencies:
  # RAPIDS packages
  - rapids=25.04
  - python=3.12
  - cuda-version>=12.0,<=12.5
  # (optional) Jupyter packages, necessary for Coiled Notebooks and Dask clusters with Jupyter enabled
  - jupyterlab
  - jupyterlab-nvdashboard
  - dask-labextension
coiled env create --name rapids --gpu-enabled --conda rapids-environment.yaml

然后您可以在启动新的 Coiled 资源时指定此软件环境。

coiled notebook start --gpu --software rapidsai-notebooks

CLI 作业#

您可以使用 Coiled CLI 作业在临时虚拟机上的容器中执行脚本。

coiled run python my_code.py  # Boots a VM on the cloud, runs the scripts, then shuts down again

我们可以利用这个功能,使用 RAPIDS 容器在远程环境上运行 GPU 代码。您可以设置 coiled CLI 在执行完成后保留虚拟机几分钟,以便在您想再次运行并重用相同硬件时使用。

$ coiled run --gpu --name rapids-demo --keepalive 5m --container nvcr.io/nvidia/rapidsai/base:25.04-cuda12.8-py3.12 -- python my_code.py
...

这与 cudf.pandas CLI 工具搭配使用效果非常好。例如,我们可以运行 python -m cudf.pandas my_script 来对我们的 Pandas 代码进行 GPU 加速,而无需重写任何内容。例如,这个脚本处理一些开放的纽约市停车数据。使用 pandas 大约需要一分钟,而使用 cudf.pandas 只需几秒钟。

$ coiled run --gpu --name rapids-demo --keepalive 5m --container nvcr.io/nvidia/rapidsai/base:25.04-cuda12.8-py3.12 -- python -m cudf.pandas cudf_pandas_coiled_demo.py

Output
------

This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.download.nvidia.com/licenses/NVIDIA_Deep_Learning_Container_License.pdf

Calculate violations by state took: 3.470 seconds
Calculate violations by vehicle type took: 0.145 seconds
Calculate violations by day of week took: 1.238 seconds

Notebooks#

要使用 Coiled Notebooks 启动交互式 Jupyter notebook 会话,请通过 notebook 服务运行 RAPIDS notebook 容器。

coiled notebook start --gpu --container nvcr.io/nvidia/rapidsai/notebooks:25.04-cuda12.8-py3.12

请注意,--gpu 标志将自动在 AWS 上选择带有 T4 GPU 的 g4dn.xlarge 实例。您还可以添加 --vm-type 标志来显式选择具有不同 GPU 配置的另一台机器类型。例如,要选择带有 4 个 L4 GPU 的机器,您可以运行以下命令。

coiled notebook start --gpu --vm-type g6.24xlarge --container nvcr.io/nvidia/rapidsai/notebooks:24.12-cuda12.5-py3.12

Dask 集群#

Coiled 的托管 Dask 集群也可以使用 dask-cuda 来配置集群,从而以分布式方式启用 RAPIDS。

cluster = coiled.Cluster(
    container="nvcr.io/nvidia/rapidsai/notebooks:25.04-cuda12.8-py3.12",  # specify the software env to use
    jupyter=True,  # run Jupyter server on scheduler
    scheduler_gpu=True,  # add GPU to scheduler
    n_workers=4,
    worker_gpu=1,  # single T4 per worker
    worker_class="dask_cuda.CUDAWorker",  # recommended
)

集群启动后,您还可以获取 Jupyter URL 并导航到在 Dask Scheduler 节点上运行的 Jupyter Lab。

>>> print(cluster.jupyter_link)
https://cluster-abc123.dask.host/jupyter/lab?token=dddeeefff444555666

我们可以在 notebook 中运行 !nvidia-smi 来查看 Jupyter 可用的 GPU 信息。

我们还可以连接 Dask 客户端来查看 workers 的信息。

from dask.distributed import Client

client = Client()
client

Screenshot of Jupyter Lab running on a Coiled Dask Cluster with GPUs

从这个 Jupyter 会话中,我们可以看到我们的 notebook 服务器有一个 GPU,并且无需任何配置即可连接到 Dask 集群,看到所有 Dask Workers 也有 GPU。