Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: CC-BY-SA-4.0

CreateTrainingJob

Starts a model training job. After training completes, Amazon SageMaker saves the resulting model artifacts to an Amazon S3 location that you specify.

If you choose to host your model using Amazon SageMaker hosting services, you can use the resulting model artifacts as part of the model. You can also use the artifacts in a machine learning service other than Amazon SageMaker, provided that you know how to use them for inferences.

In the request body, you provide the following: + AlgorithmSpecification - Identifies the training algorithm to use. + HyperParameters - Specify these algorithm-specific parameters to enable the estimation of model parameters during training. Hyperparameters can be tuned to optimize this learning process. For a list of hyperparameters for each training algorithm provided by Amazon SageMaker, see Algorithms. + InputDataConfig - Describes the training dataset and the Amazon S3 location where it is stored. + OutputDataConfig - Identifies the Amazon S3 location where you want Amazon SageMaker to save the results of model training.

For more information about Amazon SageMaker, see How It Works.

{
   "[AlgorithmSpecification](#SageMaker-CreateTrainingJob-request-AlgorithmSpecification)": { 
      "[AlgorithmName](API_AlgorithmSpecification.md#SageMaker-Type-AlgorithmSpecification-AlgorithmName)": "string",
      "[MetricDefinitions](API_AlgorithmSpecification.md#SageMaker-Type-AlgorithmSpecification-MetricDefinitions)": [ 
         { 
            "[Name](API_MetricDefinition.md#SageMaker-Type-MetricDefinition-Name)": "string",
            "[Regex](API_MetricDefinition.md#SageMaker-Type-MetricDefinition-Regex)": "string"
         }
      ],
      "[TrainingImage](API_AlgorithmSpecification.md#SageMaker-Type-AlgorithmSpecification-TrainingImage)": "string",
      "[TrainingInputMode](API_AlgorithmSpecification.md#SageMaker-Type-AlgorithmSpecification-TrainingInputMode)": "string"
   },
   "[EnableInterContainerTrafficEncryption](#SageMaker-CreateTrainingJob-request-EnableInterContainerTrafficEncryption)": boolean,
   "[EnableNetworkIsolation](#SageMaker-CreateTrainingJob-request-EnableNetworkIsolation)": boolean,
   "[HyperParameters](#SageMaker-CreateTrainingJob-request-HyperParameters)": { 
      "string" : "string" 
   },
   "[InputDataConfig](#SageMaker-CreateTrainingJob-request-InputDataConfig)": [ 
      { 
         "[ChannelName](API_Channel.md#SageMaker-Type-Channel-ChannelName)": "string",
         "[CompressionType](API_Channel.md#SageMaker-Type-Channel-CompressionType)": "string",
         "[ContentType](API_Channel.md#SageMaker-Type-Channel-ContentType)": "string",
         "[DataSource](API_Channel.md#SageMaker-Type-Channel-DataSource)": { 
            "[S3DataSource](API_DataSource.md#SageMaker-Type-DataSource-S3DataSource)": { 
               "[AttributeNames](API_S3DataSource.md#SageMaker-Type-S3DataSource-AttributeNames)": [ "string" ],
               "[S3DataDistributionType](API_S3DataSource.md#SageMaker-Type-S3DataSource-S3DataDistributionType)": "string",
               "[S3DataType](API_S3DataSource.md#SageMaker-Type-S3DataSource-S3DataType)": "string",
               "[S3Uri](API_S3DataSource.md#SageMaker-Type-S3DataSource-S3Uri)": "string"
            }
         },
         "[InputMode](API_Channel.md#SageMaker-Type-Channel-InputMode)": "string",
         "[RecordWrapperType](API_Channel.md#SageMaker-Type-Channel-RecordWrapperType)": "string",
         "[ShuffleConfig](API_Channel.md#SageMaker-Type-Channel-ShuffleConfig)": { 
            "[Seed](API_ShuffleConfig.md#SageMaker-Type-ShuffleConfig-Seed)": number
         }
      }
   ],
   "[OutputDataConfig](#SageMaker-CreateTrainingJob-request-OutputDataConfig)": { 
      "[KmsKeyId](API_OutputDataConfig.md#SageMaker-Type-OutputDataConfig-KmsKeyId)": "string",
      "[S3OutputPath](API_OutputDataConfig.md#SageMaker-Type-OutputDataConfig-S3OutputPath)": "string"
   },
   "[ResourceConfig](#SageMaker-CreateTrainingJob-request-ResourceConfig)": { 
      "[InstanceCount](API_ResourceConfig.md#SageMaker-Type-ResourceConfig-InstanceCount)": number,
      "[InstanceType](API_ResourceConfig.md#SageMaker-Type-ResourceConfig-InstanceType)": "string",
      "[VolumeKmsKeyId](API_ResourceConfig.md#SageMaker-Type-ResourceConfig-VolumeKmsKeyId)": "string",
      "[VolumeSizeInGB](API_ResourceConfig.md#SageMaker-Type-ResourceConfig-VolumeSizeInGB)": number
   },
   "[RoleArn](#SageMaker-CreateTrainingJob-request-RoleArn)": "string",
   "[StoppingCondition](#SageMaker-CreateTrainingJob-request-StoppingCondition)": { 
      "[MaxRuntimeInSeconds](API_StoppingCondition.md#SageMaker-Type-StoppingCondition-MaxRuntimeInSeconds)": number
   },
   "[Tags](#SageMaker-CreateTrainingJob-request-Tags)": [ 
      { 
         "[Key](API_Tag.md#SageMaker-Type-Tag-Key)": "string",
         "[Value](API_Tag.md#SageMaker-Type-Tag-Value)": "string"
      }
   ],
   "[TrainingJobName](#SageMaker-CreateTrainingJob-request-TrainingJobName)": "string",
   "[VpcConfig](#SageMaker-CreateTrainingJob-request-VpcConfig)": { 
      "[SecurityGroupIds](API_VpcConfig.md#SageMaker-Type-VpcConfig-SecurityGroupIds)": [ "string" ],
      "[Subnets](API_VpcConfig.md#SageMaker-Type-VpcConfig-Subnets)": [ "string" ]
   }
}

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

