Skip to content

Commit 64c768d

Browse files
author
Rui Wang Napieralski
committed
feature: upgrade Neo MxNet to 1.7
1 parent c5d9173 commit 64c768d

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

src/sagemaker/image_uri_config/neo-mxnet.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
"processors": ["cpu", "gpu"],
33
"scope": ["inference"],
44
"version_aliases": {
5-
"0.12.1": "1.5",
6-
"1.0.0": "1.5",
7-
"1.1.0": "1.5",
8-
"1.2": "1.5",
9-
"1.2.0": "1.5",
10-
"1.2.1": "1.5",
11-
"1.3": "1.5",
12-
"1.3.0": "1.5",
13-
"1.4": "1.5",
14-
"1.4.0": "1.5",
15-
"1.4.1": "1.5"
5+
"0.12.1": "1.7",
6+
"1.0.0": "1.7",
7+
"1.1.0": "1.7",
8+
"1.2": "1.7",
9+
"1.2.0": "1.7",
10+
"1.2.1": "1.7",
11+
"1.3": "1.7",
12+
"1.3.0": "1.7",
13+
"1.4": "1.7",
14+
"1.4.0": "1.7",
15+
"1.4.1": "1.7"
1616
},
1717
"versions": {
18-
"1.5": {
18+
"1.7": {
1919
"py_versions": ["py3"],
2020
"registries": {
2121
"af-south-1": "774647643957",
@@ -42,7 +42,7 @@
4242
"us-west-1": "710691900526",
4343
"us-west-2": "301217895009"
4444
},
45-
"repository": "sagemaker-neo-mxnet"
45+
"repository": "sagemaker-inference-mxnet"
4646
}
4747
}
4848
}

tests/data/mxnet_mnist/mnist_neo.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import mxnet as mx
2121
import numpy as np
22+
import neomxnet # noqa: F401
2223

2324

2425
def load_data(path):
@@ -104,27 +105,28 @@ def train(
104105
save(model_dir, mlp_model)
105106

106107

107-
def neo_preprocess(payload, content_type):
108-
logging.info("Invoking user-defined pre-processing function")
109-
110-
if content_type != "application/vnd+python.numpy+binary":
111-
raise RuntimeError("Content type must be application/vnd+python.numpy+binary")
112-
113-
return np.asarray(json.loads(payload.decode("utf-8")))
108+
def model_fn(path_to_model_files):
109+
ctx = mx.cpu()
110+
sym, arg_params, aux_params = mx.model.load_checkpoint(
111+
os.path.join(path_to_model_files, "compiled"), 0
112+
)
113+
mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
114+
mod.bind(
115+
for_training=False, data_shapes=[("data", (1, 1, 28, 28))], label_shapes=mod._label_shapes
116+
)
117+
mod.set_params(arg_params, aux_params, allow_missing=True)
118+
return mod
114119

115120

116-
# NOTE: this function cannot use MXNet
117-
def neo_postprocess(result):
118-
logging.info("Invoking user-defined post-processing function")
121+
def transform_fn(mod, payload, input_content_type, requested_output_content_type):
122+
if input_content_type != "application/vnd+python.numpy+binary":
123+
raise RuntimeError("Input content type must be application/vnd+python.numpy+binary")
119124

120-
# Softmax (assumes batch size 1)
125+
inference_payload = np.asarray(json.loads(payload.decode("utf-8")))
126+
result = mod.predict(inference_payload)
121127
result = np.squeeze(result)
122-
result_exp = np.exp(result - np.max(result))
123-
result = result_exp / np.sum(result_exp)
124-
125-
response_body = json.dumps(result.tolist())
128+
response_body = json.dumps(result.asnumpy().tolist())
126129
content_type = "application/json"
127-
128130
return response_body, content_type
129131

130132

@@ -135,7 +137,7 @@ def neo_postprocess(result):
135137
parser = argparse.ArgumentParser()
136138

137139
parser.add_argument("--batch-size", type=int, default=100)
138-
parser.add_argument("--epochs", type=int, default=10)
140+
parser.add_argument("--epochs", type=int, default=1)
139141
parser.add_argument("--learning-rate", type=float, default=0.1)
140142

141143
parser.add_argument("--model-dir", type=str, default=os.environ["SM_MODEL_DIR"])

tests/integ/test_neo_mxnet.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def mxnet_training_job(
5858

5959

6060
@pytest.mark.canary_quick
61-
@pytest.mark.skip(
62-
reason="This test is failing because the image uri and the training script format has changed."
63-
)
6461
def test_attach_deploy(
6562
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
6663
):
@@ -71,7 +68,7 @@ def test_attach_deploy(
7168

7269
estimator.compile_model(
7370
target_instance_family=cpu_instance_family,
74-
input_shape={"data": [1, 1, 28, 28]},
71+
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
7572
output_path=estimator.output_path,
7673
)
7774

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

9188

92-
@pytest.mark.skip(
93-
reason="This test is failing because the image uri and the training script format has changed."
94-
)
9589
def test_deploy_model(
9690
mxnet_training_job,
9791
sagemaker_session,
@@ -123,7 +117,7 @@ def test_deploy_model(
123117

124118
model.compile(
125119
target_instance_family=cpu_instance_family,
126-
input_shape={"data": [1, 1, 28, 28]},
120+
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
127121
role=role,
128122
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
129123
output_path="/".join(model_data.split("/")[:-1]),
@@ -165,7 +159,7 @@ def test_inferentia_deploy_model(
165159

166160
model.compile(
167161
target_instance_family=inf_instance_family,
168-
input_shape={"data": [1, 1, 28, 28]},
162+
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
169163
role=role,
170164
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
171165
output_path="/".join(model_data.split("/")[:-1]),

0 commit comments

Comments
 (0)