Skip to content

create_model_package async

create_model_package(
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    model_package_name: Optional[EntityName] = None,
    model_package_group_name: Optional[ArnOrName] = None,
    model_package_description: Optional[EntityDescription] = None,
    model_package_registration_type: Optional[ModelPackageRegistrationType] = None,
    inference_specification: Optional[InferenceSpecification] = None,
    validation_specification: Optional[ModelPackageValidationSpecification] = None,
    source_algorithm_specification: Optional[SourceAlgorithmSpecification] = None,
    certify_for_marketplace: Optional[CertifyForMarketplace] = None,
    tags: Optional[TagList] = None,
    model_approval_status: Optional[ModelApprovalStatus] = None,
    metadata_properties: Optional[MetadataProperties] = None,
    model_metrics: Optional[ModelMetrics] = None,
    client_token: Optional[ClientToken] = None,
    domain: Optional[String] = None,
    task: Optional[String] = None,
    sample_payload_url: Optional[S3Uri] = None,
    customer_metadata_properties: Optional[CustomerMetadataMap] = None,
    drift_check_baselines: Optional[DriftCheckBaselines] = None,
    additional_inference_specifications: Optional[
        AdditionalInferenceSpecifications
    ] = None,
    skip_model_validation: Optional[SkipModelValidation] = None,
    source_uri: Optional[ModelPackageSourceUri] = None,
    security_config: Optional[ModelPackageSecurityConfig] = None,
    model_card: Optional[ModelPackageModelCard] = None,
    model_life_cycle: Optional[ModelLifeCycle] = None,
    managed_storage_type: Optional[ManagedStorageType] = None,
) -> CreateModelPackageOutput

Creates a model package that you can use to create SageMaker models or list on Amazon Web Services Marketplace, or a versioned model that is part of a model group. Buyers can subscribe to model packages listed on Amazon Web Services Marketplace to create models in SageMaker.

To create a model package by specifying a Docker container that contains your inference code and the Amazon S3 location of your model artifacts, provide values for InferenceSpecification. To create a model from an algorithm resource that you created or subscribed to in Amazon Web Services Marketplace, provide a value for SourceAlgorithmSpecification.

There are two types of model packages:

  • Versioned - a model that is part of a model group in the model registry.

  • Unversioned - a model package that is not part of a model group.

Parameters:

  • model_package_name (Optional[EntityName], default: None ) –

    The name of the model package. The name must have 1 to 63 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen).

    This parameter is required for unversioned models. It is not applicable to versioned models.

  • model_package_group_name (Optional[ArnOrName], default: None ) –

    The name or Amazon Resource Name (ARN) of the model package group that this model version belongs to.

    This parameter is required for versioned models, and does not apply to unversioned models.

  • model_package_description (Optional[EntityDescription], default: None ) –

    A description of the model package.

  • model_package_registration_type (Optional[ModelPackageRegistrationType], default: None ) –

    The package registration type of the model package input.

  • inference_specification (Optional[InferenceSpecification], default: None ) –

    Specifies details about inference jobs that you can run with models based on this model package, including the following information:

    • The Amazon ECR paths of containers that contain the inference code and model artifacts.

    • The instance types that the model package supports for transform jobs and real-time endpoints used for inference.

    • The input and output content formats that the model package supports for inference.

  • validation_specification (Optional[ModelPackageValidationSpecification], default: None ) –

    Specifies configurations for one or more transform jobs that SageMaker runs to test the model package.

  • source_algorithm_specification (Optional[SourceAlgorithmSpecification], default: None ) –

    Details about the algorithm that was used to create the model package.

  • certify_for_marketplace (Optional[CertifyForMarketplace], default: None ) –

    Whether to certify the model package for listing on Amazon Web Services Marketplace.

    This parameter is optional for unversioned models, and does not apply to versioned models.

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

    A list of key value pairs associated with the model. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide.

    If you supply ModelPackageGroupName, your model package belongs to the model group you specify and uses the tags associated with the model group. In this case, you cannot supply a tag argument.

  • model_approval_status (Optional[ModelApprovalStatus], default: None ) –

    Whether the model is approved for deployment.

    This parameter is optional for versioned models, and does not apply to unversioned models.

    For versioned models, the value of this parameter must be set to Approved to deploy the model.

  • model_metrics (Optional[ModelMetrics], default: None ) –

    A structure that contains model metrics reports.

  • client_token (Optional[ClientToken], default: None ) –

    A unique token that guarantees that the call to this API is idempotent.

  • domain (Optional[String], default: None ) –

    The machine learning domain of your model package and its components. Common machine learning domains include computer vision and natural language processing.

  • task (Optional[String], default: None ) –

    The machine learning task your model package accomplishes. Common machine learning tasks include object detection and image classification. The following tasks are supported by Inference Recommender: "IMAGE_CLASSIFICATION" | "OBJECT_DETECTION" | "TEXT_GENERATION" |"IMAGE_SEGMENTATION" | "FILL_MASK" | "CLASSIFICATION" | "REGRESSION" | "OTHER".

    Specify "OTHER" if none of the tasks listed fit your use case.

  • sample_payload_url (Optional[S3Uri], default: None ) –

    The Amazon Simple Storage Service (Amazon S3) path where the sample payload is stored. This path must point to a single gzip compressed tar archive (.tar.gz suffix). This archive can hold multiple files that are all equally used in the load test. Each file in the archive must satisfy the size constraints of the InvokeEndpoint call.

  • customer_metadata_properties (Optional[CustomerMetadataMap], default: None ) –

    The metadata properties associated with the model package versions.

  • drift_check_baselines (Optional[DriftCheckBaselines], default: None ) –

    Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on Drift Detection against Previous Baselines in SageMaker Pipelines in the Amazon SageMaker Developer Guide.

  • additional_inference_specifications (Optional[AdditionalInferenceSpecifications], default: None ) –

    An array of additional Inference Specification objects. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts.

  • skip_model_validation (Optional[SkipModelValidation], default: None ) –

    Indicates if you want to skip model validation.

  • source_uri (Optional[ModelPackageSourceUri], default: None ) –

    The URI of the source for the model package. If you want to clone a model package, set it to the model package Amazon Resource Name (ARN). If you want to register a model, set it to the model ARN.

  • security_config (Optional[ModelPackageSecurityConfig], default: None ) –

    The KMS Key ID (KMSKeyId) used for encryption of model package information.

  • model_card (Optional[ModelPackageModelCard], default: None ) –

    The model card associated with the model package. Since ModelPackageModelCard is tied to a model package, it is a specific usage of a model card and its schema is simplified compared to the schema of ModelCard. The ModelPackageModelCard schema does not include model_package_details, and model_overview is composed of the model_creator and model_artifact properties. For more information about the model package model card schema, see Model package model card schema. For more information about the model card associated with the model package, see View the Details of a Model Version.

  • model_life_cycle (Optional[ModelLifeCycle], default: None ) –

    A structure describing the current state of the model in its life cycle.

  • managed_storage_type (Optional[ManagedStorageType], default: None ) –

    The storage type of the model package.