** AlgorithmSpecification ** The registry path of the Docker image that contains the training algorithm and algorithm-specific metadata, including the input mode. For more information about algorithms provided by Amazon SageMaker, see Algorithms. For information about providing your own algorithms, see Using Your Own Algorithms with Amazon SageMaker.
Type: AlgorithmSpecification object
Required: Yes

** EnableInterContainerTrafficEncryption ** To encrypt all communications between ML compute instances in distributed training, choose True. Encryption provides greater security for distributed training, but training might take longer. How long it takes depends on the amount of communication between compute instances, especially if you use a deep learning algorithm in distributed training. For more information, see Protect Communications Between ML Compute Instances in a Distributed Training Job.
Type: Boolean
Required: No

** EnableNetworkIsolation ** Isolates the training container. No inbound or outbound network calls can be made, except for calls between peers within a training cluster for distributed training. If you enable network isolation for training jobs that are configured to use a VPC, Amazon SageMaker downloads and uploads customer data and model artifacts through the specified VPC, but the training container does not have network access.
The Semantic Segmentation built-in algorithm does not support network isolation. Type: Boolean
Required: No

** HyperParameters ** Algorithm-specific parameters that influence the quality of the model. You set hyperparameters before you start the learning process. For a list of hyperparameters for each training algorithm provided by Amazon SageMaker, see Algorithms.
You can specify a maximum of 100 hyperparameters. Each hyperparameter is a key-value pair. Each key and value is limited to 256 characters, as specified by the Length Constraint.
Type: String to string map
Key Length Constraints: Maximum length of 256.
Key Pattern: .*
Value Length Constraints: Maximum length of 256.
Value Pattern: .*
Required: No

