Skip to content

feature: TensorFlow 2.4 for Neo #2861

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 12 commits into from
Mar 3, 2022
2 changes: 1 addition & 1 deletion doc/doc_utils/jumpstart_doc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_jumpstart_model_table():
file_content.append(" - Latest Version\n")
file_content.append(" - Min SDK Version\n")

for model in sorted(sdk_manifest, key=lambda elt: elt["model_id"]):
for model in sdk_manifest_top_versions_for_models.values():
model_spec = get_jumpstart_sdk_spec(model["spec_key"])
file_content.append(" * - {}\n".format(model["model_id"]))
file_content.append(" - {}\n".format(model_spec["training_supported"]))
Expand Down
33 changes: 32 additions & 1 deletion src/sagemaker/image_uri_config/neo-tensorflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"1.11.0": "1.15.3",
"1.12.0": "1.15.3",
"1.13.0": "1.15.3",
"1.14.0": "1.15.3"
"1.14.0": "1.15.3",
"2.4.2": "2.4.2"
},
"versions": {
"1.15.3": {
Expand Down Expand Up @@ -44,6 +45,36 @@
"us-west-2": "301217895009"
},
"repository": "sagemaker-inference-tensorflow"
},
"2.4.2": {
"py_versions": ["py3"],
"registries": {
"af-south-1": "774647643957",
"ap-east-1": "110948597952",
"ap-northeast-1": "941853720454",
"ap-northeast-2": "151534178276",
"ap-northeast-3": "925152966179",
"ap-south-1": "763008648453",
"ap-southeast-1": "324986816169",
"ap-southeast-2": "355873309152",
"ca-central-1": "464438896020",
"cn-north-1": "472730292857",
"cn-northwest-1": "474822919863",
"eu-central-1": "746233611703",
"eu-north-1": "601324751636",
"eu-south-1": "966458181534",
"eu-west-1": "802834080501",
"eu-west-2": "205493899709",
"eu-west-3": "254080097072",
"me-south-1": "836785723513",
"sa-east-1": "756306329178",
"us-east-1": "785573368785",
"us-east-2": "007439368137",
"us-gov-west-1": "263933020539",
"us-west-1": "710691900526",
"us-west-2": "301217895009"
},
"repository": "sagemaker-inference-tensorflow"
}
}
}
36 changes: 35 additions & 1 deletion src/sagemaker/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import csv
import io
import json

import numpy as np
from six import with_metaclass

Expand Down Expand Up @@ -357,3 +356,38 @@ def serialize(self, data):
return data.read()

raise ValueError("Unable to handle input format: %s" % type(data))


class DataSerializer(SimpleBaseSerializer):
"""Serialize data in any file by extracting raw bytes from the file."""

def __init__(self, content_type="file-path/raw-bytes"):
"""Initialize a ``DataSerializer`` instance.

Args:
content_type (str): The MIME type to signal to the inference endpoint when sending
request data (default: "file-path/raw-bytes").
"""
super(DataSerializer, self).__init__(content_type=content_type)

def serialize(self, data):
"""Serialize file data to a raw bytes.

Args:
data (object): Data to be serialized. The data can be a string
representing file-path or the raw bytes from a file.
Returns:
raw-bytes: The data serialized as raw-bytes from the input.
"""
if isinstance(data, str):
try:
dataFile = open(data, "rb")
dataFileInfo = dataFile.read()
dataFile.close()
return dataFileInfo
except Exception as e:
raise ValueError(f"Could not open/read file: {data}. {e}")
if isinstance(data, bytes):
return data

raise ValueError(f"Object of type {type(data)} is not Data serializable.")
Binary file added tests/data/cuteCat.raw
Binary file not shown.
9 changes: 8 additions & 1 deletion tests/scripts/run-notebook-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ echo "$LIFECYCLE_CONFIG_CONTENT"

set -euo pipefail

# git doesn't work in codepipeline, use CODEBUILD_RESOLVED_SOURCE_VERSION to get commit id
codebuild_initiator="${CODEBUILD_INITIATOR:-0}"
if [ "${codebuild_initiator:0:12}" == "codepipeline" ]; then
COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
else
COMMIT_ID=$(git rev-parse --short HEAD)
fi

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
COMMIT_ID=$(git rev-parse --short HEAD)
LIFECYCLE_CONFIG_NAME="install-python-sdk-$COMMIT_ID"

python setup.py sdist
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/sagemaker/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SparseMatrixSerializer,
JSONLinesSerializer,
LibSVMSerializer,
DataSerializer,
)
from tests.unit import DATA_DIR

Expand Down Expand Up @@ -331,3 +332,26 @@ def test_libsvm_serializer_file_like(libsvm_serializer):
libsvm_file.seek(0)
result = libsvm_serializer.serialize(libsvm_file)
assert result == validation_data


@pytest.fixture
def data_serializer():
return DataSerializer()


def test_data_serializer_raw(data_serializer):
input_image_file_path = os.path.join(DATA_DIR, "", "cuteCat.jpg")
with open(input_image_file_path, "rb") as image:
input_image = image.read()
input_image_data = data_serializer.serialize(input_image)
validation_image_file_path = os.path.join(DATA_DIR, "", "cuteCat.raw")
validation_image_data = open(validation_image_file_path, "rb").read()
assert input_image_data == validation_image_data


def test_data_serializer_file_like(data_serializer):
input_image_file_path = os.path.join(DATA_DIR, "", "cuteCat.jpg")
validation_image_file_path = os.path.join(DATA_DIR, "", "cuteCat.raw")
input_image_data = data_serializer.serialize(input_image_file_path)
validation_image_data = open(validation_image_file_path, "rb").read()
assert input_image_data == validation_image_data