将数据输入通道配置为使用 Amazon for Lu FSx stre - 亚马逊 SageMaker AI

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

将数据输入通道配置为使用 Amazon for Lu FSx stre

了解如何使用 Amazon f FSx or Lustre 作为数据源,通过缩短数据加载时间,实现更高的吞吐量和更快的训练。

注意

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

同步亚马逊 S3 和亚马逊获得 Lu FSx stre

要将您的 Amazon S3 链接到 Amazon FSx for Lustre 并上传您的训练数据集,请执行以下操作。

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

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

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

    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 和亚马逊 FSx 之间的同步完成后,您的数据集将保存在亚马逊的以下目录 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,请务必提供以开头的 Amazon FSx 文件系统路径MountName

  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. 通过在亚马逊文件系统中运行 estimator.fit 方法来启动训练作业。 FSx

    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,请务必提供以开头的 Amazon FSx 文件系统路径MountName