SageMaker#

RAPIDS 可通过几种方式与 AWS SageMaker 结合使用。

SageMaker Notebooks#

首先,前往 SageMaker 控制台 并创建一个 新的 SageMaker Notebook 实例

选择 Applications and IDEs > Notebooks > Create notebook instance

选择您的实例#

如果未提及某个字段,请保留默认值

  • Notebook 实例名称 = Notebook 实例的名称

  • Notebook 实例类型 = Notebook 实例的类型。选择与 RAPIDS 兼容的 GPU(请参阅 RAPIDS 文档)作为 SageMaker Notebook 实例类型(例如,ml.p3.2xlarge)。

  • 平台标识符 = ‘Amazon Linux 2, Jupyter Lab 4’

Screenshot of the create new notebook screen with a ml.p3.2xlarge selected

创建 RAPIDS 生命周期配置#

SageMaker Notebook 实例 可以通过 RAPIDS conda 环境增强。

我们可以通过在生命周期配置脚本中安装,将 RAPIDS conda 环境添加到 SageMaker notebook 实例中可用的 Jupyter ipython 内核集合中。

创建一个新的生命周期配置(通过“附加配置”下拉菜单)。

Screenshot of the create lifecycle configuration screen

为您的配置命名,例如 rapids,并将以下脚本粘贴到“启动 notebook”脚本中。

#!/bin/bash

set -e

sudo -u ec2-user -i <<'EOF'

mamba create -y -n rapids -c rapidsai -c conda-forge -c nvidia rapids=24.12 python=3.12 cuda-version=12.4 \
    boto3 \
    ipykernel \
    'sagemaker-python-sdk>=2.239.0'

conda activate rapids

python -m ipykernel install --user --name rapids
echo "kernel install completed"
EOF

警告

在 SageMaker Notebook 实例支持 Amazon Linux 2023 或 GLIBC 版本至少为 2.28 的其他 Linux 发行版之前,将无法在其上安装 RAPIDS >24.12。有关更多详细信息,请参阅 rapidsai/deployment#520

将卷大小设置为至少 15GB,以容纳 conda 环境。

然后启动实例。

选择 RAPIDS 环境#

当您的 Notebook 实例状态为 InService 后,选择“Open JupyterLab”

注意

如果您在状态列中看到 notebook 实例右侧显示 Pending,则表示您的 notebook 仍在创建中。当 notebook 可用时,状态将变为 InService。

然后在 Jupyter 中创建新 notebook 时,选择 rapids 内核。

Screenshot of Jupyter with the rapids kernel highlighted

运行示例 Notebook#

进入 JupyterLab 后,您应该能够上传 大规模运行 RAPIDS 超参数实验 示例 notebook 并继续按照这些说明操作。

SageMaker Estimators#

RAPIDS 也可以在 SageMaker Estimators 中使用。通过 Estimators,您可以在 SageMaker 为您管理的临时 VM 上启动训练作业。使用此选项,您的 Notebook 实例不需要配备 GPU……您只需为训练作业运行期间使用的 GPU 实例付费。

您只需将 RAPIDS 训练脚本和库打包成 Docker 容器镜像,然后请求 Amazon SageMaker 在指定数量的 GPU 实例上并行运行其副本即可。

让我们通过分步方法更详细地了解其工作原理

  • 训练脚本应接受超参数作为命令行参数。从基础 RAPIDS 容器(从 Docker Hub 拉取)开始,使用 Dockerfile 通过复制您的训练代码来增强它,并将 WORKDIR 路径设置为代码路径。

  • 安装 sagemaker-training toolkit 使容器与 SageMaker 兼容。根据您的工作流程需要添加其他包,例如 python、flask(模型服务)、dask-ml 等。

  • 将镜像推送到容器注册表 (ECR)。

  • 构建好我们的容器和自定义逻辑后,现在可以将所有组件组装到 Estimator 中。现在我们可以测试 Estimator 并运行并行超参数优化调优作业。

Estimators 的 API 大致如下

# set up configuration for the estimator
estimator = sagemaker.estimator.Estimator(
    image_uri,
    role,
    instance_type,
    instance_count,
    input_mode,
    output_path,
    use_spot_instances,
    max_run=86400,
    sagemaker_session,
)

# launch a single remote training job
estimator.fit(inputs=s3_data_input, job_name=job_name)

# set up configuration for HyperparameterTuner
hpo = sagemaker.tuner.HyperparameterTuner(
    estimator,
    metric_definitions,
    objective_metric_name,
    objective_type="Maximize",
    hyperparameter_ranges,
    strategy,
    max_jobs,
    max_parallel_jobs,
)

# launch multiple training jobs (one per combination of hyperparameters)
hpo.fit(inputs=s3_data_input, job_name=tuning_job_name, wait=True, logs="All")

有关此操作的实践演示,请尝试 [“深入探究在 AWS SageMaker 上运行超参数优化”]/examples/rapids-sagemaker-higgs/notebook)。

延伸阅读#

我们还撰写了一篇详细的博客文章,介绍如何在 SageMaker 中使用 RAPIDS。

相关示例#

深入探究在 AWS SageMaker 上运行超参数优化

cloud/aws/sagemaker workflow/hpo library/xgboost library/cuml library/cupy library/cudf library/dask data-storage/s3 data-format/parquet

深入探究在 AWS SageMaker 上运行超参数优化

使用十亿行挑战测量性能

tools/dask-cuda data-format/csv library/cudf library/cupy library/dask library/pandas cloud/aws/ec2 cloud/aws/sagemaker cloud/azure/azure-vm cloud/azure/ml cloud/gcp/compute-engine cloud/gcp/vertex-ai

使用十亿行挑战测量性能

在 Amazon SageMaker 上大规模运行 RAPIDS 超参数实验

cloud/aws/sagemaker workflow/hpo library/cudf library/cuml library/scikit-learn data-format/csv data-storage/s3

在 Amazon SageMaker 上大规模运行 RAPIDS 超参数实验