Skip to content

breaking: Remove the content_types module #1744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doc/v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ Please use :func:`sagemaker.predictor.Predictor.delete_endpoint` instead.
The ``update_endpoint`` argument in ``deploy()`` methods for estimators and models has been deprecated.
Please use :func:`sagemaker.predictor.Predictor.update_endpoint` instead.

``sagemaker.content_types``
---------------------------

The ``sagemaker.content_types`` module is removed in v2.0 and later of the
SageMaker Python SDK.

Instead of importing constants from ``sagemaker.content_types``, explicitly
write MIME types as a string,

+-------------------------------+--------------------------------+
| v1.x | v2.0 and later |
+===============================+================================+
| ``CONTENT_TYPE_JSON`` | ``"application/json"`` |
+-------------------------------+--------------------------------+
| ``CONTENT_TYPE_CSV`` | ``"text/csv"`` |
+-------------------------------+--------------------------------+
| ``CONTENT_TYPE_OCTET_STREAM`` | ``"application/octet-stream"`` |
+-------------------------------+--------------------------------+
| ``CONTENT_TYPE_NPY`` | ``"application/x-npy"`` |
+-------------------------------+--------------------------------+


Require ``framework_version`` and ``py_version`` for Frameworks
===============================================================

Expand Down
19 changes: 0 additions & 19 deletions src/sagemaker/content_types.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/sagemaker/sparkml/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from __future__ import absolute_import

from sagemaker import Model, Predictor, Session, image_uris
from sagemaker.content_types import CONTENT_TYPE_CSV
from sagemaker.serializers import CSVSerializer

framework_name = "sparkml-serving"
Expand Down Expand Up @@ -50,7 +49,7 @@ def __init__(self, endpoint_name, sagemaker_session=None):
endpoint_name=endpoint_name,
sagemaker_session=sagemaker_session,
serializer=CSVSerializer(),
content_type=CONTENT_TYPE_CSV,
content_type="text/csv",
)


Expand Down
3 changes: 1 addition & 2 deletions src/sagemaker/tensorflow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import sagemaker
from sagemaker import image_uris
from sagemaker.content_types import CONTENT_TYPE_JSON
from sagemaker.deserializers import JSONDeserializer
from sagemaker.predictor import Predictor
from sagemaker.serializers import JSONSerializer
Expand Down Expand Up @@ -96,7 +95,7 @@ def _classify_or_regress(self, data, method):
if method not in ["classify", "regress"]:
raise ValueError("invalid TensorFlow Serving method: {}".format(method))

if self.content_type != CONTENT_TYPE_JSON:
if self.content_type != "application/json":
raise ValueError("The {} api requires json requests.".format(method))

args = {"CustomAttributes": "tfs-method={}".format(method)}
Expand Down
9 changes: 3 additions & 6 deletions tests/integ/test_inference_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)

from sagemaker import image_uris
from sagemaker.content_types import CONTENT_TYPE_CSV
from sagemaker.model import Model
from sagemaker.pipeline import PipelineModel
from sagemaker.predictor import Predictor
Expand Down Expand Up @@ -87,9 +86,7 @@ def test_inference_pipeline_batch_transform(sagemaker_session, cpu_instance_type
with timeout_and_delete_model_with_transformer(
transformer, sagemaker_session, minutes=TRANSFORM_DEFAULT_TIMEOUT_MINUTES
):
transformer.transform(
transform_input, content_type=CONTENT_TYPE_CSV, job_name=batch_job_name
)
transformer.transform(transform_input, content_type="text/csv", job_name=batch_job_name)
transformer.wait()


Expand Down Expand Up @@ -134,8 +131,8 @@ def test_inference_pipeline_model_deploy(sagemaker_session, cpu_instance_type):
endpoint_name=endpoint_name,
sagemaker_session=sagemaker_session,
serializer=JSONSerializer,
content_type=CONTENT_TYPE_CSV,
accept=CONTENT_TYPE_CSV,
content_type="text/csv",
accept="text/csv",
)

