class_docstr: A mixin class for SageMaker ``Inference Recommender`` that will be extended by ``Model``
class_docstr_tok: ["A","mixin","class","for","SageMaker","``","Inference","Recommender","``","that","will","be","extended","by","``","Model","``"]
docstr: Recommends an instance type for a SageMaker or BYOC model.
  
  Create a SageMaker ``Model`` or use a registered ``ModelPackage``,
  to start an Inference Recommender job.
  
  The name of the created model is accessible in the ``name`` field of
  this ``Model`` after right_size returns.
  
  Args:
      sample_payload_url (str): The S3 path where the sample payload is stored.
      supported_content_types: (list[str]): The supported MIME types for the input data.
      supported_instance_types (list[str]): A list of the instance types that this model
          is expected to work on. (default: None).
      job_name (str): The name of the Inference Recommendations Job. (default: None).
      framework (str): The machine learning framework of the Image URI.
          Only required to specify if you bring your own custom containers (default: None).
      job_duration_in_seconds (int): The maximum job duration that a job can run for.
          (default: None).
      hyperparameter_ranges (list[Dict[str, sagemaker.parameter.CategoricalParameter]]):
          Specifies the hyper parameters to be used during endpoint load tests.
          `instance_type` must be specified as a hyperparameter range.
          `env_vars` can be specified as an optional hyperparameter range. (default: None).
          Example::
  
              hyperparameter_ranges = [{
                  'instance_types': CategoricalParameter(['ml.c5.xlarge', 'ml.c5.2xlarge']),
                  'OMP_NUM_THREADS': CategoricalParameter(['1', '2', '3', '4'])
              }]
  
      phases (list[Phase]): Shape of the traffic pattern to use in the load test
          (default: None).
      traffic_type (str): Specifies the traffic pattern type. Currently only supports
          one type 'PHASES' (default: None).
      max_invocations (str): defines the minimum invocations per minute for the endpoint
          to support (default: None).
      model_latency_thresholds (list[ModelLatencyThreshold]): defines the maximum response
          latency for endpoints to support (default: None).
      max_tests (int): restricts how many endpoints in total are allowed to be
          spun up for this job (default: None).
      max_parallel_tests (int): restricts how many concurrent endpoints
          this job is allowed to spin up (default: None).
      log_level (str): specifies the inline output when waiting for right_size to complete
          (default: "Verbose").
  
  Returns:
      sagemaker.model.Model: A SageMaker ``Model`` object. See
      :func:`~sagemaker.model.Model` for full details.
