設定資料輸入通道以使用 Amazon FSx for Lustre - Amazon SageMaker AI

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

設定資料輸入通道以使用 Amazon FSx for Lustre

了解如何使用 Amazon FSx for Lustre 做為您的資料來源,藉由縮短資料載入的時間,提高輸送量並加快訓練。

注意

當您使用已啟用 EFA 的執行個體 (例如 P4d 和 P3dn) 時,請務必在安全群組中設定適當的輸入和輸出規則。特別需要開啟這些連接埠,SageMaker AI 才能存取訓練任務中的 Amazon FSx 檔案系統。如需進一步了解,請參閱 Amazon VPC 的檔案系統存取控制

同步 Amazon S3 和 Amazon FSx for Lustre

若要將您的 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 儲存貯體連結的 FSx for Lustre 檔案系統,請按照 Amazon FSx for Lustre 使用者指南內的連結您的檔案系統至 Amazon S3 儲存貯體的步驟。請務必新增端點至您的 VPC,以允許 Amazon S3 存取。如需詳細資訊,請參閱建立 Amazon S3 VPC 端點。指定資料儲存庫路徑時,請提供包含您的資料集資料夾的 Amazon S3 儲存貯體 URI。例如,根據步驟 1 中的 S3 路徑範例,資料儲存庫路徑應如下所示。

    s3://amzn-s3-demo-bucket/data
  3. 建立 FSx for 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 和 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. 設定檔案系統輸入類別物件。

    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. 使用用於 Amazon FSx 檔案系統的 VPC 組態來設定 SageMaker 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 時,請務必提供 Amazon FSx 檔案系統路徑,開頭為 MountName