def deploy( self, initial_instance_count, instance_type, candidate=None, sagemaker_session=None, name=None, endpoint_name=None, tags=None, wait=True, update_endpoint=False, vpc_config=None, enable_network_isolation=False, model_kms_key=None, ): """Deploy a candidate to a SageMaker Inference Pipeline and return a Predictor Args: initial_instance_count (int): The initial number of instances to run in the ``Endpoint`` created from this ``Model``. instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge'. candidate (CandidateEstimator or dict): a CandidateEstimator used for deploying to a SageMaker Inference Pipeline. If None, the best candidate will be used. If the candidate input is a dict, a CandidateEstimator will be created from it. sagemaker_session (sagemaker.session.Session): A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain. name (str): The pipeline model name. If None, a default model name will be selected on each ``deploy``. endpoint_name (str): The name of the endpoint to create (default: None). If not specified, a unique endpoint name will be created. tags (List[dict[str, str]]): The list of tags to attach to this specific endpoint. wait (bool): Whether the call should wait until the deployment of model completes (default: True). update_endpoint (bool): Flag to update the model in an existing Amazon SageMaker endpoint. If True, this will deploy a new EndpointConfig to an already existing endpoint and delete resources corresponding to the previous EndpointConfig. If False, a new endpoint will be created. Default: False vpc_config (dict): Specifies a VPC that your training jobs and hosted models have access to. Contents include "SecurityGroupIds" and "Subnets". enable_network_isolation (bool): Isolates the training container. No inbound or outbound network calls can be made, except for calls between peers within a training cluster for distributed training. Default: False model_kms_key (str): KMS key ARN used to encrypt the repacked model archive file if the model is repacked Returns: callable[string, sagemaker.session.Session]: Invocation of ``self.predictor_cls`` on the created endpoint name. """ if candidate is None: candidate_dict = self.best_candidate() candidate = CandidateEstimator(candidate_dict, sagemaker_session=sagemaker_session) elif isinstance(candidate, dict): candidate = CandidateEstimator(candidate, sagemaker_session=sagemaker_session) inference_containers = candidate.containers endpoint_name = endpoint_name or self.current_job_name return self._deploy_inference_pipeline( inference_containers, initial_instance_count=initial_instance_count, instance_type=instance_type, name=name, sagemaker_session=sagemaker_session, endpoint_name=endpoint_name, tags=tags, wait=wait, update_endpoint=update_endpoint, vpc_config=vpc_config, enable_network_isolation=enable_network_isolation, model_kms_key=model_kms_key, )
def create_model( self, name, sagemaker_session=None, candidate=None, vpc_config=None, enable_network_isolation=False, model_kms_key=None, predictor_cls=None, inference_response_keys=None, ): """Creates a model from a given candidate or the best candidate from the automl job Args: name (str): The pipeline model name. sagemaker_session (sagemaker.session.Session): A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, the one originally associated with the ``AutoML`` instance is used.: candidate (CandidateEstimator or dict): a CandidateEstimator used for deploying to a SageMaker Inference Pipeline. If None, the best candidate will be used. If the candidate input is a dict, a CandidateEstimator will be created from it. vpc_config (dict): Specifies a VPC that your training jobs and hosted models have access to. Contents include "SecurityGroupIds" and "Subnets". enable_network_isolation (bool): Isolates the training container. No inbound or outbound network calls can be made, except for calls between peers within a training cluster for distributed training. Default: False model_kms_key (str): KMS key ARN used to encrypt the repacked model archive file if the model is repacked predictor_cls (callable[string, sagemaker.session.Session]): A function to call to create a predictor (default: None). If specified, ``deploy()`` returns the result of invoking this function on the created endpoint name. inference_response_keys (list): List of keys for response content. The order of the keys will dictate the content order in the response. Returns: PipelineModel object """ sagemaker_session = sagemaker_session or self.sagemaker_session if candidate is None: candidate_dict = self.best_candidate() candidate = CandidateEstimator(candidate_dict, sagemaker_session=sagemaker_session) elif isinstance(candidate, dict): candidate = CandidateEstimator(candidate, sagemaker_session=sagemaker_session) inference_containers = candidate.containers self.validate_and_update_inference_response(inference_containers, inference_response_keys) # construct Model objects models = [] for container in inference_containers: image_uri = container["Image"] model_data = container["ModelDataUrl"] env = container["Environment"] model = Model( image_uri=image_uri, model_data=model_data, role=self.role, env=env, vpc_config=vpc_config, sagemaker_session=sagemaker_session or self.sagemaker_session, enable_network_isolation=enable_network_isolation, model_kms_key=model_kms_key, ) models.append(model) pipeline = PipelineModel( models=models, role=self.role, predictor_cls=predictor_cls, name=name, vpc_config=vpc_config, sagemaker_session=sagemaker_session or self.sagemaker_session, ) return pipeline