

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# SageMaker Python SDK を使用してデータ入力モードを設定する
<a name="model-access-training-data-using-pysdk"></a>

SageMaker Python SDK には、トレーニングジョブを開始するための 汎用的な [Estimator クラス](https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html#sagemaker.estimator.Estimator)と [ML フレームワーク用のバリエーション](https://sagemaker.readthedocs.io/en/stable/frameworks/index.html)が用意されています。SageMaker AI `Estimator` クラスまたは `Estimator.fit` メソッドの設定時に、データ入力モードのいずれかを指定できます。以下のコードテンプレートは、入力モードを指定する 2 つの方法を示しています。

**Estimator クラスを使用して入力モードを指定するには**

```
from sagemaker.estimator import Estimator
from sagemaker.inputs import TrainingInput

estimator = Estimator(
    checkpoint_s3_uri='s3://amzn-s3-demo-bucket/checkpoint-destination/',
    output_path='s3://amzn-s3-demo-bucket/output-path/',
    base_job_name='job-name',
    input_mode='File'  # Available options: File | Pipe | FastFile
    ...
)

# Run the training job
estimator.fit(
    inputs=TrainingInput(s3_data="s3://amzn-s3-demo-bucket/my-data/train")
)
```

詳細については、「*SageMaker Python SDK ドキュメント*」の「[sagemaker.estimator.Estimator](https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html#sagemaker.estimator.Estimator)」クラスを参照してください。

**`estimator.fit()` メソッドを使用して入力モードを指定するには**

```
from sagemaker.estimator import Estimator
from sagemaker.inputs import TrainingInput

estimator = Estimator(
    checkpoint_s3_uri='s3://amzn-s3-demo-bucket/checkpoint-destination/',
    output_path='s3://amzn-s3-demo-bucket/output-path/',
    base_job_name='job-name',
    ...
)

# Run the training job
estimator.fit(
    inputs=TrainingInput(
        s3_data="s3://amzn-s3-demo-bucket/my-data/train",
        input_mode='File'  # Available options: File | Pipe | FastFile
    )
)
```

詳細については、「*SageMaker Python SDK ドキュメント*」の「[sagemaker.estimator.Estimator.fit](https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html#sagemaker.estimator.Estimator.fit)」クラスメソッドと「[sagemaker.inputs.TrainingInput](https://sagemaker.readthedocs.io/en/stable/api/utility/inputs.html#sagemaker.inputs.TrainingInput)」クラスを参照してください。

**ヒント**  
SageMaker Python SDK 推定器を使用して VPC 設定で Amazon FSx for Lustre または Amazon EFS を設定する方法の詳細については、SageMaker AI Python SDK ドキュメントの「[Use File Systems as Training Inputs](https://sagemaker.readthedocs.io/en/stable/overview.html?highlight=VPC#use-file-systems-as-training-inputs)」を参照してください。

**ヒント**  
Amazon S3、Amazon EFS、FSx for Lustre とのデータ入力モードの統合は、ベストプラクティスに合わせてデータソースを最適に設定するための推奨方法です。SageMaker AI のマネージドストレージオプションと入力モードを使用すると、データ読み込みのパフォーマンスを戦略的に向上させることができますが、厳密な制約はありません。独自のデータ読み取りロジックをトレーニングコンテナに直接記述できます。例えば、別のデータソースから読み込むように設定したり、独自の S3 データローダークラスを作成したり、トレーニングスクリプト内でサードパーティフレームワークのデータロード機能を使用したりできます。ただし、SageMaker AI が認識できる正しいパスを指定する必要があります。

**ヒント**  
カスタムトレーニングコンテナを使用する場合は、SageMaker トレーニングジョブの環境設定に役立つ [SageMaker トレーニングツールキット](https://github.com/aws/sagemaker-training-toolkit)がインストールされていることを確認してください。それ以外の場合は、Dockerfile の環境変数を明示的に指定する必要があります。詳細については、「[Create a container with your own algorithms and models](https://docs.aws.amazon.com/sagemaker/latest/dg/docker-containers-create.html)」を参照してください。

低レベルの SageMaker API を使用してデータ入力モードを設定する方法の詳細については、「[Amazon SageMaker AI がトレーニング情報を提供する方法](your-algorithms-training-algo-running-container.md)」、「[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html)」API、「[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AlgorithmSpecification.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AlgorithmSpecification.html)」の「`TrainingInputMode`」を参照してください。