From 7bbd09a933d593d48dbe4aefbfa53b3bcd3b1573 Mon Sep 17 00:00:00 2001 From: Dan Choi Date: Tue, 26 Feb 2019 12:38:22 -0800 Subject: [PATCH 1/3] pass accelerator_type for tfs model --- src/sagemaker/fw_utils.py | 2 +- src/sagemaker/tensorflow/deploying_python.rst | 2 +- src/sagemaker/tensorflow/deploying_tensorflow_serving.rst | 2 ++ src/sagemaker/tensorflow/serving.py | 6 +++--- tests/unit/test_tfs.py | 8 ++++++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sagemaker/fw_utils.py b/src/sagemaker/fw_utils.py index 7fddc40757..013786405a 100644 --- a/src/sagemaker/fw_utils.py +++ b/src/sagemaker/fw_utils.py @@ -106,7 +106,7 @@ def _accelerator_type_valid_for_framework(framework, accelerator_type=None, opti if framework not in VALID_EIA_FRAMEWORKS: raise ValueError('{} is not supported with Amazon Elastic Inference. Currently only ' - 'TensorFlow and MXNet are supported for SageMaker.'.format(framework)) + 'Python-based TensorFlow and MXNet are supported for SageMaker.'.format(framework)) if optimized_families: raise ValueError('Neo does not support Amazon Elastic Inference.') diff --git a/src/sagemaker/tensorflow/deploying_python.rst b/src/sagemaker/tensorflow/deploying_python.rst index fdacbdd92b..7722e5124a 100644 --- a/src/sagemaker/tensorflow/deploying_python.rst +++ b/src/sagemaker/tensorflow/deploying_python.rst @@ -25,7 +25,7 @@ like this: The code block above deploys a SageMaker Endpoint with one instance of the type 'ml.c4.xlarge'. -TensorFlow serving on SageMaker has support for `Elastic Inference `_, which allows for inference acceleration to a hosted endpoint for a fraction of the cost of using a full GPU instance. In order to attach an Elastic Inference accelerator to your endpoint provide the accelerator type to ``accelerator_type`` to your ``deploy`` call. +Python-based TensorFlow serving on SageMaker has support for `Elastic Inference `_, which allows for inference acceleration to a hosted endpoint for a fraction of the cost of using a full GPU instance. In order to attach an Elastic Inference accelerator to your endpoint provide the accelerator type to ``accelerator_type`` to your ``deploy`` call. .. code:: python diff --git a/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst b/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst index 30de627a37..31d32c585c 100644 --- a/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst +++ b/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst @@ -34,6 +34,8 @@ estimator object to create a SageMaker Endpoint: The code block above deploys a SageMaker Endpoint with one instance of the type 'ml.c5.xlarge'. +As of now, only the Python based TensorFlow serving endpoints support Elastic Inference. For more information, see `Deploying to Python-based Endpoints `_. + What happens when deploy is called ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/sagemaker/tensorflow/serving.py b/src/sagemaker/tensorflow/serving.py index dd923ea0ef..9e141e5728 100644 --- a/src/sagemaker/tensorflow/serving.py +++ b/src/sagemaker/tensorflow/serving.py @@ -123,7 +123,7 @@ def __init__(self, model_data, role, image=None, framework_version=TF_VERSION, self._container_log_level = container_log_level def prepare_container_def(self, instance_type, accelerator_type=None): - image = self._get_image_uri(instance_type) + image = self._get_image_uri(instance_type, accelerator_type) env = self._get_container_env() return sagemaker.container_def(image, self.model_data, env) @@ -139,10 +139,10 @@ def _get_container_env(self): env[Model.LOG_LEVEL_PARAM_NAME] = Model.LOG_LEVEL_MAP[self._container_log_level] return env - def _get_image_uri(self, instance_type): + def _get_image_uri(self, instance_type, accelerator_type=None): if self.image: return self.image region_name = self.sagemaker_session.boto_region_name return create_image_uri(region_name, Model.FRAMEWORK_NAME, instance_type, - self._framework_version) + self._framework_version, accelerator_type=accelerator_type) diff --git a/tests/unit/test_tfs.py b/tests/unit/test_tfs.py index 77f68561a2..a5b6e84962 100644 --- a/tests/unit/test_tfs.py +++ b/tests/unit/test_tfs.py @@ -25,6 +25,7 @@ CSV_CONTENT_TYPE = 'text/csv' INSTANCE_COUNT = 1 INSTANCE_TYPE = 'ml.c4.4xlarge' +ACCELERATOR_TYPE = 'ml.eia.medium' ROLE = 'Dummy' REGION = 'us-west-2' PREDICT_INPUT = {'instances': [1.0, 2.0, 5.0]} @@ -75,6 +76,13 @@ def test_tfs_model(sagemaker_session, tf_version): assert isinstance(predictor, Predictor) +def test_tfs_model_image_accelerator(sagemaker_session, tf_version): + model = Model("s3://some/data.tar.gz", role=ROLE, framework_version=tf_version, + sagemaker_session=sagemaker_session) + with pytest.raises(ValueError): + model.prepare_container_def(INSTANCE_TYPE, accelerator_type=ACCELERATOR_TYPE) + + def test_tfs_model_with_log_level(sagemaker_session, tf_version): model = Model("s3://some/data.tar.gz", role=ROLE, framework_version=tf_version, container_log_level=logging.INFO, From 3c2b607e7a184e39ea3ae8d31c257a00206fc881 Mon Sep 17 00:00:00 2001 From: Dan Choi Date: Tue, 26 Feb 2019 12:43:28 -0800 Subject: [PATCH 2/3] update changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a7757cad0f..ee964caff6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ CHANGELOG * doc-fix: Remove incorrect parameter for EI TFS Python README * feature: ``Predictor``: delete SageMaker model * feature: ``Pipeline``: delete SageMaker model +* bug-fix: pass accelerator_type in ``deploy`` for REST API TFS ``Model`` 1.18.3.post1 ============ From 2066597200f17fbd5f082909c79f8eb0861ab026 Mon Sep 17 00:00:00 2001 From: Dan Choi Date: Tue, 26 Feb 2019 13:06:42 -0800 Subject: [PATCH 3/3] address comments --- src/sagemaker/fw_utils.py | 2 +- src/sagemaker/tensorflow/deploying_tensorflow_serving.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sagemaker/fw_utils.py b/src/sagemaker/fw_utils.py index 013786405a..e3183f1cbf 100644 --- a/src/sagemaker/fw_utils.py +++ b/src/sagemaker/fw_utils.py @@ -106,7 +106,7 @@ def _accelerator_type_valid_for_framework(framework, accelerator_type=None, opti if framework not in VALID_EIA_FRAMEWORKS: raise ValueError('{} is not supported with Amazon Elastic Inference. Currently only ' - 'Python-based TensorFlow and MXNet are supported for SageMaker.'.format(framework)) + 'Python-based TensorFlow and MXNet are supported.'.format(framework)) if optimized_families: raise ValueError('Neo does not support Amazon Elastic Inference.') diff --git a/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst b/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst index 31d32c585c..be42aa2731 100644 --- a/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst +++ b/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst @@ -34,7 +34,7 @@ estimator object to create a SageMaker Endpoint: The code block above deploys a SageMaker Endpoint with one instance of the type 'ml.c5.xlarge'. -As of now, only the Python based TensorFlow serving endpoints support Elastic Inference. For more information, see `Deploying to Python-based Endpoints `_. +As of now, only the Python-based TensorFlow serving endpoints support Elastic Inference. For more information, see `Deploying to Python-based Endpoints `_. What happens when deploy is called ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^