Raises:

  • ConflictException –

    There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact.

  • ResourceLimitExceeded –

    You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created.

  • UnknownServiceError –

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

Source code in docs_src/capo_sagemaker/_services/async_sage_maker.py
async def create_model_package(
    self,
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    model_package_name: Optional[
        "capo_sagemaker.types.entity_name.EntityName"
    ] = None,
    model_package_group_name: Optional[
        "capo_sagemaker.types.arn_or_name.ArnOrName"
    ] = None,
    model_package_description: Optional[
        "capo_sagemaker.types.entity_description.EntityDescription"
    ] = None,
    model_package_registration_type: Optional[
        "capo_sagemaker.types.model_package_registration_type.ModelPackageRegistrationType"
    ] = None,
    inference_specification: Optional[
        "capo_sagemaker.types.inference_specification.InferenceSpecification"
    ] = None,
    validation_specification: Optional[
        "capo_sagemaker.types.model_package_validation_specification.ModelPackageValidationSpecification"
    ] = None,
    source_algorithm_specification: Optional[
        "capo_sagemaker.types.source_algorithm_specification.SourceAlgorithmSpecification"
    ] = None,
    certify_for_marketplace: Optional[
        "capo_sagemaker.types.certify_for_marketplace.CertifyForMarketplace"
    ] = None,
    tags: Optional["capo_sagemaker.types.tag_list.TagList"] = None,
    model_approval_status: Optional[
        "capo_sagemaker.types.model_approval_status.ModelApprovalStatus"
    ] = None,
    metadata_properties: Optional[
        "capo_sagemaker.types.metadata_properties.MetadataProperties"
    ] = None,
    model_metrics: Optional[
        "capo_sagemaker.types.model_metrics.ModelMetrics"
    ] = None,
    client_token: Optional["capo_sagemaker.types.client_token.ClientToken"] = None,
    domain: Optional["capo_sagemaker.types.string.String"] = None,
    task: Optional["capo_sagemaker.types.string.String"] = None,
    sample_payload_url: Optional["capo_sagemaker.types.s3_uri.S3Uri"] = None,
    customer_metadata_properties: Optional[
        "capo_sagemaker.types.customer_metadata_map.CustomerMetadataMap"
    ] = None,
    drift_check_baselines: Optional[
        "capo_sagemaker.types.drift_check_baselines.DriftCheckBaselines"
    ] = None,
    additional_inference_specifications: Optional[
        "capo_sagemaker.types.additional_inference_specifications.AdditionalInferenceSpecifications"
    ] = None,
    skip_model_validation: Optional[
        "capo_sagemaker.types.skip_model_validation.SkipModelValidation"
    ] = None,
    source_uri: Optional[
        "capo_sagemaker.types.model_package_source_uri.ModelPackageSourceUri"
    ] = None,
    security_config: Optional[
        "capo_sagemaker.types.model_package_security_config.ModelPackageSecurityConfig"
    ] = None,
    model_card: Optional[
        "capo_sagemaker.types.model_package_model_card.ModelPackageModelCard"
    ] = None,
    model_life_cycle: Optional[
        "capo_sagemaker.types.model_life_cycle.ModelLifeCycle"
    ] = None,
    managed_storage_type: Optional[
        "capo_sagemaker.types.managed_storage_type.ManagedStorageType"
    ] = None,
) -> "capo_sagemaker.types.create_model_package_output.CreateModelPackageOutput":
    """<p>Creates a model package that you can use to create SageMaker models or list on Amazon Web Services Marketplace, or a versioned model that is part of a model group. Buyers can subscribe to model packages listed on Amazon Web Services Marketplace to create models in SageMaker.</p> <p>To create a model package by specifying a Docker container that contains your inference code and the Amazon S3 location of your model artifacts, provide values for <code>InferenceSpecification</code>. To create a model from an algorithm resource that you created or subscribed to in Amazon Web Services Marketplace, provide a value for <code>SourceAlgorithmSpecification</code>.</p> <note> <p>There are two types of model packages:</p> <ul> <li> <p>Versioned - a model that is part of a model group in the model registry.</p> </li> <li> <p>Unversioned - a model package that is not part of a model group.</p> </li> </ul> </note>

    Args:
        model_package_name: <p>The name of the model package. The name must have 1 to 63 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen).</p> <p>This parameter is required for unversioned models. It is not applicable to versioned models.</p>
        model_package_group_name: <p>The name or Amazon Resource Name (ARN) of the model package group that this model version belongs to.</p> <p>This parameter is required for versioned models, and does not apply to unversioned models.</p>
        model_package_description: <p>A description of the model package.</p>
        model_package_registration_type: <p> The package registration type of the model package input. </p>
        inference_specification: <p>Specifies details about inference jobs that you can run with models based on this model package, including the following information:</p> <ul> <li> <p>The Amazon ECR paths of containers that contain the inference code and model artifacts.</p> </li> <li> <p>The instance types that the model package supports for transform jobs and real-time endpoints used for inference.</p> </li> <li> <p>The input and output content formats that the model package supports for inference.</p> </li> </ul>
        validation_specification: <p>Specifies configurations for one or more transform jobs that SageMaker runs to test the model package.</p>
        source_algorithm_specification: <p>Details about the algorithm that was used to create the model package.</p>
        certify_for_marketplace: <p>Whether to certify the model package for listing on Amazon Web Services Marketplace.</p> <p>This parameter is optional for unversioned models, and does not apply to versioned models.</p>
        tags: <p>A list of key value pairs associated with the model. For more information, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html">Tagging Amazon Web Services resources</a> in the <i>Amazon Web Services General Reference Guide</i>.</p> <p>If you supply <code>ModelPackageGroupName</code>, your model package belongs to the model group you specify and uses the tags associated with the model group. In this case, you cannot supply a <code>tag</code> argument. </p>
        model_approval_status: <p>Whether the model is approved for deployment.</p> <p>This parameter is optional for versioned models, and does not apply to unversioned models.</p> <p>For versioned models, the value of this parameter must be set to <code>Approved</code> to deploy the model.</p>
        model_metrics: <p>A structure that contains model metrics reports.</p>
        client_token: <p>A unique token that guarantees that the call to this API is idempotent.</p>
        domain: <p>The machine learning domain of your model package and its components. Common machine learning domains include computer vision and natural language processing.</p>
        task: <p>The machine learning task your model package accomplishes. Common machine learning tasks include object detection and image classification. The following tasks are supported by Inference Recommender: <code>"IMAGE_CLASSIFICATION"</code> | <code>"OBJECT_DETECTION"</code> | <code>"TEXT_GENERATION"</code> |<code>"IMAGE_SEGMENTATION"</code> | <code>"FILL_MASK"</code> | <code>"CLASSIFICATION"</code> | <code>"REGRESSION"</code> | <code>"OTHER"</code>.</p> <p>Specify "OTHER" if none of the tasks listed fit your use case.</p>
        sample_payload_url: <p>The Amazon Simple Storage Service (Amazon S3) path where the sample payload is stored. This path must point to a single gzip compressed tar archive (.tar.gz suffix). This archive can hold multiple files that are all equally used in the load test. Each file in the archive must satisfy the size constraints of the <a href="https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html#API_runtime_InvokeEndpoint_RequestSyntax">InvokeEndpoint</a> call.</p>
        customer_metadata_properties: <p>The metadata properties associated with the model package versions.</p>
        drift_check_baselines: <p>Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-quality-clarify-baseline-lifecycle.html#pipelines-quality-clarify-baseline-drift-detection">Drift Detection against Previous Baselines in SageMaker Pipelines</a> in the <i>Amazon SageMaker Developer Guide</i>. </p>
        additional_inference_specifications: <p>An array of additional Inference Specification objects. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts. </p>
        skip_model_validation: <p>Indicates if you want to skip model validation.</p>
        source_uri: <p>The URI of the source for the model package. If you want to clone a model package, set it to the model package Amazon Resource Name (ARN). If you want to register a model, set it to the model ARN.</p>
        security_config: <p>The KMS Key ID (<code>KMSKeyId</code>) used for encryption of model package information.</p>
        model_card: <p>The model card associated with the model package. Since <code>ModelPackageModelCard</code> is tied to a model package, it is a specific usage of a model card and its schema is simplified compared to the schema of <code>ModelCard</code>. The <code>ModelPackageModelCard</code> schema does not include <code>model_package_details</code>, and <code>model_overview</code> is composed of the <code>model_creator</code> and <code>model_artifact</code> properties. For more information about the model package model card schema, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-details.html#model-card-schema">Model package model card schema</a>. For more information about the model card associated with the model package, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/model-registry-details.html">View the Details of a Model Version</a>.</p>
        model_life_cycle: <p> A structure describing the current state of the model in its life cycle. </p>
        managed_storage_type: <p>The storage type of the model package.</p>

    Raises:
        capo_sagemaker.errors.conflict_exception.ConflictException: <p>There was a conflict when you attempted to modify a SageMaker entity such as an <code>Experiment</code> or <code>Artifact</code>.</p>
        capo_sagemaker.errors.resource_limit_exceeded.ResourceLimitExceeded: <p> You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. </p>
        capo_sagemaker.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_sagemaker.types.create_model_package_input.CreateModelPackageInput]",
    ) -> AsyncOperationResponse[
        "capo_sagemaker.types.create_model_package_output.CreateModelPackageOutput"
    ]:
        import capo_sagemaker._operations.sage_maker.create_model_package

        (
            output,
            http_response,
        ) = await capo_sagemaker._operations.sage_maker.create_model_package.async_create_model_package(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sagemaker.types.create_model_package_input.CreateModelPackageInput",
    ) -> dict[str, Any]:
        import capo_sagemaker.types.create_model_package_input

        return capo_sagemaker.types.create_model_package_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateModelPackage", redact_input=_redact_input),
    )
    input_: capo_sagemaker.types.create_model_package_input.CreateModelPackageInput = {}
    if model_package_name is not None:
        input_["model_package_name"] = model_package_name
    if model_package_group_name is not None:
        input_["model_package_group_name"] = model_package_group_name
    if model_package_description is not None:
        input_["model_package_description"] = model_package_description
    if model_package_registration_type is not None:
        input_["model_package_registration_type"] = model_package_registration_type
    if inference_specification is not None:
        input_["inference_specification"] = inference_specification
    if validation_specification is not None:
        input_["validation_specification"] = validation_specification
    if source_algorithm_specification is not None:
        input_["source_algorithm_specification"] = source_algorithm_specification
    if certify_for_marketplace is not None:
        input_["certify_for_marketplace"] = certify_for_marketplace
    if tags is not None:
        input_["tags"] = tags
    if model_approval_status is not None:
        input_["model_approval_status"] = model_approval_status
    if metadata_properties is not None:
        input_["metadata_properties"] = metadata_properties
    if model_metrics is not None:
        input_["model_metrics"] = model_metrics
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if domain is not None:
        input_["domain"] = domain
    if task is not None:
        input_["task"] = task
    if sample_payload_url is not None:
        input_["sample_payload_url"] = sample_payload_url
    if customer_metadata_properties is not None:
        input_["customer_metadata_properties"] = customer_metadata_properties
    if drift_check_baselines is not None:
        input_["drift_check_baselines"] = drift_check_baselines
    if additional_inference_specifications is not None:
        input_["additional_inference_specifications"] = (
            additional_inference_specifications
        )
    if skip_model_validation is not None:
        input_["skip_model_validation"] = skip_model_validation
    if source_uri is not None:
        input_["source_uri"] = source_uri
    if security_config is not None:
        input_["security_config"] = security_config
    if model_card is not None:
        input_["model_card"] = model_card
    if model_life_cycle is not None:
        input_["model_life_cycle"] = model_life_cycle
    if managed_storage_type is not None:
        input_["managed_storage_type"] = managed_storage_type

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