Skip to content

create_inference_experiment async

create_inference_experiment(
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    name: Optional[InferenceExperimentName] = None,
    type: Optional[InferenceExperimentType] = None,
    schedule: Optional[InferenceExperimentSchedule] = None,
    description: Optional[InferenceExperimentDescription] = None,
    role_arn: Optional[RoleArn] = None,
    endpoint_name: Optional[EndpointName] = None,
    model_variants: Optional[ModelVariantConfigList] = None,
    data_storage_config: Optional[InferenceExperimentDataStorageConfig] = None,
    shadow_mode_config: Optional[ShadowModeConfig] = None,
    kms_key: Optional[KmsKeyId] = None,
    tags: Optional[TagList] = None,
) -> CreateInferenceExperimentResponse

Creates an inference experiment using the configurations specified in the request.

Use this API to setup and schedule an experiment to compare model variants on a Amazon SageMaker inference endpoint. For more information about inference experiments, see Shadow tests.

Amazon SageMaker begins your experiment at the scheduled time and routes traffic to your endpoint's model variants based on your specified configuration.

While the experiment is in progress or after it has concluded, you can view metrics that compare your model variants. For more information, see View, monitor, and edit shadow tests.

Parameters:

  • name (Optional[InferenceExperimentName], default: None ) –

    The name for the inference experiment.

  • type (Optional[InferenceExperimentType], default: None ) –

    The type of the inference experiment that you want to run. The following types of experiments are possible:

    • ShadowMode: You can use this type to validate a shadow variant. For more information, see Shadow tests.

  • schedule (Optional[InferenceExperimentSchedule], default: None ) –

    The duration for which you want the inference experiment to run. If you don't specify this field, the experiment automatically starts immediately upon creation and concludes after 7 days.

  • description (Optional[InferenceExperimentDescription], default: None ) –

    A description for the inference experiment.

  • role_arn (Optional[RoleArn], default: None ) –

    The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment.

  • endpoint_name (Optional[EndpointName], default: None ) –

    The name of the Amazon SageMaker endpoint on which you want to run the inference experiment.

  • model_variants (Optional[ModelVariantConfigList], default: None ) –

    An array of ModelVariantConfig objects. There is one for each variant in the inference experiment. Each ModelVariantConfig object in the array describes the infrastructure configuration for the corresponding variant.

  • data_storage_config (Optional[InferenceExperimentDataStorageConfig], default: None ) –

    The Amazon S3 location and configuration for storing inference request and response data.

    This is an optional parameter that you can use for data capture. For more information, see Capture data.

  • shadow_mode_config (Optional[ShadowModeConfig], default: None ) –

    The configuration of ShadowMode inference experiment type. Use this field to specify a production variant which takes all the inference requests, and a shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant also specify the percentage of requests that Amazon SageMaker replicates.

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

    The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The KmsKey can be any of the following formats:

    • KMS key ID

      "1234abcd-12ab-34cd-56ef-1234567890ab"

    • Amazon Resource Name (ARN) of a KMS key

      "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"

    • KMS key Alias

      "alias/ExampleAlias"

    • Amazon Resource Name (ARN) of a KMS key Alias

      "arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias"

    If you use a KMS key ID or an alias of your KMS key, the Amazon SageMaker execution role must include permissions to call kms:Encrypt. If you don't provide a KMS key ID, Amazon SageMaker uses the default KMS key for Amazon S3 for your role's account. Amazon SageMaker uses server-side encryption with KMS managed keys for OutputDataConfig. If you use a bucket policy with an s3:PutObject permission that only allows objects with server-side encryption, set the condition key of s3:x-amz-server-side-encryption to "aws:kms". For more information, see KMS managed Encryption Keys in the Amazon Simple Storage Service Developer Guide.

    The KMS key policy must grant permission to the IAM role that you specify in your CreateEndpoint and UpdateEndpoint requests. For more information, see Using Key Policies in Amazon Web Services KMS in the Amazon Web Services Key Management Service Developer Guide.

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

    Array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging your Amazon Web Services Resources.