with open(VALID_DATA_PATH, "r") as f:
Expand Down
29 changes: 14 additions & 15 deletions tests/integ/test_multi_variant_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from sagemaker.s3 import S3Uploader
from sagemaker.session import production_variant
from sagemaker.sparkml import SparkMLModel
from sagemaker.content_types import CONTENT_TYPE_CSV
from sagemaker.utils import unique_name_from_base
from sagemaker.predictor import Predictor
from sagemaker.serializers import CSVSerializer
Expand Down Expand Up @@ -153,17 +152,17 @@ def test_target_variant_invocation(sagemaker_session, multi_variant_endpoint):
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
EndpointName=multi_variant_endpoint.endpoint_name,
Body=TEST_CSV_DATA,
ContentType=CONTENT_TYPE_CSV,
Accept=CONTENT_TYPE_CSV,
ContentType="text/csv",
Accept="text/csv",
TargetVariant=TEST_VARIANT_1,
)
assert response["InvokedProductionVariant"] == TEST_VARIANT_1

response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
EndpointName=multi_variant_endpoint.endpoint_name,
Body=TEST_CSV_DATA,
ContentType=CONTENT_TYPE_CSV,
Accept=CONTENT_TYPE_CSV,
ContentType="text/csv",
Accept="text/csv",
TargetVariant=TEST_VARIANT_2,
)
assert response["InvokedProductionVariant"] == TEST_VARIANT_2
Expand All @@ -174,8 +173,8 @@ def test_predict_invocation_with_target_variant(sagemaker_session, multi_variant
endpoint_name=multi_variant_endpoint.endpoint_name,
sagemaker_session=sagemaker_session,
serializer=CSVSerializer(),
content_type=CONTENT_TYPE_CSV,
accept=CONTENT_TYPE_CSV,
content_type="text/csv",
accept="text/csv",
)

# Validate that no exception is raised when the target_variant is specified.
Expand All @@ -191,8 +190,8 @@ def test_variant_traffic_distribution(sagemaker_session, multi_variant_endpoint)
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
EndpointName=multi_variant_endpoint.endpoint_name,
Body=TEST_CSV_DATA,
ContentType=CONTENT_TYPE_CSV,
Accept=CONTENT_TYPE_CSV,
ContentType="text/csv",
Accept="text/csv",
)
if response["InvokedProductionVariant"] == TEST_VARIANT_1:
variant_1_invocation_count += 1
Expand Down Expand Up @@ -274,17 +273,17 @@ def test_target_variant_invocation_local_mode(sagemaker_session, multi_variant_e
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
EndpointName=multi_variant_endpoint.endpoint_name,
Body=TEST_CSV_DATA,
ContentType=CONTENT_TYPE_CSV,
Accept=CONTENT_TYPE_CSV,
ContentType="text/csv",
Accept="text/csv",
TargetVariant=TEST_VARIANT_1,
)
assert response["InvokedProductionVariant"] == TEST_VARIANT_1

response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
EndpointName=multi_variant_endpoint.endpoint_name,
Body=TEST_CSV_DATA,
ContentType=CONTENT_TYPE_CSV,
Accept=CONTENT_TYPE_CSV,
ContentType="text/csv",
Accept="text/csv",
TargetVariant=TEST_VARIANT_2,
)
assert response["InvokedProductionVariant"] == TEST_VARIANT_2
Expand All @@ -302,8 +301,8 @@ def test_predict_invocation_with_target_variant_local_mode(
endpoint_name=multi_variant_endpoint.endpoint_name,
sagemaker_session=sagemaker_session,
serializer=CSVSerializer(),
content_type=CONTENT_TYPE_CSV,
accept=CONTENT_TYPE_CSV,
content_type="text/csv",
accept="text/csv",
)

# Validate that no exception is raised when the target_variant is specified.
Expand Down
3 changes: 1 addition & 2 deletions tests/integ/test_tuner_multi_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from sagemaker import image_uris, utils
from sagemaker.analytics import HyperparameterTuningJobAnalytics
from sagemaker.content_types import CONTENT_TYPE_JSON
from sagemaker.deserializers import JSONDeserializer
from sagemaker.estimator import Estimator
from sagemaker.tuner import ContinuousParameter, IntegerParameter, HyperparameterTuner
Expand Down Expand Up @@ -215,7 +214,7 @@ def _create_training_inputs(sagemaker_session):

def _make_prediction(predictor, data):
predictor.serializer = _prediction_data_serializer
predictor.content_type = CONTENT_TYPE_JSON
predictor.content_type = "application/json"
predictor.deserializer = JSONDeserializer()
return predictor.predict(data)

Expand Down