

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

# 将数据输入通道配置为使用 Amazon for Lu FSx stre
<a name="model-access-training-data-fsx"></a>

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

**注意**  
当您使用启用 EFA 的实例（例如 P4d 和 P3dn）时，请确保在安全组中设置适当的入站和输出规则。特别是，要让 SageMaker AI 在训练作业中访问 Amazon FSx 文件系统，就必须打开这些端口。要了解更多信息，请参阅使用 [Amazon VPC 进行文件系统访问控制](https://docs.aws.amazon.com/fsx/latest/LustreGuide/limit-access-security-groups.html)。

## 同步亚马逊 S3 和亚马逊获得 Lu FSx stre
<a name="model-access-training-data-fsx-sync-s3"></a>

要将您的 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
   ```

1. 要创建与包含训练数据的 Amazon S3 存储桶关联的 for Lustre 文件系统，请按照《Amazon for *Lustre 用户指南》中[将您的文件系统关联到 Amazon S3 存储桶](https://docs.aws.amazon.com/fsx/latest/LustreGuide/create-dra-linked-data-repo.html)中的步骤 FSx 进行*操作。 FSx 请务必在您的 VPC 中添加一个允许访问 Amazon S3 的端点。有关更多信息，请参阅 [创建 Amazon S3 VPC 端点](train-vpc.md#train-vpc-s3)。指定**数据存储库路径**时，请提供包含您的数据集的文件夹的 Amazon S3 存储桶 URI。例如，根据步骤 1 中的 S3 路径示例，数据存储库路径应如下所示。

   ```
   s3://amzn-s3-demo-bucket/data
   ```

1. 创建 f FSx or Lustre 文件系统后，通过运行以下命令检查配置信息。

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

   这些命令返回 `FileSystemId`、`MountName`、`FileSystemPath` 和 `DataRepositoryPath`。输出应该类似以下示例。

   ```
   # 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 训练的数据输入通道
<a name="model-access-training-data-fsx-set-as-input-channel"></a>

以下过程将引导您完成将 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`。

1. 使用用于 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。

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

   ```
   estimator.fit(train_fs)
   ```

要查找更多代码示例，请参阅 *SageMaker Python SDK 文档*中的[使用文件系统作为训练输入](https://sagemaker.readthedocs.io/en/stable/overview.html#use-file-systems-as-training-inputs)。

------
#### [ Using the SageMaker AI CreateTrainingJob API ]

作为[CreateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html)请求 JSON 的一部分，请按以下方式进行配置`InputDataConfig`。

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

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

------