Skip to content

Commit b3f8abc

Browse files
icywang86ruiRui Wang Napieralski
and
Rui Wang Napieralski
authored
fix: revert "feature: upgrade Neo MxNet to 1.7 (#1928)" (#1930)
This reverts commit f800e0c. Co-authored-by: Rui Wang Napieralski <[email protected]>
1 parent 2c4bf5b commit b3f8abc

File tree

6 files changed

+45
-51
lines changed

6 files changed

+45
-51
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.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"
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"
1616
},
1717
"versions": {
18-
"1.7": {
18+
"1.5": {
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-inference-mxnet"
45+
"repository": "sagemaker-neo-mxnet"
4646
}
4747
}
4848
}

src/sagemaker/image_uri_config/neo-pytorch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"us-west-1": "710691900526",
3737
"us-west-2": "301217895009"
3838
},
39-
"repository": "sagemaker-inference-pytorch"
39+
"repository": "sagemaker-neo-pytorch"
4040
}
4141
}
4242
}

tests/data/mxnet_mnist/mnist_neo.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,27 @@ def train(
104104
save(model_dir, mlp_model)
105105

106106

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

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

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

122-
def transform_fn(mod, payload, input_content_type, requested_output_content_type):
123-
import neomxnet # noqa: F401
124115

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

128-
inference_payload = np.asarray(json.loads(payload.decode("utf-8")))
129-
result = mod.predict(inference_payload)
120+
# Softmax (assumes batch size 1)
130121
result = np.squeeze(result)
131-
response_body = json.dumps(result.asnumpy().tolist())
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())
132126
content_type = "application/json"
127+
133128
return response_body, content_type
134129

135130

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

142137
parser.add_argument("--batch-size", type=int, default=100)
143-
parser.add_argument("--epochs", type=int, default=1)
138+
parser.add_argument("--epochs", type=int, default=10)
144139
parser.add_argument("--learning-rate", type=float, default=0.1)
145140

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

tests/integ/test_neo_mxnet.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ 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+
)
6164
def test_attach_deploy(
6265
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
6366
):
@@ -68,7 +71,7 @@ def test_attach_deploy(
6871

6972
estimator.compile_model(
7073
target_instance_family=cpu_instance_family,
71-
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
74+
input_shape={"data": [1, 1, 28, 28]},
7275
output_path=estimator.output_path,
7376
)
7477

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

8891

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

118124
model.compile(
119125
target_instance_family=cpu_instance_family,
120-
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
126+
input_shape={"data": [1, 1, 28, 28]},
121127
role=role,
122128
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
123129
output_path="/".join(model_data.split("/")[:-1]),
@@ -159,7 +165,7 @@ def test_inferentia_deploy_model(
159165

160166
model.compile(
161167
target_instance_family=inf_instance_family,
162-
input_shape={"data": [1, 1, 28, 28], "softmax_label": [1]},
168+
input_shape={"data": [1, 1, 28, 28]},
163169
role=role,
164170
job_name=unique_name_from_base("test-deploy-model-compilation-job"),
165171
output_path="/".join(model_data.split("/")[:-1]),

tests/unit/sagemaker/image_uris/test_neo.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,19 @@ def test_algo_uris(algo):
6262

6363

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

6867
for region in regions.regions():
6968
if region in ACCOUNTS:
70-
uri = image_uris.retrieve(
71-
framework_in_config, region, instance_type="ml_c5", version=version
72-
)
73-
assert _expected_framework_uri(framework_in_uri, version, region=region) == uri
69+
uri = image_uris.retrieve(framework, region, instance_type="ml_c5", version=version)
70+
assert _expected_framework_uri(framework, version, region=region) == uri
7471
else:
7572
with pytest.raises(ValueError) as e:
76-
image_uris.retrieve(
77-
framework_in_config, region, instance_type="ml_c5", version=version
78-
)
73+
image_uris.retrieve(framework, region, instance_type="ml_c5", version=version)
7974
assert "Unsupported region: {}.".format(region) in str(e.value)
8075

81-
uri = image_uris.retrieve(
82-
framework_in_config, "us-west-2", instance_type="ml_p2", version=version
83-
)
84-
assert _expected_framework_uri(framework_in_uri, version, processor="gpu") == uri
76+
uri = image_uris.retrieve(framework, "us-west-2", instance_type="ml_p2", version=version)
77+
assert _expected_framework_uri(framework, version, processor="gpu") == uri
8578

8679

8780
def test_neo_mxnet(neo_mxnet_version):

tests/unit/test_mxnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _create_compilation_job(input_shape, output_location):
175175

176176

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

0 commit comments

Comments
 (0)