createOptimizationJob method

Future<CreateOptimizationJobResponse> createOptimizationJob({
  1. required OptimizationJobDeploymentInstanceType deploymentInstanceType,
  2. required OptimizationJobModelSource modelSource,
  3. required List<OptimizationConfig> optimizationConfigs,
  4. required String optimizationJobName,
  5. required OptimizationJobOutputConfig outputConfig,
  6. required String roleArn,
  7. required StoppingCondition stoppingCondition,
  8. int? maxInstanceCount,
  9. Map<String, String>? optimizationEnvironment,
  10. List<Tag>? tags,
  11. OptimizationVpcConfig? vpcConfig,
})

Creates a job that optimizes a model for inference performance. To create the job, you provide the location of a source model, and you provide the settings for the optimization techniques that you want the job to apply. When the job completes successfully, SageMaker uploads the new optimized model to the output destination that you specify.

For more information about how to use this action, and about the supported optimization techniques, see Optimize model inference with Amazon SageMaker.

May throw ResourceInUse. May throw ResourceLimitExceeded.

Parameter deploymentInstanceType : The type of instance that hosts the optimized model that you create with the optimization job.

Parameter modelSource : The location of the source model to optimize with an optimization job.

Parameter optimizationConfigs : Settings for each of the optimization techniques that the job applies.

Parameter optimizationJobName : A custom name for the new optimization job.

Parameter outputConfig : Details for where to store the optimized model that you create with the optimization job.

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

During model optimization, Amazon SageMaker AI 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 AI, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker AI Roles.

Parameter maxInstanceCount : The maximum number of instances to use for the optimization job.

Parameter optimizationEnvironment : The environment variables to set in the model container.

Parameter tags : A list of key-value pairs associated with the optimization job. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide.

Parameter vpcConfig : A VPC in Amazon VPC that your optimized model has access to.

Implementation

Future<CreateOptimizationJobResponse> createOptimizationJob({
  required OptimizationJobDeploymentInstanceType deploymentInstanceType,
  required OptimizationJobModelSource modelSource,
  required List<OptimizationConfig> optimizationConfigs,
  required String optimizationJobName,
  required OptimizationJobOutputConfig outputConfig,
  required String roleArn,
  required StoppingCondition stoppingCondition,
  int? maxInstanceCount,
  Map<String, String>? optimizationEnvironment,
  List<Tag>? tags,
  OptimizationVpcConfig? vpcConfig,
}) async {
  _s.validateNumRange(
    'maxInstanceCount',
    maxInstanceCount,
    1,
    1152921504606846976,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'SageMaker.CreateOptimizationJob'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'DeploymentInstanceType': deploymentInstanceType.value,
      'ModelSource': modelSource,
      'OptimizationConfigs': optimizationConfigs,
      'OptimizationJobName': optimizationJobName,
      'OutputConfig': outputConfig,
      'RoleArn': roleArn,
      'StoppingCondition': stoppingCondition,
      if (maxInstanceCount != null) 'MaxInstanceCount': maxInstanceCount,
      if (optimizationEnvironment != null)
        'OptimizationEnvironment': optimizationEnvironment,
      if (tags != null) 'Tags': tags,
      if (vpcConfig != null) 'VpcConfig': vpcConfig,
    },
  );

  return CreateOptimizationJobResponse.fromJson(jsonResponse.body);
}