Skip to content

change: enable Neo integ tests #1309

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 2 commits into from
Feb 25, 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
7 changes: 4 additions & 3 deletions src/sagemaker/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def compile(
https://docs.aws.amazon.com/sagemaker/latest/dg/API_OutputConfig.html.
input_shape (dict): Specifies the name and shape of the expected
inputs for your trained model in json dictionary form, for
example: {'data':[1,3,1024,1024]}, or {'var1': [1,1,28,28],
'var2':[1,1,28,28]}
example: {'data': [1,3,1024,1024]}, or {'var1': [1,1,28,28],
'var2': [1,1,28,28]}
output_path (str): Specifies where to store the compiled model
role (str): Execution role
tags (list[dict]): List of tags for labeling a compilation job. For
Expand Down Expand Up @@ -436,7 +436,8 @@ def deploy(

compiled_model_suffix = "-".join(instance_type.split(".")[:-1])
if self._is_compiled_model:
self.name += compiled_model_suffix
name_prefix = self.name or utils.name_from_image(self.image)
self.name = "{}{}".format(name_prefix, compiled_model_suffix)

self._create_sagemaker_model(instance_type, accelerator_type, tags)
production_variant = sagemaker.production_variant(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def alternative_cpu_instance_type(sagemaker_session, request):

@pytest.fixture(scope="session")
def cpu_instance_family(cpu_instance_type):
"_".join(cpu_instance_type.split(".")[0:2])
return "_".join(cpu_instance_type.split(".")[0:2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol



def pytest_generate_tests(metafunc):
Expand Down
22 changes: 5 additions & 17 deletions tests/data/mxnet_mnist/mnist_neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import mxnet as mx
import numpy as np

from sagemaker_mxnet_container.training_utils import scheduler_host


def load_data(path):
with gzip.open(find_file(path, "labels.gz")) as flbl:
Expand Down Expand Up @@ -112,11 +110,10 @@ def neo_preprocess(payload, content_type):
if content_type != "application/vnd+python.numpy+binary":
raise RuntimeError("Content type must be application/vnd+python.numpy+binary")

f = io.BytesIO(payload)
return np.load(f)
return np.asarray(json.loads(payload.decode("utf-8")))


### NOTE: this function cannot use MXNet
# NOTE: this function cannot use MXNet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[INFO] For prod code, I'd probably also modify this to actually print something out, because that's much more discoverable than the comment. Not worth the effort for a test script, though.

def neo_postprocess(result):
logging.info("Invoking user-defined post-processing function")

Expand All @@ -131,19 +128,10 @@ def neo_postprocess(result):
return response_body, content_type


def save(model_dir, model):
model.symbol.save(os.path.join(model_dir, "model-symbol.json"))
model.save_params(os.path.join(model_dir, "model-0000.params"))

signature = [
{"name": data_desc.name, "shape": [dim for dim in data_desc.shape]}
for data_desc in model.data_shapes
]
with open(os.path.join(model_dir, "model-shapes.json"), "w") as f:
json.dump(signature, f)


if __name__ == "__main__":
# Import here to prevent import during serving
from sagemaker_mxnet_container.training_utils import scheduler_host, save

parser = argparse.ArgumentParser()

parser.add_argument("--batch-size", type=int, default=100)
Expand Down
26 changes: 12 additions & 14 deletions tests/integ/test_neo_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@
# language governing permissions and limitations under the License.
from __future__ import absolute_import

import numpy
import os

import numpy
import pytest

from sagemaker.mxnet.estimator import MXNet
from sagemaker.mxnet.model import MXNetModel
from sagemaker.utils import sagemaker_timestamp
from sagemaker.utils import unique_name_from_base
from tests.integ import DATA_DIR, PYTHON_VERSION, TRAINING_DEFAULT_TIMEOUT_MINUTES
from tests.integ.timeout import timeout, timeout_and_delete_endpoint_by_name
import time

NEO_MXNET_VERSION = "1.4.1" # Neo doesn't support MXNet 1.6 yet.


@pytest.fixture(scope="module")
def mxnet_training_job(sagemaker_session, mxnet_full_version, cpu_instance_type):
def mxnet_training_job(sagemaker_session, cpu_instance_type):
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_neo.py")
data_path = os.path.join(DATA_DIR, "mxnet_mnist")

mx = MXNet(
entry_point=script_path,
role="SageMakerRole",
framework_version=mxnet_full_version,
framework_version=NEO_MXNET_VERSION,
py_version=PYTHON_VERSION,
train_instance_count=1,
train_instance_type=cpu_instance_type,
Expand All @@ -52,13 +55,10 @@ def mxnet_training_job(sagemaker_session, mxnet_full_version, cpu_instance_type)

@pytest.mark.canary_quick
@pytest.mark.regional_testing
@pytest.mark.skip(
reason="This should be enabled along with the Boto SDK release for Neo API changes"
)
def test_attach_deploy(
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
):
endpoint_name = "test-mxnet-attach-deploy-{}".format(sagemaker_timestamp())
endpoint_name = unique_name_from_base("test-neo-attach-deploy")

with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
estimator = MXNet.attach(mxnet_training_job, sagemaker_session=sagemaker_session)
Expand All @@ -77,13 +77,10 @@ def test_attach_deploy(
predictor.predict(data)


@pytest.mark.skip(
reason="This should be enabled along with the Boto SDK release for Neo API changes"
)
def test_deploy_model(
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
):
endpoint_name = "test-mxnet-deploy-model-{}".format(sagemaker_timestamp())
endpoint_name = unique_name_from_base("test-neo-deploy-model")

with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
desc = sagemaker_session.sagemaker_client.describe_training_job(
Expand All @@ -97,14 +94,15 @@ def test_deploy_model(
role,
entry_point=script_path,
py_version=PYTHON_VERSION,
framework_version=NEO_MXNET_VERSION,
sagemaker_session=sagemaker_session,
)

model.compile(
target_instance_family=cpu_instance_family,
input_shape={"data": [1, 1, 28, 28]},
role=role,
job_name="test-deploy-model-compilation-job-{}".format(int(time.time())),
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
output_path="/".join(model_data.split("/")[:-1]),
)
predictor = model.deploy(1, cpu_instance_type, endpoint_name=endpoint_name)
Expand Down