Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Créez une tâche de formation à l'aide de l'API AWS CLI, du SageMaker SDK
Pour utiliser SageMaker des plans de SageMaker formation pour votre tâche de formation, spécifiez le TrainingPlanArn paramètre du plan souhaité ResourceConfig lors de l'appel de l'opération CreateTrainingJobAPI. Vous pouvez utiliser un et un seul plan par tâche.
Important
Le champ InstanceType défini dans la section ResourceConfig de la demande CreateTrainingJob doit correspondre à l’élément InstanceType de votre plan d’entraînement.
Exécution d’une tâche d’entraînement sur un plan à l’aide de l’interface de ligne de commande
L'exemple suivant montre comment créer une tâche de SageMaker formation et l'associer à un plan de formation fourni à l'aide de l'TrainingPlanArnattribut de la create-training-job AWS CLI commande.
Pour plus d'informations sur la création d'une tâche de formation à l'aide de la AWS CLI CreateTrainingJobcommande, consultez create-training-job.
# Create a training job aws sagemaker create-training-job \ --training-job-nametraining-job-name\ ... --resource-config '{ "InstanceType": "ml.p5.48xlarge", "InstanceCount":8, "VolumeSizeInGB":10, "TrainingPlanArn": "training-plan-arn" } }' \ ...
Cet AWS CLI exemple de commande crée une nouvelle tâche de formation en SageMaker IA en utilisant un plan de formation dans l'--resource-configargument.
aws sagemaker create-training-job \ --training-job-namejob-name\ --role-arnarn:aws:iam::111122223333:role/DataAndAPIAccessRole\ --algorithm-specification '{"TrainingInputMode": "File","TrainingImage": "111122223333.dkr.ecr.us-east-1.amazonaws.com/algo-image:tag", "ContainerArguments": [" "]}' \ --input-data-config '[{"ChannelName":"training","DataSource":{"S3DataSource":{"S3DataType":"S3Prefix","S3Uri":"s3://bucketname/input","S3DataDistributionType":"ShardedByS3Key"}}}]' \ --output-data-config '{"S3OutputPath": "s3://bucketname/output"}' \ --resource-config '{"VolumeSizeInGB":10,"InstanceCount":4,"InstanceType":"ml.p5.48xlarge", "TrainingPlanArn" : "arn:aws:sagemaker:us-east-1:111122223333:training-plan/plan-name"}' \ --stopping-condition '{"MaxRuntimeInSeconds":1800}' \ --regionus-east-1
Après avoir créé la tâche d’entraînement, vous pouvez vérifier qu’elle a été correctement attribuée au plan d’entraînement en appelant l’API DescribeTrainingJob.
aws sagemaker describe-training-job --training-job-nametraining-job-name
Exécutez une tâche de formation sur un plan à l'aide du SDK SageMaker AI Python
Vous pouvez également créer une tâche de formation associée à un plan de formation à l'aide du SDK SageMaker Python
Si vous utilisez le SDK SageMaker Python depuis JupyterLab Studio pour créer une tâche de formation, assurez-vous que le rôle d'exécution utilisé par l'espace exécutant votre JupyterLab application dispose des autorisations requises pour utiliser les plans de SageMaker formation. Pour en savoir plus sur les autorisations requises pour utiliser les plans de SageMaker formation, consultezIAM pour les plans de SageMaker formation.
L'exemple suivant montre comment créer une tâche de SageMaker formation et l'associer à un plan de formation fourni à l'aide de l'training_planattribut de l'Estimatorobjet lors de l'utilisation du SDK SageMaker Python.
Pour plus d'informations sur l' SageMaker estimateur, voir Utiliser un SageMaker estimateur pour exécuter une tâche de formation.
import sagemaker import boto3 from sagemaker import get_execution_role from sagemaker.estimator import Estimator from sagemaker.inputs import TrainingInput # Set up the session and SageMaker client session = boto3.Session() region = session.region_name sagemaker_session = session.client('sagemaker') # Get the execution role for the training job role = get_execution_role() # Define the input data configuration trainingInput = TrainingInput( s3_data='s3://input-path', distribution='ShardedByS3Key', s3_data_type='S3Prefix' ) estimator = Estimator( entry_point='train.py', image_uri="123456789123.dkr.ecr.{}.amazonaws.com/image:tag", role=role, instance_count=4, instance_type='ml.p5.48xlarge', training_plan="training-plan-arn", volume_size=20, max_run=3600, sagemaker_session=sagemaker_session, output_path="s3://output-path" ) # Create the training job estimator.fit(inputs=trainingInput, job_name=job_name)
Après avoir créé la tâche d’entraînement, vous pouvez vérifier qu’elle a été correctement attribuée au plan d’entraînement en appelant l’API DescribeTrainingJob.
# Check job details sagemaker_session.describe_training_job(TrainingJobName=job_name)