docstr_tok: ["Recommends","an","instance","type","for","a","SageMaker","or","BYOC","model",".","Create","a","SageMaker","``","Model","``","or","use","a","registered","``","ModelPackage","``",",","to","start","an","Inference","Recommender","job",".","The","name","of","the","created","model","is","accessible","in","the","``","name","``","field","of","this","``","Model","``","after","right_size","returns",".","Args",":","sample_payload_url","(","str",")",":","The","S3","path","where","the","sample","payload","is","stored",".","supported_content_types",":","(","list","[","str","]",")",":","The","supported","MIME","types","for","the","input","data",".","supported_instance_types","(","list","[","str","]",")",":","A","list","of","the","instance","types","that","this","model","is","expected","to","work","on",".","(","default",":","None",")",".","job_name","(","str",")",":","The","name","of","the","Inference","Recommendations","Job",".","(","default",":","None",")",".","framework","(","str",")",":","The","machine","learning","framework","of","the","Image","URI",".","Only","required","to","specify","if","you","bring","your","own","custom","containers","(","default",":","None",")",".","job_duration_in_seconds","(","int",")",":","The","maximum","job","duration","that","a","job","can","run","for",".","(","default",":","None",")",".","hyperparameter_ranges","(","list","[","Dict","[","str",",","sagemaker.parameter.CategoricalParameter","]","]",")",":","Specifies","the","hyper","parameters","to","be","used","during","endpoint","load","tests",".","`","instance_type","`","must","be","specified","as","a","hyperparameter","range",".","`","env_vars","`","can","be","specified","as","an","optional","hyperparameter","range",".","(","default",":","None",")",".","Example",":",":","hyperparameter_ranges","=","[","{","'instance_types","'",":","CategoricalParameter","(","[","'ml.c5.xlarge","'",",","'ml.c5.2xlarge","'","]",")",",","'OMP_NUM_THREADS","'",":","CategoricalParameter","(","[","'","1","'",",","'","2","'",",","'","3","'",",","'","4","'","]",")","}","]","phases","(","list","[","Phase","]",")",":","Shape","of","the","traffic","pattern","to","use","in","the","load","test","(","default",":","None",")",".","traffic_type","(","str",")",":","Specifies","the","traffic","pattern","type",".","Currently","only","supports","one","type","'PHASES","'","(","default",":","None",")",".","max_invocations","(","str",")",":","defines","the","minimum","invocations","per","minute","for","the","endpoint","to","support","(","default",":","None",")",".","model_latency_thresholds","(","list","[","ModelLatencyThreshold","]",")",":","defines","the","maximum","response","latency","for","endpoints","to","support","(","default",":","None",")",".","max_tests","(","int",")",":","restricts","how","many","endpoints","in","total","are","allowed","to","be","spun","up","for","this","job","(","default",":","None",")",".","max_parallel_tests","(","int",")",":","restricts","how","many","concurrent","endpoints","this","job","is","allowed","to","spin","up","(","default",":","None",")",".","log_level","(","str",")",":","specifies","the","inline","output","when","waiting","for","right_size","to","complete","(","default",":","``","Verbose","''",")",".","Returns",":","sagemaker.model.Model",":","A","SageMaker","``","Model","``","object",".","See",":","func",":","`","~sagemaker.model.Model","`","for","full","details","."]
code: def right_size(
      self,
      sample_payload_url: str = None,
      supported_content_types: List[str] = None,
      supported_instance_types: List[str] = None,
      job_name: str = None,
      framework: str = None,
      job_duration_in_seconds: int = None,
      hyperparameter_ranges: List[
          Dict[str, CategoricalParameter]
      ] = None,
      phases: List[Phase] = None,
      traffic_type: str = None,
      max_invocations: int = None,
      model_latency_thresholds: List[ModelLatencyThreshold] = None,
      max_tests: int = None,
      max_parallel_tests: int = None,
      log_level: Optional[str] = "Verbose",
  ):
      """Recommends an instance type for a SageMaker or BYOC model.
  
      Create a SageMaker ``Model`` or use a registered ``ModelPackage``,
      to start an Inference Recommender job.
  
      The name of the created model is accessible in the ``name`` field of
      this ``Model`` after right_size returns.
  
      Args:
          sample_payload_url (str): The S3 path where the sample payload is stored.
          supported_content_types: (list[str]): The supported MIME types for the input data.
          supported_instance_types (list[str]): A list of the instance types that this model
              is expected to work on. (default: None).
          job_name (str): The name of the Inference Recommendations Job. (default: None).
          framework (str): The machine learning framework of the Image URI.
              Only required to specify if you bring your own custom containers (default: None).
          job_duration_in_seconds (int): The maximum job duration that a job can run for.
              (default: None).
          hyperparameter_ranges (list[Dict[str, sagemaker.parameter.CategoricalParameter]]):
              Specifies the hyper parameters to be used during endpoint load tests.
              `instance_type` must be specified as a hyperparameter range.
              `env_vars` can be specified as an optional hyperparameter range. (default: None).
              Example::
  
                  hyperparameter_ranges = [{
                      'instance_types': CategoricalParameter(['ml.c5.xlarge', 'ml.c5.2xlarge']),
                      'OMP_NUM_THREADS': CategoricalParameter(['1', '2', '3', '4'])
                  }]
  
          phases (list[Phase]): Shape of the traffic pattern to use in the load test
              (default: None).
          traffic_type (str): Specifies the traffic pattern type. Currently only supports
              one type 'PHASES' (default: None).
          max_invocations (str): defines the minimum invocations per minute for the endpoint
              to support (default: None).
          model_latency_thresholds (list[ModelLatencyThreshold]): defines the maximum response
              latency for endpoints to support (default: None).
          max_tests (int): restricts how many endpoints in total are allowed to be
              spun up for this job (default: None).
          max_parallel_tests (int): restricts how many concurrent endpoints
              this job is allowed to spin up (default: None).
          log_level (str): specifies the inline output when waiting for right_size to complete
              (default: "Verbose").
  
      Returns:
          sagemaker.model.Model: A SageMaker ``Model`` object. See
          :func:`~sagemaker.model.Model` for full details.
      """
  
      if not framework and self._framework():
          framework = INFERENCE_RECOMMENDER_FRAMEWORK_MAPPING.get(
              self._framework(), framework
          )
  
      framework_version = self._get_framework_version()
  
      endpoint_configurations = (
          self._convert_to_endpoint_configurations_json(
              hyperparameter_ranges=hyperparameter_ranges
          )
      )
      traffic_pattern = self._convert_to_traffic_pattern_json(
          traffic_type=traffic_type, phases=phases
      )
      stopping_conditions = self._convert_to_stopping_conditions_json(
          max_invocations=max_invocations,
          model_latency_thresholds=model_latency_thresholds,
      )
      resource_limit = self._convert_to_resource_limit_json(
          max_tests=max_tests, max_parallel_tests=max_parallel_tests
      )
  
      if (
          endpoint_configurations
          or traffic_pattern
          or stopping_conditions
          or resource_limit
      ):
          logger.info(
              "Advanced Job parameters were specified. Running Advanced job..."
          )
          job_type = "Advanced"
      else:
          logger.info(
              "Advanced Job parameters were not specified. Running Default job..."
          )
          job_type = "Default"
  
      self._init_sagemaker_session_if_does_not_exist()
  
      if isinstance(self, sagemaker.model.Model) and not isinstance(
          self, sagemaker.model.ModelPackage
      ):
          primary_container_def = self.prepare_container_def()
          if not self.name:
              self._ensure_base_name_if_needed(
                  image_uri=primary_container_def["Image"],
                  script_uri=self.source_dir,
                  model_uri=self.model_data,
              )
              self._set_model_name_if_needed()
  
          create_model_args = dict(
              name=self.name,
              role=self.role,
              container_defs=None,
              primary_container=primary_container_def,
              vpc_config=self.vpc_config,
              enable_network_isolation=self.enable_network_isolation(),
          )
          logger.warning(
              "Attempting to create new model with name %s", self.name
          )
          self.sagemaker_session.create_model(**create_model_args)
  
      ret_name = (
          self.sagemaker_session.create_inference_recommendations_job(
              role=self.role,
              job_name=job_name,
              job_type=job_type,
              job_duration_in_seconds=job_duration_in_seconds,
              model_name=self.name,
              model_package_version_arn=getattr(
                  self, "model_package_arn", None
              ),
              framework=framework,
              framework_version=framework_version,
              sample_payload_url=sample_payload_url,
              supported_content_types=supported_content_types,
              supported_instance_types=supported_instance_types,
              endpoint_configurations=endpoint_configurations,
              traffic_pattern=traffic_pattern,
              stopping_conditions=stopping_conditions,
              resource_limit=resource_limit,
          )
      )
  
      self.inference_recommender_job_results = (
          self.sagemaker_session.wait_for_inference_recommendations_job(
              ret_name, log_level=log_level
          )
      )
      self.inference_recommendations = (
          self.inference_recommender_job_results.get(
              "InferenceRecommendations"
          )
      )
  
      return self
  
imports: from __future__ import absolute_import
  import logging
  import re
  from typing import List, Dict, Optional
  import sagemaker
  from sagemaker.parameter import CategoricalParameter
label_desc: Use image node_id 1 for calling the InferenceRecommenderMixin obj's underlying member method code with example usage: obj.right_size(sample_payload_url, supported_content_types, supported_instance_types, job_name, framework, job_duration_in_seconds, hyperparameter_ranges, phases, traffic_type, max_invocations, model_latency_thresholds, max_tests, max_parallel_tests, log_level) and returns: self