createCompilationJob method

Future<CreateCompilationJobResponse> createCompilationJob({
  1. required String compilationJobName,
  2. required InputConfig inputConfig,
  3. required OutputConfig outputConfig,
  4. required String roleArn,
  5. required StoppingCondition stoppingCondition,
  6. List<Tag>? tags,
})

Starts a model compilation job. After the model has been compiled, Amazon SageMaker saves the resulting model artifacts to an Amazon Simple Storage Service (Amazon S3) bucket 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 with AWS IoT Greengrass. In that case, deploy them as an ML resource.

In the request body, you provide the following:

  • A name for the compilation job
  • Information about the input model artifacts
  • The output location for the compiled model and the device (target) that the model runs on
  • The Amazon Resource Name (ARN) of the IAM role that Amazon SageMaker assumes to perform the model compilation job.
You can also provide a Tag to track the model compilation job's resource use and costs. The response body contains the CompilationJobArn for the compiled job.

To stop a model compilation job, use StopCompilationJob. To get information about a particular model compilation job, use DescribeCompilationJob. To get information about multiple model compilation jobs, use ListCompilationJobs.

May throw ResourceInUse. May throw ResourceLimitExceeded.

Parameter compilationJobName : A name for the model compilation job. The name must be unique within the AWS Region and within your AWS account.

Parameter inputConfig : Provides information about the location of input model artifacts, the name and shape of the expected data inputs, and the framework in which the model was trained.

Parameter outputConfig : Provides information about the output location for the compiled model and the target device the model runs on.

Parameter roleArn : The Amazon Resource Name (ARN) of an IAM role that enables Amazon SageMaker to perform tasks on your behalf.

During model compilation, Amazon SageMaker needs your permission to:

  • Read input data from an S3 bucket
  • Write model artifacts to an S3 bucket
  • Write logs to Amazon CloudWatch Logs
  • Publish metrics to Amazon CloudWatch
You grant permissions for all of these tasks to an IAM role. To pass this role to Amazon SageMaker, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker Roles.

Parameter stoppingCondition : Specifies a limit to how long a model compilation job can run. When the job reaches the time limit, Amazon SageMaker ends the compilation job. Use this API to cap model training costs.

Parameter tags : An array of key-value pairs. You can use tags to categorize your AWS resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging AWS Resources.

Implementation

Future<CreateCompilationJobResponse> createCompilationJob({
  required String compilationJobName,
  required InputConfig inputConfig,
  required OutputConfig outputConfig,
  required String roleArn,
  required StoppingCondition stoppingCondition,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(compilationJobName, 'compilationJobName');
  _s.validateStringLength(
    'compilationJobName',
    compilationJobName,
    1,
    63,
    isRequired: true,
  );
  ArgumentError.checkNotNull(inputConfig, 'inputConfig');
  ArgumentError.checkNotNull(outputConfig, 'outputConfig');
  ArgumentError.checkNotNull(roleArn, 'roleArn');
  _s.validateStringLength(
    'roleArn',
    roleArn,
    20,
    2048,
    isRequired: true,
  );
  ArgumentError.checkNotNull(stoppingCondition, 'stoppingCondition');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'SageMaker.CreateCompilationJob'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'CompilationJobName': compilationJobName,
      'InputConfig': inputConfig,
      'OutputConfig': outputConfig,
      'RoleArn': roleArn,
      'StoppingCondition': stoppingCondition,
      if (tags != null) 'Tags': tags,
    },
  );

  return CreateCompilationJobResponse.fromJson(jsonResponse.body);
}