Skip to content

create_model_customization_job async

create_model_customization_job(
    job_name: JobName,
    custom_model_name: CustomModelName,
    role_arn: RoleArn,
    base_model_identifier: BaseModelIdentifier,
    training_data_config: TrainingDataConfig,
    output_data_config: OutputDataConfig,
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    client_request_token: Optional[IdempotencyToken] = None,
    customization_type: Optional[CustomizationType] = None,
    custom_model_kms_key_id: Optional[KmsKeyId] = None,
    job_tags: Optional[TagList] = None,
    custom_model_tags: Optional[TagList] = None,
    validation_data_config: Optional[ValidationDataConfig] = None,
    hyper_parameters: Optional[ModelCustomizationHyperParameters] = None,
    vpc_config: Optional[VpcConfig] = None,
    customization_config: Optional[CustomizationConfig] = None,
) -> CreateModelCustomizationJobResponse

Creates a fine-tuning job to customize a base model.

You specify the base foundation model and the location of the training data. After the model-customization job completes successfully, your custom model resource will be ready to use. Amazon Bedrock returns validation loss metrics and output generations after the job completes.

For information on the format of training and validation data, see Prepare the datasets.

Model-customization jobs are asynchronous and the completion time depends on the base model and the training/validation data size. To monitor a job, use the GetModelCustomizationJob operation to retrieve the job status.

For more information, see Custom models in the Amazon Bedrock User Guide.

Parameters:

  • job_name (JobName) –

    A name for the fine-tuning job.

  • custom_model_name (CustomModelName) –

    A name for the resulting custom model.

  • role_arn (RoleArn) –

    The Amazon Resource Name (ARN) of an IAM service role that Amazon Bedrock can assume to perform tasks on your behalf. For example, during model training, Amazon Bedrock needs your permission to read input data from an S3 bucket, write model artifacts to an S3 bucket. To pass this role to Amazon Bedrock, the caller of this API must have the iam:PassRole permission.

  • client_request_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency.

  • base_model_identifier (BaseModelIdentifier) –

    Name of the base model.

  • customization_type (Optional[CustomizationType], default: None ) –

    The customization type.

  • custom_model_kms_key_id (Optional[KmsKeyId], default: None ) –

    The custom model is encrypted at rest using this key.

  • job_tags (Optional[TagList], default: None ) –

    Tags to attach to the job.

  • custom_model_tags (Optional[TagList], default: None ) –

    Tags to attach to the resulting custom model.

  • training_data_config (TrainingDataConfig) –

    Information about the training dataset.

  • validation_data_config (Optional[ValidationDataConfig], default: None ) –

    Information about the validation dataset.

  • output_data_config (OutputDataConfig) –

    S3 location for the output data.

  • hyper_parameters (Optional[ModelCustomizationHyperParameters], default: None ) –

    Parameters related to tuning the model. For details on the format for different models, see Custom model hyperparameters.

  • vpc_config (Optional[VpcConfig], default: None ) –

    The configuration of the Virtual Private Cloud (VPC) that contains the resources that you're using for this job. For more information, see Protect your model customization jobs using a VPC.

  • customization_config (Optional[CustomizationConfig], default: None ) –

    The customization configuration for the model customization job.

Raises:

  • AccessDeniedException –

    The request is denied because of missing access permissions.

  • ConflictException –

    Error occurred because of a conflict while performing an operation.

  • InternalServerException –

    An internal server error occurred. Retry your request.

  • ResourceNotFoundException –

    The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

  • ServiceQuotaExceededException –

    The number of requests exceeds the service quota. Resubmit your request later.

  • ThrottlingException –

    The number of requests exceeds the limit. Resubmit your request later.

  • TooManyTagsException –

    The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request.

  • ValidationException –

    Input validation failed. Check your request parameters and retry the request.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_bedrock/_services/async_bedrock.py
