@@ -4655,6 +4655,195 @@ def _intercept_create_request(
4655
4655
"""
4656
4656
return create (request )
4657
4657
4658
+ def _create_inference_recommendations_job_request (
4659
+ self ,
4660
+ role : str ,
4661
+ job_name : str ,
4662
+ job_description : str ,
4663
+ framework : str ,
4664
+ sample_payload_url : str ,
4665
+ supported_content_types : List [str ],
4666
+ model_package_version_arn : str = None ,
4667
+ job_duration_in_seconds : int = None ,
4668
+ job_type : str = "Default" ,
4669
+ framework_version : str = None ,
4670
+ nearest_model_name : str = None ,
4671
+ supported_instance_types : List [str ] = None ,
4672
+ endpoint_configurations : List [Dict [str , Any ]] = None ,
4673
+ traffic_pattern : Dict [str , Any ] = None ,
4674
+ stopping_conditions : Dict [str , Any ] = None ,
4675
+ resource_limit : Dict [str , Any ] = None ,
4676
+ ) -> Dict [str , Any ]:
4677
+ """Get request dictionary for CreateInferenceRecommendationsJob API.
4678
+
4679
+ Args:
4680
+ role (str): An AWS IAM role (either name or full ARN). The Amazon SageMaker training
4681
+ jobs and APIs that create Amazon SageMaker endpoints use this role to access
4682
+ training data and model artifacts.
4683
+ You must grant sufficient permissions to this role.
4684
+ job_name (str): The name of the Inference Recommendations Job.
4685
+ job_description (str): A description of the Inference Recommendations Job.
4686
+ framework (str): The machine learning framework of the Image URI.
4687
+ sample_payload_url (str): The S3 path where the sample payload is stored.
4688
+ supported_content_types (List[str]): The supported MIME types for the input data.
4689
+ model_package_version_arn (str): The Amazon Resource Name (ARN) of a
4690
+ versioned model package.
4691
+ job_duration_in_seconds (int): The maximum job duration that a job
4692
+ can run for. Will be used for `Advanced` jobs.
4693
+ job_type (str): The type of job being run. Must either be `Default` or `Advanced`.
4694
+ framework_version (str): The framework version of the Image URI.
4695
+ nearest_model_name (str): The name of a pre-trained machine learning model
4696
+ benchmarked by Amazon SageMaker Inference Recommender that matches your model.
4697
+ supported_instance_types (List[str]): A list of the instance types that are used
4698
+ to generate inferences in real-time.
4699
+ endpoint_configurations (List[Dict[str, any]]): Specifies the endpoint configurations
4700
+ to use for a job. Will be used for `Advanced` jobs.
4701
+ traffic_pattern (Dict[str, any]): Specifies the traffic pattern for the job.
4702
+ Will be used for `Advanced` jobs.
4703
+ stopping_conditions (Dict[str, any]): A set of conditions for stopping a
4704
+ recommendation job.
4705
+ If any of the conditions are met, the job is automatically stopped.
4706
+ Will be used for `Advanced` jobs.
4707
+ resource_limit (Dict[str, any]): Defines the resource limit for the job.
4708
+ Will be used for `Advanced` jobs.
4709
+ Returns:
4710
+ Dict[str, Any]: request dictionary for the CreateInferenceRecommendationsJob API
4711
+ """
4712
+
4713
+ containerConfig = {
4714
+ "Domain" : "MACHINE_LEARNING" ,
4715
+ "Task" : "OTHER" ,
4716
+ "Framework" : framework ,
4717
+ "PayloadConfig" : {
4718
+ "SamplePayloadUrl" : sample_payload_url ,
4719
+ "SupportedContentTypes" : supported_content_types ,
4720
+ },
4721
+ }
4722
+
4723
+ if framework_version :
4724
+ containerConfig ["FrameworkVersion" ] = framework_version
4725
+ if nearest_model_name :
4726
+ containerConfig ["NearestModelName" ] = nearest_model_name
4727
+ if supported_instance_types :
4728
+ containerConfig ["SupportedInstanceTypes" ] = supported_instance_types
4729
+
4730
+ request = {
4731
+ "JobName" : job_name ,
4732
+ "JobType" : job_type ,
4733
+ "RoleArn" : role ,
4734
+ "InputConfig" : {
4735
+ "ContainerConfig" : containerConfig ,
4736
+ "ModelPackageVersionArn" : model_package_version_arn ,
4737
+ },
4738
+ }
4739
+
4740
+ if job_description :
4741
+ request ["JobDescription" ] = job_description
4742
+ if job_duration_in_seconds :
4743
+ request ["InputConfig" ]["JobDurationInSeconds" ] = job_duration_in_seconds
4744
+
4745
+ if job_type == "Advanced" :
4746
+ if stopping_conditions :
4747
+ request ["StoppingConditions" ] = stopping_conditions
4748
+ if resource_limit :
4749
+ request ["InputConfig" ]["ResourceLimit" ] = resource_limit
4750
+ if traffic_pattern :
4751
+ request ["InputConfig" ]["TrafficPattern" ] = traffic_pattern
4752
+ if endpoint_configurations :
4753
+ request ["InputConfig" ]["EndpointConfigurations" ] = endpoint_configurations
4754
+
4755
+ return request
4756
+
4757
+ def create_inference_recommendations_job (
4758
+ self ,
4759
+ role : str ,
4760
+ sample_payload_url : str ,
4761
+ supported_content_types : List [str ],
4762
+ job_name : str = None ,
4763
+ job_type : str = "Default" ,
4764
+ model_package_version_arn : str = None ,
4765
+ job_duration_in_seconds : int = None ,
4766
+ nearest_model_name : str = None ,
4767
+ supported_instance_types : List [str ] = None ,
4768
+ framework : str = None ,
4769
+ framework_version : str = None ,
4770
+ endpoint_configurations : List [Dict [str , any ]] = None ,
4771
+ traffic_pattern : Dict [str , any ] = None ,
4772
+ stopping_conditions : Dict [str , any ] = None ,
4773
+ resource_limit : Dict [str , any ] = None ,
4774
+ ):
4775
+ """Creates an Inference Recommendations Job
4776
+
4777
+ Args:
4778
+ role (str): An AWS IAM role (either name or full ARN). The Amazon SageMaker training
4779
+ jobs and APIs that create Amazon SageMaker endpoints use this role to access
4780
+ training data and model artifacts.
4781
+ You must grant sufficient permissions to this role.
4782
+ sample_payload_url (str): The S3 path where the sample payload is stored.
4783
+ supported_content_types (List[str]): The supported MIME types for the input data.
4784
+ model_package_version_arn (str): The Amazon Resource Name (ARN) of a
4785
+ versioned model package.
4786
+ job_name (str): The name of the job being run.
4787
+ job_type (str): The type of job being run. Must either be `Default` or `Advanced`.
4788
+ job_duration_in_seconds (int): The maximum job duration that a job
4789
+ can run for. Will be used for `Advanced` jobs.
4790
+ nearest_model_name (str): The name of a pre-trained machine learning model
4791
+ benchmarked by Amazon SageMaker Inference Recommender that matches your model.
4792
+ supported_instance_types (List[str]): A list of the instance types that are used
4793
+ to generate inferences in real-time.
4794
+ framework (str): The machine learning framework of the Image URI.
4795
+ framework_version (str): The framework version of the Image URI.
4796
+ endpoint_configurations (List[Dict[str, any]]): Specifies the endpoint configurations
4797
+ to use for a job. Will be used for `Advanced` jobs.
4798
+ traffic_pattern (Dict[str, any]): Specifies the traffic pattern for the job.
4799
+ Will be used for `Advanced` jobs.
4800
+ stopping_conditions (Dict[str, any]): A set of conditions for stopping a
4801
+ recommendation job.
4802
+ If any of the conditions are met, the job is automatically stopped.
4803
+ Will be used for `Advanced` jobs.
4804
+ resource_limit (Dict[str, any]): Defines the resource limit for the job.
4805
+ Will be used for `Advanced` jobs.
4806
+ Returns:
4807
+ str: The name of the job created. In the form of `SMPYTHONSDK-<timestamp>`
4808
+ """
4809
+
4810
+ if not job_name :
4811
+ job_name = "SMPYTHONSDK-" + str (round (time .time ()))
4812
+ job_description = "#python-sdk-create"
4813
+
4814
+ create_inference_recommendations_job_request = (
4815
+ self ._create_inference_recommendations_job_request (
4816
+ role = role ,
4817
+ model_package_version_arn = model_package_version_arn ,
4818
+ job_name = job_name ,
4819
+ job_type = job_type ,
4820
+ job_duration_in_seconds = job_duration_in_seconds ,
4821
+ job_description = job_description ,
4822
+ framework = framework ,
4823
+ framework_version = framework_version ,
4824
+ nearest_model_name = nearest_model_name ,
4825
+ sample_payload_url = sample_payload_url ,
4826
+ supported_content_types = supported_content_types ,
4827
+ supported_instance_types = supported_instance_types ,
4828
+ endpoint_configurations = endpoint_configurations ,
4829
+ traffic_pattern = traffic_pattern ,
4830
+ stopping_conditions = stopping_conditions ,
4831
+ resource_limit = resource_limit ,
4832
+ )
4833
+ )
4834
+
4835
+ def submit (request ):
4836
+ LOGGER .info ("Creating Inference Recommendations job with name: %s" , job_name )
4837
+ LOGGER .debug ("process request: %s" , json .dumps (request , indent = 4 ))
4838
+ self .sagemaker_client .create_inference_recommendations_job (** request )
4839
+
4840
+ self ._intercept_create_request (
4841
+ create_inference_recommendations_job_request ,
4842
+ submit ,
4843
+ self .create_inference_recommendations_job .__name__ ,
4844
+ )
4845
+ return job_name
4846
+
4658
4847
4659
4848
def get_model_package_args (
4660
4849
content_types ,
0 commit comments