@@ -319,7 +319,7 @@ def delete_endpoint(self):
319319
320320 def transformer (self , instance_count , instance_type , strategy = None , assemble_with = None , output_path = None ,
321321 output_kms_key = None , accept = None , env = None , max_concurrent_transforms = None ,
322- max_payload = None , tags = None ):
322+ max_payload = None , tags = None , role = None ):
323323 """Return a ``Transformer`` that uses a SageMaker Model based on the training job. It reuses the
324324 SageMaker Session and base job name used by the Estimator.
325325
@@ -339,10 +339,12 @@ def transformer(self, instance_count, instance_type, strategy=None, assemble_wit
339339 max_payload (int): Maximum size of the payload in a single HTTP request to the container in MB.
340340 tags (list[dict]): List of tags for labeling a transform job. If none specified, then the tags used for
341341 the training job are used for the transform job.
342+ role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during
343+ transform jobs. If not specified, the role from the Estimator will be used.
342344 """
343345 self ._ensure_latest_training_job ()
344346
345- model_name = self .sagemaker_session .create_model_from_job (self .latest_training_job .name )
347+ model_name = self .sagemaker_session .create_model_from_job (self .latest_training_job .name , role = role )
346348 tags = tags or self .tags
347349
348350 return Transformer (model_name , instance_count , instance_type , strategy = strategy , assemble_with = assemble_with ,
@@ -476,12 +478,14 @@ def hyperparameters(self):
476478 """
477479 return self .hyperparam_dict
478480
479- def create_model (self , image = None , predictor_cls = None , serializer = None , deserializer = None ,
481+ def create_model (self , role = None , image = None , predictor_cls = None , serializer = None , deserializer = None ,
480482 content_type = None , accept = None , ** kwargs ):
481483 """
482484 Create a model to deploy.
483485
484486 Args:
487+ role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during
488+ transform jobs. If not specified, the role from the Estimator will be used.
485489 image (str): An container image to use for deploying the model. Defaults to the image used for training.
486490 predictor_cls (RealTimePredictor): The predictor class to use when deploying the model.
487491 serializer (callable): Should accept a single argument, the input data, and return a sequence
@@ -503,7 +507,9 @@ def predict_wrapper(endpoint, session):
503507 return RealTimePredictor (endpoint , session , serializer , deserializer , content_type , accept )
504508 predictor_cls = predict_wrapper
505509
506- return Model (self .model_data , image or self .train_image (), self .role , sagemaker_session = self .sagemaker_session ,
510+ role = role or self .role
511+
512+ return Model (self .model_data , image or self .train_image (), role , sagemaker_session = self .sagemaker_session ,
507513 predictor_cls = predictor_cls , ** kwargs )
508514
509515 @classmethod
@@ -737,7 +743,7 @@ def _update_init_params(cls, hp, tf_arguments):
737743
738744 def transformer (self , instance_count , instance_type , strategy = None , assemble_with = None , output_path = None ,
739745 output_kms_key = None , accept = None , env = None , max_concurrent_transforms = None ,
740- max_payload = None , tags = None , model_server_workers = None ):
746+ max_payload = None , tags = None , role = None , model_server_workers = None ):
741747 """Return a ``Transformer`` that uses a SageMaker Model based on the training job. It reuses the
742748 SageMaker Session and base job name used by the Estimator.
743749
@@ -757,16 +763,19 @@ def transformer(self, instance_count, instance_type, strategy=None, assemble_wit
757763 max_payload (int): Maximum size of the payload in a single HTTP request to the container in MB.
758764 tags (list[dict]): List of tags for labeling a transform job. If none specified, then the tags used for
759765 the training job are used for the transform job.
766+ role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during
767+ transform jobs. If not specified, the role from the Estimator will be used.
760768 model_server_workers (int): Optional. The number of worker processes used by the inference server.
761769 If None, server will use one worker per vCPU.
762770 """
763771 self ._ensure_latest_training_job ()
772+ role = role or self .role
764773
765- model = self .create_model (model_server_workers = model_server_workers )
774+ model = self .create_model (role = role , model_server_workers = model_server_workers )
766775
767776 container_def = model .prepare_container_def (instance_type )
768777 model_name = model .name or name_from_image (container_def ['Image' ])
769- self .sagemaker_session .create_model (model_name , self . role , container_def )
778+ self .sagemaker_session .create_model (model_name , role , container_def )
770779
771780 transform_env = model .env .copy ()
772781 if env is not None :
0 commit comments