code: def multi_variant_endpoint(sagemaker_session):
      """
      Sets up the multi variant endpoint before the integration tests run.
      Cleans up the multi variant endpoint after the integration tests run.
      """
      multi_variant_endpoint.endpoint_name = unique_name_from_base(
          "integ-test-multi-variant-endpoint"
      )
      with tests.integ.timeout.timeout_and_delete_endpoint_by_name(
          endpoint_name=multi_variant_endpoint.endpoint_name,
          sagemaker_session=sagemaker_session,
          hours=2,
      ):
          # Creating a model
          bucket = sagemaker_session.default_bucket()
          prefix = "sagemaker/DEMO-VariantTargeting"
          model_url = S3Uploader.upload(
              local_path=XG_BOOST_MODEL_LOCAL_PATH,
              desired_s3_uri="s3://{}/{}".format(bucket, prefix),
              sagemaker_session=sagemaker_session,
          )
  
          image_uri = image_uris.retrieve(
              "xgboost",
              sagemaker_session.boto_region_name,
              version="0.90-1",
              instance_type=DEFAULT_INSTANCE_TYPE,
              image_scope="inference",
          )
          multi_variant_endpoint_model = sagemaker_session.create_model(
              name=MODEL_NAME,
              role=ROLE,
              container_defs={
                  "Image": image_uri,
                  "ModelDataUrl": model_url,
              },
          )
  
          # Creating a multi variant endpoint
          variant1 = production_variant(
              model_name=MODEL_NAME,
              instance_type=DEFAULT_INSTANCE_TYPE,
              initial_instance_count=DEFAULT_INSTANCE_COUNT,
              variant_name=TEST_VARIANT_1,
              initial_weight=TEST_VARIANT_1_WEIGHT,
          )
          variant2 = production_variant(
              model_name=MODEL_NAME,
              instance_type=DEFAULT_INSTANCE_TYPE,
              initial_instance_count=DEFAULT_INSTANCE_COUNT,
              variant_name=TEST_VARIANT_2,
              initial_weight=TEST_VARIANT_2_WEIGHT,
          )
          sagemaker_session.endpoint_from_production_variants(
              name=multi_variant_endpoint.endpoint_name,
              production_variants=[variant1, variant2],
          )
  
          # Yield to run the integration tests
          yield multi_variant_endpoint
  
          # Cleanup resources
          sagemaker_session.delete_model(multi_variant_endpoint_model)
          sagemaker_session.sagemaker_client.delete_endpoint_config(
              EndpointConfigName=multi_variant_endpoint.endpoint_name
          )
  
      # Validate resource cleanup
      with pytest.raises(Exception) as exception:
          sagemaker_session.sagemaker_client.describe_model(
              ModelName=multi_variant_endpoint_model.name
          )
          assert "Could not find model" in str(exception.value)
          sagemaker_session.sagemaker_client.describe_endpoint_config(
              name=multi_variant_endpoint.endpoint_name
          )
          assert "Could not find endpoint" in str(exception.value)
  
imports: from __future__ import absolute_import
  import json
  import math
  import os
  import pytest
  import scipy.stats
  from sagemaker import image_uris
  from sagemaker.deserializers import CSVDeserializer
  from sagemaker.s3 import S3Uploader
  from sagemaker.session import production_variant
  from sagemaker.sparkml import SparkMLModel
  from sagemaker.utils import unique_name_from_base
  from sagemaker.predictor import Predictor
  from sagemaker.serializers import CSVSerializer
  import tests.integ
label_desc: Use image node_id 1 for calling a global function with example usage: multi_variant_endpoint(sagemaker_session) without return types