Skip to content

fix: revert "feature: upgrade Neo MxNet to 1.7 (#1928)" #1930

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 1 commit into from
Sep 29, 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
26 changes: 13 additions & 13 deletions src/sagemaker/image_uri_config/neo-mxnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"processors": ["cpu", "gpu"],
"scope": ["inference"],
"version_aliases": {
"0.12.1": "1.7",
"1.0.0": "1.7",
"1.1.0": "1.7",
"1.2": "1.7",
"1.2.0": "1.7",
"1.2.1": "1.7",
"1.3": "1.7",
"1.3.0": "1.7",
"1.4": "1.7",
"1.4.0": "1.7",
"1.4.1": "1.7"
"0.12.1": "1.5",
"1.0.0": "1.5",
"1.1.0": "1.5",
"1.2": "1.5",
"1.2.0": "1.5",
"1.2.1": "1.5",
"1.3": "1.5",
"1.3.0": "1.5",
"1.4": "1.5",
"1.4.0": "1.5",
"1.4.1": "1.5"
},
"versions": {
"1.7": {
"1.5": {
"py_versions": ["py3"],
"registries": {
"af-south-1": "774647643957",
Expand All @@ -42,7 +42,7 @@
"us-west-1": "710691900526",
"us-west-2": "301217895009"
},
"repository": "sagemaker-inference-mxnet"
"repository": "sagemaker-neo-mxnet"
}
}
}
2 changes: 1 addition & 1 deletion src/sagemaker/image_uri_config/neo-pytorch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"us-west-1": "710691900526",
"us-west-2": "301217895009"
},
"repository": "sagemaker-inference-pytorch"
"repository": "sagemaker-neo-pytorch"
}
}
}
35 changes: 15 additions & 20 deletions tests/data/mxnet_mnist/mnist_neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,27 @@ def train(
save(model_dir, mlp_model)


def model_fn(path_to_model_files):
import neomxnet # noqa: F401
def neo_preprocess(payload, content_type):
logging.info("Invoking user-defined pre-processing function")

ctx = mx.cpu()
sym, arg_params, aux_params = mx.model.load_checkpoint(
os.path.join(path_to_model_files, "compiled"), 0
)
mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
mod.bind(
for_training=False, data_shapes=[("data", (1, 1, 28, 28))], label_shapes=mod._label_shapes
)
mod.set_params(arg_params, aux_params, allow_missing=True)
return mod
if content_type != "application/vnd+python.numpy+binary":
raise RuntimeError("Content type must be application/vnd+python.numpy+binary")

return np.asarray(json.loads(payload.decode("utf-8")))

def transform_fn(mod, payload, input_content_type, requested_output_content_type):
import neomxnet # noqa: F401

if input_content_type != "application/vnd+python.numpy+binary":
raise RuntimeError("Input content type must be application/vnd+python.numpy+binary")
# NOTE: this function cannot use MXNet
def neo_postprocess(result):
logging.info("Invoking user-defined post-processing function")

inference_payload = np.asarray(json.loads(payload.decode("utf-8")))
result = mod.predict(inference_payload)
# Softmax (assumes batch size 1)
result = np.squeeze(result)
response_body = json.dumps(result.asnumpy().tolist())
result_exp = np.exp(result - np.max(result))
result = result_exp / np.sum(result_exp)

response_body = json.dumps(result.tolist())
content_type = "application/json"

return response_body, content_type


Expand All @@ -140,7 +135,7 @@ def transform_fn(mod, payload, input_content_type, requested_output_content_type
parser = argparse.ArgumentParser()

parser.add_argument("--batch-size", type=int, default=100)
parser.add_argument("--epochs", type=int, default=1)
parser.add_argument("--epochs", type=int, default=10)
parser.add_argument("--learning-rate", type=float, default=0.1)

parser.add_argument("--model-dir", type=str, default=os.environ["SM_MODEL_DIR"])
Expand Down
12 changes: 9 additions & 3 deletions tests/integ/test_neo_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def mxnet_training_job(


@pytest.mark.canary_quick
@pytest.mark.skip(
reason="This test is failing because the image uri and the training script format has changed."
)
def test_attach_deploy(
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
):
Expand All @@ -68,7 +71,7 @@ def test_attach_deploy(

estimator.compile_model(
target_instance_family=cpu_instance_family,
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
input_shape={"data": [1, 1, 28, 28]},
output_path=estimator.output_path,
)

Expand All @@ -86,6 +89,9 @@ def test_attach_deploy(
predictor.predict(data)


@pytest.mark.skip(
reason="This test is failing because the image uri and the training script format has changed."
)
def test_deploy_model(
mxnet_training_job,
sagemaker_session,
Expand Down Expand Up @@ -117,7 +123,7 @@ def test_deploy_model(

model.compile(
target_instance_family=cpu_instance_family,
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
input_shape={"data": [1, 1, 28, 28]},
role=role,
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
output_path="/".join(model_data.split("/")[:-1]),
Expand Down Expand Up @@ -159,7 +165,7 @@ def test_inferentia_deploy_model(

model.compile(
target_instance_family=inf_instance_family,
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
input_shape={"data": [1, 1, 28, 28]},
role=role,
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
output_path="/".join(model_data.split("/")[:-1]),
Expand Down
19 changes: 6 additions & 13 deletions tests/unit/sagemaker/image_uris/test_neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,19 @@ def test_algo_uris(algo):


def _test_neo_framework_uris(framework, version):
framework_in_config = f"neo-{framework}"
framework_in_uri = f"neo-{framework}" if framework == "tensorflow" else f"inference-{framework}"
framework = "neo-{}".format(framework)

for region in regions.regions():
if region in ACCOUNTS:
uri = image_uris.retrieve(
framework_in_config, region, instance_type="ml_c5", version=version
)
assert _expected_framework_uri(framework_in_uri, version, region=region) == uri
uri = image_uris.retrieve(framework, region, instance_type="ml_c5", version=version)
assert _expected_framework_uri(framework, version, region=region) == uri
else:
with pytest.raises(ValueError) as e:
image_uris.retrieve(
framework_in_config, region, instance_type="ml_c5", version=version
)
image_uris.retrieve(framework, region, instance_type="ml_c5", version=version)
assert "Unsupported region: {}.".format(region) in str(e.value)

uri = image_uris.retrieve(
framework_in_config, "us-west-2", instance_type="ml_p2", version=version
)
assert _expected_framework_uri(framework_in_uri, version, processor="gpu") == uri
uri = image_uris.retrieve(framework, "us-west-2", instance_type="ml_p2", version=version)
assert _expected_framework_uri(framework, version, processor="gpu") == uri


def test_neo_mxnet(neo_mxnet_version):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _create_compilation_job(input_shape, output_location):


def _neo_inference_image(mxnet_version):
return "301217895009.dkr.ecr.us-west-2.amazonaws.com/sagemaker-inference-{}:{}-cpu-py3".format(
return "301217895009.dkr.ecr.us-west-2.amazonaws.com/sagemaker-neo-{}:{}-cpu-py3".format(
FRAMEWORK.lower(), mxnet_version
)

Expand Down