Raises:

  • ResourceInUse –

    Resource being accessed is in use.

  • 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_inference_experiment(
    self,
    *,
    config_overrides: Optional[AsyncSageMakerClientConfig] = None,
    name: Optional[
        "capo_sagemaker.types.inference_experiment_name.InferenceExperimentName"
    ] = None,
    type: Optional[
        "capo_sagemaker.types.inference_experiment_type.InferenceExperimentType"
    ] = None,
    schedule: Optional[
        "capo_sagemaker.types.inference_experiment_schedule.InferenceExperimentSchedule"
    ] = None,
    description: Optional[
        "capo_sagemaker.types.inference_experiment_description.InferenceExperimentDescription"
    ] = None,
    role_arn: Optional["capo_sagemaker.types.role_arn.RoleArn"] = None,
    endpoint_name: Optional[
        "capo_sagemaker.types.endpoint_name.EndpointName"
    ] = None,
    model_variants: Optional[
        "capo_sagemaker.types.model_variant_config_list.ModelVariantConfigList"
    ] = None,
    data_storage_config: Optional[
        "capo_sagemaker.types.inference_experiment_data_storage_config.InferenceExperimentDataStorageConfig"
    ] = None,
    shadow_mode_config: Optional[
        "capo_sagemaker.types.shadow_mode_config.ShadowModeConfig"
    ] = None,
    kms_key: Optional["capo_sagemaker.types.kms_key_id.KmsKeyId"] = None,
    tags: Optional["capo_sagemaker.types.tag_list.TagList"] = None,
) -> "capo_sagemaker.types.create_inference_experiment_response.CreateInferenceExperimentResponse":
    """<p> Creates an inference experiment using the configurations specified in the request. </p> <p> Use this API to setup and schedule an experiment to compare model variants on a Amazon SageMaker inference endpoint. For more information about inference experiments, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/shadow-tests.html">Shadow tests</a>. </p> <p> Amazon SageMaker begins your experiment at the scheduled time and routes traffic to your endpoint's model variants based on your specified configuration. </p> <p> While the experiment is in progress or after it has concluded, you can view metrics that compare your model variants. For more information, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/shadow-tests-view-monitor-edit.html">View, monitor, and edit shadow tests</a>. </p>

    Args:
        name: <p>The name for the inference experiment.</p>
        type: <p> The type of the inference experiment that you want to run. The following types of experiments are possible: </p> <ul> <li> <p> <code>ShadowMode</code>: You can use this type to validate a shadow variant. For more information, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/shadow-tests.html">Shadow tests</a>. </p> </li> </ul>
        schedule: <p> The duration for which you want the inference experiment to run. If you don't specify this field, the experiment automatically starts immediately upon creation and concludes after 7 days. </p>
        description: <p>A description for the inference experiment.</p>
        role_arn: <p> The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment. </p>
        endpoint_name: <p> The name of the Amazon SageMaker endpoint on which you want to run the inference experiment. </p>
        model_variants: <p> An array of <code>ModelVariantConfig</code> objects. There is one for each variant in the inference experiment. Each <code>ModelVariantConfig</code> object in the array describes the infrastructure configuration for the corresponding variant. </p>
        data_storage_config: <p> The Amazon S3 location and configuration for storing inference request and response data. </p> <p> This is an optional parameter that you can use for data capture. For more information, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor-data-capture.html">Capture data</a>. </p>
        shadow_mode_config: <p> The configuration of <code>ShadowMode</code> inference experiment type. Use this field to specify a production variant which takes all the inference requests, and a shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant also specify the percentage of requests that Amazon SageMaker replicates. </p>
        kms_key: <p> The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The <code>KmsKey</code> can be any of the following formats: </p> <ul> <li> <p>KMS key ID</p> <p> <code>"1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> <li> <p>Amazon Resource Name (ARN) of a KMS key</p> <p> <code>"arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> <li> <p>KMS key Alias</p> <p> <code>"alias/ExampleAlias"</code> </p> </li> <li> <p>Amazon Resource Name (ARN) of a KMS key Alias</p> <p> <code>"arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias"</code> </p> </li> </ul> <p> If you use a KMS key ID or an alias of your KMS key, the Amazon SageMaker execution role must include permissions to call <code>kms:Encrypt</code>. If you don't provide a KMS key ID, Amazon SageMaker uses the default KMS key for Amazon S3 for your role's account. Amazon SageMaker uses server-side encryption with KMS managed keys for <code>OutputDataConfig</code>. If you use a bucket policy with an <code>s3:PutObject</code> permission that only allows objects with server-side encryption, set the condition key of <code>s3:x-amz-server-side-encryption</code> to <code>"aws:kms"</code>. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html">KMS managed Encryption Keys</a> in the <i>Amazon Simple Storage Service Developer Guide.</i> </p> <p> The KMS key policy must grant permission to the IAM role that you specify in your <code>CreateEndpoint</code> and <code>UpdateEndpoint</code> requests. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html">Using Key Policies in Amazon Web Services KMS</a> in the <i>Amazon Web Services Key Management Service Developer Guide</i>. </p>
        tags: <p> Array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see <a href="https://docs.aws.amazon.com/ARG/latest/userguide/tagging.html">Tagging your Amazon Web Services Resources</a>. </p>

    Raises:
        capo_sagemaker.errors.resource_in_use.ResourceInUse: <p>Resource being accessed is in use.</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_inference_experiment_request.CreateInferenceExperimentRequest]",
    ) -> AsyncOperationResponse[
        "capo_sagemaker.types.create_inference_experiment_response.CreateInferenceExperimentResponse"
    ]:
        import capo_sagemaker._operations.sage_maker.create_inference_experiment

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateInferenceExperiment")
    )
    input_: capo_sagemaker.types.create_inference_experiment_request.CreateInferenceExperimentRequest = {}
    if name is not None:
        input_["name"] = name
    if type is not None:
        input_["type"] = type
    if schedule is not None:
        input_["schedule"] = schedule
    if description is not None:
        input_["description"] = description
    if role_arn is not None:
        input_["role_arn"] = role_arn
    if endpoint_name is not None:
        input_["endpoint_name"] = endpoint_name
    if model_variants is not None:
        input_["model_variants"] = model_variants
    if data_storage_config is not None:
        input_["data_storage_config"] = data_storage_config
    if shadow_mode_config is not None:
        input_["shadow_mode_config"] = shadow_mode_config
    if kms_key is not None:
        input_["kms_key"] = kms_key
    if tags is not None:
        input_["tags"] = tags

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