async def create_model_customization_job(
    self,
    job_name: "capo_bedrock.types.job_name.JobName",
    custom_model_name: "capo_bedrock.types.custom_model_name.CustomModelName",
    role_arn: "capo_bedrock.types.role_arn.RoleArn",
    base_model_identifier: "capo_bedrock.types.base_model_identifier.BaseModelIdentifier",
    training_data_config: "capo_bedrock.types.training_data_config.TrainingDataConfig",
    output_data_config: "capo_bedrock.types.output_data_config.OutputDataConfig",
    *,
    config_overrides: Optional[AsyncBedrockClientConfig] = None,
    client_request_token: Optional[
        "capo_bedrock.types.idempotency_token.IdempotencyToken"
    ] = None,
    customization_type: Optional[
        "capo_bedrock.types.customization_type.CustomizationType"
    ] = None,
    custom_model_kms_key_id: Optional[
        "capo_bedrock.types.kms_key_id.KmsKeyId"
    ] = None,
    job_tags: Optional["capo_bedrock.types.tag_list.TagList"] = None,
    custom_model_tags: Optional["capo_bedrock.types.tag_list.TagList"] = None,
    validation_data_config: Optional[
        "capo_bedrock.types.validation_data_config.ValidationDataConfig"
    ] = None,
    hyper_parameters: Optional[
        "capo_bedrock.types.model_customization_hyper_parameters.ModelCustomizationHyperParameters"
    ] = None,
    vpc_config: Optional["capo_bedrock.types.vpc_config.VpcConfig"] = None,
    customization_config: Optional[
        "capo_bedrock.types.customization_config.CustomizationConfig"
    ] = None,
) -> "capo_bedrock.types.create_model_customization_job_response.CreateModelCustomizationJobResponse":
    """<p>Creates a fine-tuning job to customize a base model.</p> <p>You specify the base foundation model and the location of the training data. After the model-customization job completes successfully, your custom model resource will be ready to use. Amazon Bedrock returns validation loss metrics and output generations after the job completes. </p> <p>For information on the format of training and validation data, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html">Prepare the datasets</a>.</p> <p> Model-customization jobs are asynchronous and the completion time depends on the base model and the training/validation data size. To monitor a job, use the <code>GetModelCustomizationJob</code> operation to retrieve the job status.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/custom-models.html">Custom models</a> in the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html">Amazon Bedrock User Guide</a>.</p>

    Args:
        job_name: <p>A name for the fine-tuning job.</p>
        custom_model_name: <p>A name for the resulting custom model.</p>
        role_arn: <p>The Amazon Resource Name (ARN) of an IAM service role that Amazon Bedrock can assume to perform tasks on your behalf. For example, during model training, Amazon Bedrock needs your permission to read input data from an S3 bucket, write model artifacts to an S3 bucket. To pass this role to Amazon Bedrock, the caller of this API must have the <code>iam:PassRole</code> permission. </p>
        client_request_token: <p>A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p>
        base_model_identifier: <p>Name of the base model.</p>
        customization_type: <p>The customization type.</p>
        custom_model_kms_key_id: <p>The custom model is encrypted at rest using this key.</p>
        job_tags: <p>Tags to attach to the job.</p>
        custom_model_tags: <p>Tags to attach to the resulting custom model.</p>
        training_data_config: <p>Information about the training dataset.</p>
        validation_data_config: <p>Information about the validation dataset. </p>
        output_data_config: <p>S3 location for the output data.</p>
        hyper_parameters: <p>Parameters related to tuning the model. For details on the format for different models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/custom-models-hp.html">Custom model hyperparameters</a>.</p>
        vpc_config: <p>The configuration of the Virtual Private Cloud (VPC) that contains the resources that you're using for this job. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/vpc-model-customization.html">Protect your model customization jobs using a VPC</a>.</p>
        customization_config: <p>The customization configuration for the model customization job.</p>

    Raises:
        capo_bedrock.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
        capo_bedrock.errors.conflict_exception.ConflictException: <p>Error occurred because of a conflict while performing an operation.</p>
        capo_bedrock.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.</p>
        capo_bedrock.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock.errors.too_many_tags_exception.TooManyTagsException: <p>The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request. </p>
        capo_bedrock.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_bedrock.types.create_model_customization_job_request.CreateModelCustomizationJobRequest]",
    ) -> AsyncOperationResponse[
        "capo_bedrock.types.create_model_customization_job_response.CreateModelCustomizationJobResponse"
    ]:
        import capo_bedrock._operations.amazon_bedrock_control_plane_service.create_model_customization_job

        (
            output,
            http_response,
        ) = await capo_bedrock._operations.amazon_bedrock_control_plane_service.create_model_customization_job.async_create_model_customization_job(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock.types.create_model_customization_job_request.CreateModelCustomizationJobRequest",
    ) -> dict[str, Any]:
        import capo_bedrock.types.create_model_customization_job_request

        return capo_bedrock.types.create_model_customization_job_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateModelCustomizationJob", redact_input=_redact_input),
    )
    input_: capo_bedrock.types.create_model_customization_job_request.CreateModelCustomizationJobRequest = {
        "job_name": job_name,
        "custom_model_name": custom_model_name,
        "role_arn": role_arn,
        "base_model_identifier": base_model_identifier,
        "training_data_config": training_data_config,
        "output_data_config": output_data_config,
    }
    if client_request_token is None:
        client_request_token = str(uuid.uuid4())
    input_["client_request_token"] = client_request_token
    if customization_type is not None:
        input_["customization_type"] = customization_type
    if custom_model_kms_key_id is not None:
        input_["custom_model_kms_key_id"] = custom_model_kms_key_id
    if job_tags is not None:
        input_["job_tags"] = job_tags
    if custom_model_tags is not None:
        input_["custom_model_tags"] = custom_model_tags
    if validation_data_config is not None:
        input_["validation_data_config"] = validation_data_config
    if hyper_parameters is not None:
        input_["hyper_parameters"] = hyper_parameters
    if vpc_config is not None:
        input_["vpc_config"] = vpc_config
    if customization_config is not None:
        input_["customization_config"] = customization_config

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output