** InputDataConfig ** An array of Channel objects. Each channel is a named input source. InputDataConfig describes the input data and its location.
Algorithms can accept input data from one or more channels. For example, an algorithm might have two channels of input data, training_data and validation_data. The configuration for each channel provides the S3 location where the input data is stored. It also provides information about the stored data: the MIME type, compression method, and whether the data is wrapped in RecordIO format.
Depending on the input mode that the algorithm supports, Amazon SageMaker either copies input data files from an S3 bucket to a local directory in the Docker container, or makes it available as input streams.
Type: Array of Channel objects
Array Members: Minimum number of 1 item. Maximum number of 20 items.
Required: No

** OutputDataConfig ** Specifies the path to the S3 bucket where you want to store model artifacts. Amazon SageMaker creates subfolders for the artifacts.
Type: OutputDataConfig object
Required: Yes

** ResourceConfig ** The resources, including the ML compute instances and ML storage volumes, to use for model training.
ML storage volumes store model artifacts and incremental states. Training algorithms might also use ML storage volumes for scratch space. If you want Amazon SageMaker to use the ML storage volume to store the training data, choose File as the TrainingInputMode in the algorithm specification. For distributed training algorithms, specify an instance count greater than 1.
Type: ResourceConfig object
Required: Yes

** RoleArn ** The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker can assume to perform tasks on your behalf.
During model training, Amazon SageMaker needs your permission to read input data from an S3 bucket, download a Docker image that contains training code, write model artifacts to an S3 bucket, write logs to Amazon CloudWatch Logs, and publish metrics to Amazon CloudWatch. You grant permissions for all of these tasks to an IAM role. For more information, see Amazon SageMaker Roles.
To be able to pass this role to Amazon SageMaker, the caller of this API must have the iam:PassRole permission. Type: String
Length Constraints: Minimum length of 20. Maximum length of 2048.
Pattern: ^arn:aws[a-z\-]*:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+$
Required: Yes

** StoppingCondition ** Specifies a limit to how long a model training job can run. When the job reaches the time limit, Amazon SageMaker ends the training job. Use this API to cap model training costs.
To stop a job, Amazon SageMaker sends the algorithm the SIGTERM signal, which delays job termination for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training are not lost.
Type: StoppingCondition object
Required: Yes

** Tags ** An array of key-value pairs. For more information, see Using Cost Allocation Tags in the AWS Billing and Cost Management User Guide.
Type: Array of Tag objects
Array Members: Minimum number of 0 items. Maximum number of 50 items.
Required: No

** TrainingJobName ** The name of the training job. The name must be unique within an AWS Region in an AWS account.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 63.
Pattern: ^[a-zA-Z0-9](-*[a-zA-Z0-9])*
Required: Yes

** VpcConfig ** A VpcConfig object that specifies the VPC that you want your training job to connect to. Control access to and from your training container by configuring the VPC. For more information, see Protect Training Jobs by Using an Amazon Virtual Private Cloud.
Type: VpcConfig object
Required: No

{
   "[TrainingJobArn](#SageMaker-CreateTrainingJob-response-TrainingJobArn)": "string"
}

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

** TrainingJobArn ** The Amazon Resource Name (ARN) of the training job.
Type: String
Length Constraints: Maximum length of 256.
Pattern: arn:aws[a-z\-]*:sagemaker:[a-z0-9\-]*:[0-9]{12}:training-job/.*

For information about the errors that are common to all actions, see Common Errors.

ResourceInUse
Resource being accessed is in use.
HTTP Status Code: 400

ResourceLimitExceeded
You have exceeded an Amazon SageMaker resource limit. For example, you might have too many training jobs created.
HTTP Status Code: 400

For more information about using this API in one of the language-specific AWS SDKs, see the following: + AWS Command Line Interface + AWS SDK for .NET + AWS SDK for C++ + AWS SDK for Go + AWS SDK for Go - Pilot + AWS SDK for Java + AWS SDK for JavaScript + AWS SDK for PHP V3 + AWS SDK for Python + AWS SDK for Ruby V2