Skip to content

Commit 82efce9

Browse files
author
Balaji Veeramani
committed
Update deploy method
1 parent 3e3bee8 commit 82efce9

File tree

6 files changed

+85
-19
lines changed

6 files changed

+85
-19
lines changed

src/sagemaker/automl/automl.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ def deploy(
337337
self,
338338
initial_instance_count,
339339
instance_type,
340+
serializer=None,
341+
deserializer=None,
340342
candidate=None,
341343
sagemaker_session=None,
342344
name=None,
@@ -356,6 +358,14 @@ def deploy(
356358
in the ``Endpoint`` created from this ``Model``.
357359
instance_type (str): The EC2 instance type to deploy this Model to.
358360
For example, 'ml.p2.xlarge'.
361+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
362+
serializer object, used to encode data for an inference endpoint
363+
(default: None). If ``serializer`` is not None, then
364+
``serializer`` will override the default serializer.
365+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
366+
deserializer object, used to decode data from an inference
367+
endpoint (default: None). If ``deserializer`` is not None, then
368+
``deserializer`` will override the default deserializer.
359369
candidate (CandidateEstimator or dict): a CandidateEstimator used for deploying
360370
to a SageMaker Inference Pipeline. If None, the best candidate will
361371
be used. If the candidate input is a dict, a CandidateEstimator will be
@@ -405,6 +415,8 @@ def deploy(
405415
return model.deploy(
406416
initial_instance_count=initial_instance_count,
407417
instance_type=instance_type,
418+
serializer=serializer,
419+
deserializer=deserializer,
408420
endpoint_name=endpoint_name,
409421
tags=tags,
410422
wait=wait,

src/sagemaker/estimator.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ def deploy(
644644
self,
645645
initial_instance_count,
646646
instance_type,
647+
serializer=None,
648+
deserializer=None,
647649
accelerator_type=None,
648650
endpoint_name=None,
649651
use_compiled_model=False,
@@ -665,6 +667,14 @@ def deploy(
665667
deploy to an endpoint for prediction.
666668
instance_type (str): Type of EC2 instance to deploy to an endpoint
667669
for prediction, for example, 'ml.c4.xlarge'.
670+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
671+
serializer object, used to encode data for an inference endpoint
672+
(default: None). If ``serializer`` is not None, then
673+
``serializer`` will override the default serializer.
674+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
675+
deserializer object, used to decode data from an inference
676+
endpoint (default: None). If ``deserializer`` is not None, then
677+
``deserializer`` will override the default deserializer.
668678
accelerator_type (str): Type of Elastic Inference accelerator to
669679
attach to an endpoint for model loading and inference, for
670680
example, 'ml.eia1.medium'. If not specified, no Elastic
@@ -727,6 +737,8 @@ def deploy(
727737
return model.deploy(
728738
instance_type=instance_type,
729739
initial_instance_count=initial_instance_count,
740+
serializer=serializer,
741+
deserializer=deserializer,
730742
accelerator_type=accelerator_type,
731743
endpoint_name=endpoint_name,
732744
tags=tags or self.tags,
@@ -1341,10 +1353,6 @@ def create_model(
13411353
role=None,
13421354
image_uri=None,
13431355
predictor_cls=None,
1344-
serializer=None,
1345-
deserializer=None,
1346-
content_type=None,
1347-
accept=None,
13481356
vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT,
13491357
**kwargs
13501358
):
@@ -1362,17 +1370,6 @@ def create_model(
13621370
Defaults to the image used for training.
13631371
predictor_cls (Predictor): The predictor class to use when
13641372
deploying the model.
1365-
serializer (callable): Should accept a single argument, the input
1366-
data, and return a sequence of bytes. May provide a content_type
1367-
attribute that defines the endpoint request content type
1368-
deserializer (callable): Should accept two arguments, the result
1369-
data and the response content type, and return a sequence of
1370-
bytes. May provide a content_type attribute that defines th
1371-
endpoint response Accept content type.
1372-
content_type (str): The invocation ContentType, overriding any
1373-
content_type from the serializer
1374-
accept (str): The invocation Accept, overriding any accept from the
1375-
deserializer.
13761373
vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on
13771374
the model.
13781375
Default: use subnets and security groups from this Estimator.
@@ -1391,7 +1388,7 @@ def create_model(
13911388
if predictor_cls is None:
13921389

13931390
def predict_wrapper(endpoint, session):
1394-
return Predictor(endpoint, session, serializer, deserializer, content_type, accept)
1391+
return Predictor(endpoint, session)
13951392

13961393
predictor_cls = predict_wrapper
13971394

src/sagemaker/model.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ def deploy(
420420
self,
421421
initial_instance_count,
422422
instance_type,
423+
serializer=None,
424+
deserializer=None,
423425
accelerator_type=None,
424426
endpoint_name=None,
425427
tags=None,
@@ -446,6 +448,14 @@ def deploy(
446448
in the ``Endpoint`` created from this ``Model``.
447449
instance_type (str): The EC2 instance type to deploy this Model to.
448450
For example, 'ml.p2.xlarge', or 'local' for local mode.
451+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
452+
serializer object, used to encode data for an inference endpoint
453+
(default: None). If ``serializer`` is not None, then
454+
``serializer`` will override the default serializer.
455+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
456+
deserializer object, used to decode data from an inference
457+
endpoint (default: None). If ``deserializer`` is not None, then
458+
``deserializer`` will override the default deserializer.
449459
accelerator_type (str): Type of Elastic Inference accelerator to
450460
deploy this model for model loading and inference, for example,
451461
'ml.eia1.medium'. If not specified, no Elastic Inference
@@ -512,7 +522,12 @@ def deploy(
512522
)
513523

514524
if self.predictor_cls:
515-
return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
525+
predictor = self.predictor_cls(self.endpoint_name, self.sagemaker_session)
526+
if serializer:
527+
predictor.serializer = serializer
528+
if deserializer:
529+
predictor.deserializer = deserializer
530+
return predictor
516531
return None
517532

518533
def transformer(

src/sagemaker/multidatamodel.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def deploy(
143143
self,
144144
initial_instance_count,
145145
instance_type,
146+
serializer=None,
147+
deserializer=None,
146148
accelerator_type=None,
147149
endpoint_name=None,
148150
tags=None,
@@ -171,6 +173,14 @@ def deploy(
171173
in the ``Endpoint`` created from this ``Model``.
172174
instance_type (str): The EC2 instance type to deploy this Model to.
173175
For example, 'ml.p2.xlarge', or 'local' for local mode.
176+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
177+
serializer object, used to encode data for an inference endpoint
178+
(default: None). If ``serializer`` is not None, then
179+
``serializer`` will override the default serializer.
180+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
181+
deserializer object, used to decode data from an inference
182+
endpoint (default: None). If ``deserializer`` is not None, then
183+
``deserializer`` will override the default deserializer.
174184
accelerator_type (str): Type of Elastic Inference accelerator to
175185
deploy this model for model loading and inference, for example,
176186
'ml.eia1.medium'. If not specified, no Elastic Inference
@@ -246,7 +256,12 @@ def deploy(
246256
)
247257

248258
if predictor:
249-
return predictor(self.endpoint_name, self.sagemaker_session)
259+
predictor = self.predictor_cls(self.endpoint_name, self.sagemaker_session)
260+
if serializer:
261+
predictor.serializer = serializer
262+
if deserializer:
263+
predictor.deserializer = deserializer
264+
return predictor
250265
return None
251266

252267
def add_model(self, model_data_source, model_data_path=None):

src/sagemaker/pipeline.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def deploy(
8585
self,
8686
initial_instance_count,
8787
instance_type,
88+
serializer=None,
89+
deserializer=None,
8890
endpoint_name=None,
8991
tags=None,
9092
wait=True,
@@ -110,6 +112,14 @@ def deploy(
110112
in the ``Endpoint`` created from this ``Model``.
111113
instance_type (str): The EC2 instance type to deploy this Model to.
112114
For example, 'ml.p2.xlarge'.
115+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
116+
serializer object, used to encode data for an inference endpoint
117+
(default: None). If ``serializer`` is not None, then
118+
``serializer`` will override the default serializer.
119+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
120+
deserializer object, used to decode data from an inference
121+
endpoint (default: None). If ``deserializer`` is not None, then
122+
``deserializer`` will override the default deserializer.
113123
endpoint_name (str): The name of the endpoint to create (default:
114124
None). If not specified, a unique endpoint name will be created.
115125
tags (List[dict[str, str]]): The list of tags to attach to this
@@ -171,7 +181,12 @@ def deploy(
171181
)
172182

173183
if self.predictor_cls:
174-
return self.predictor_cls(self.endpoint_name, self.sagemaker_session)
184+
predictor = self.predictor_cls(self.endpoint_name, self.sagemaker_session)
185+
if serializer:
186+
predictor.serializer = serializer
187+
if deserializer:
188+
predictor.deserializer = deserializer
189+
return predictor
175190
return None
176191

177192
def _create_sagemaker_pipeline_model(self, instance_type):

src/sagemaker/tuner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ def deploy(
672672
self,
673673
initial_instance_count,
674674
instance_type,
675+
serializer=None,
676+
deserializer=None,
675677
accelerator_type=None,
676678
endpoint_name=None,
677679
wait=True,
@@ -691,6 +693,14 @@ def deploy(
691693
deploy to an endpoint for prediction.
692694
instance_type (str): Type of EC2 instance to deploy to an endpoint
693695
for prediction, for example, 'ml.c4.xlarge'.
696+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
697+
serializer object, used to encode data for an inference endpoint
698+
(default: None). If ``serializer`` is not None, then
699+
``serializer`` will override the default serializer.
700+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
701+
deserializer object, used to decode data from an inference
702+
endpoint (default: None). If ``deserializer`` is not None, then
703+
``deserializer`` will override the default deserializer.
694704
accelerator_type (str): Type of Elastic Inference accelerator to
695705
attach to an endpoint for model loading and inference, for
696706
example, 'ml.eia1.medium'. If not specified, no Elastic
@@ -725,6 +735,8 @@ def deploy(
725735
return best_estimator.deploy(
726736
initial_instance_count=initial_instance_count,
727737
instance_type=instance_type,
738+
serializer=serializer,
739+
deserializer=deserializer,
728740
accelerator_type=accelerator_type,
729741
endpoint_name=endpoint_name or best_training_job["TrainingJobName"],
730742
wait=wait,

0 commit comments

Comments
 (0)