View a markdown version of this page

配置数据输入通道以使用适用于 Lustre 的 Amazon FSx - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

配置数据输入通道以使用适用于 Lustre 的 Amazon FSx

了解如何使用适用于 Lustre 的 Amazon FSx 作为数据来源,通过缩短数据加载时间来提高吞吐量和训练速度。

注意

使用诸如 p4d 和 p3dn 之类的 EFA-enabled 实例时,请确保在安全组中设置适当的入站和输出规则。特别是,要让 SageMaker AI 在训练作业中访问 Amazon FSx 文件系统,就必须打开这些端口。要了解更多信息,请参阅使用 Amazon VPC 进行文件系统访问控制

将 Amazon S3 与适用于 Lustre 的 Amazon FSx 同步

要将您的 Amazon S3 与适用于 Lustre 的 Amazon FSx 关联并上传您的训练数据集,请执行以下操作。

  1. 准备好您的数据集并上传到 Amazon S3 存储桶。例如,假设训练数据集和测试数据集的 Amazon S3 路径采用以下格式。

    s3://amzn-s3-demo-bucket/data/train s3://amzn-s3-demo-bucket/data/test
  2. 要创建与包含训练数据的 Amazon S3 存储桶关联的、适用于 Lustre 的 FSx 文件系统,请完成《适用于 Lustre 的 Amazon FSx 用户指南》将您的文件系统与 Amazon S3 存储桶关联中的步骤。请务必在您的 VPC 中添加一个允许访问 Amazon S3 的端点。有关更多信息,请参阅 创建 Amazon S3 VPC 端点。指定数据存储库路径时,请提供包含您的数据集的文件夹的 Amazon S3 存储桶 URI。例如,根据步骤 1 中的 S3 路径示例,数据存储库路径应如下所示。

    s3://amzn-s3-demo-bucket/data
  3. 创建适用于 Lustre 的 FSx 文件系统后,通过运行以下命令检查配置信息。

    aws fsx describe-file-systems && \ aws fsx describe-data-repository-association

    这些命令返回 FileSystemIdMountNameFileSystemPathDataRepositoryPath。输出应该类似以下示例。

    # Output of aws fsx describe-file-systems "FileSystemId": "fs-0123456789abcdef0" "MountName": "1234abcd" # Output of aws fsx describe-data-repository-association "FileSystemPath": "/ns1", "DataRepositoryPath": "s3://amzn-s3-demo-bucket/data/"

    在 Amazon S3 和 Amazon FSx 之间完成同步后,您的数据集将保存在 Amazon FSx 中的以下目录中。

    /ns1/train # synced with s3://amzn-s3-demo-bucket/data/train /ns1/test # synced with s3://amzn-s3-demo-bucket/data/test

将 Amazon FSx 文件系统路径设置为训练的数据输入通道 SageMaker

以下过程将引导您完成将 Amazon FSx 文件系统设置为 SageMaker 训练作业数据源的过程。

Using the SageMaker Python SDK

要正确将 Amazon FSx 文件系统设置为数据源,请配置 SageMaker AI 估算器类并FileSystemInput使用以下指令。

  1. 配置 FileSystemInput 类对象。

    from sagemaker.inputs import FileSystemInput train_fs = FileSystemInput( file_system_id="fs-0123456789abcdef0", file_system_type="FSxLustre", directory_path="/1234abcd/ns1/", file_system_access_mode="ro", )
    提示

    指定 directory_path 时,请务必提供以 MountName 开头的 Amazon FSx 文件系统路径。

  2. 使用用于 SageMaker Amazon FSx 文件系统的 VPC 配置来配置 AI 估算器。

    from sagemaker.estimator import Estimator estimator = Estimator( ... role="your-iam-role-with-access-to-your-fsx", subnets=["subnet-id"], # Should be the same as the subnet used for Amazon FSx security_group_ids="security-group-id" )

    确保 SageMaker 训练任务的 IAM 角色有权访问和读取 Amazon FSx。

  3. 通过在 Amazon FSx 文件系统中运行 estimator.fit 方法来启动训练作业。

    estimator.fit(train_fs)

要查找更多代码示例,请参阅 SageMaker Python SDK 文档中的使用文件系统作为训练输入

Using the SageMaker AI CreateTrainingJob API

作为CreateTrainingJob请求 JSON 的一部分,请按以下方式进行配置InputDataConfig

"InputDataConfig": [ { "ChannelName": "string", "DataSource": { "FileSystemDataSource": { "DirectoryPath": "/1234abcd/ns1/", "FileSystemAccessMode": "ro", "FileSystemId": "fs-0123456789abcdef0", "FileSystemType": "FSxLustre" } } } ],
提示

指定 DirectoryPath 时,请务必提供以 MountName 开头的 Amazon FSx 文件系统路径。