Skip to content

Commit 1e03620

Browse files
committed
Update Archiver to v0.3.1 / Integ tests
1 parent 6936c08 commit 1e03620

File tree

13 files changed

+16
-15
lines changed

13 files changed

+16
-15
lines changed

src/sagemaker_pytorch_serving_container/torchserve.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
)
4343
DEFAULT_TS_MODEL_DIRECTORY = os.path.join(os.getcwd(), ".sagemaker", "ts", "models")
4444
DEFAULT_TS_MODEL_NAME = "model"
45-
DEFAULT_TS_MODEL_SERIALIZED_FILE = "model.pth"
4645
DEFAULT_TS_CODE_DIR = "code"
4746
DEFAULT_HANDLER_SERVICE = "sagemaker_pytorch_serving_container.handler_service"
4847

@@ -117,12 +116,8 @@ def _adapt_to_ts_format(handler_service):
117116
DEFAULT_TS_MODEL_NAME,
118117
"--handler",
119118
handler_service,
120-
"--serialized-file",
121-
os.path.join(environment.model_dir, DEFAULT_TS_MODEL_SERIALIZED_FILE),
122119
"--export-path",
123120
DEFAULT_TS_MODEL_DIRECTORY,
124-
"--extra-files",
125-
os.path.join(environment.model_dir, DEFAULT_TS_CODE_DIR, environment.Environment().module_name + ".py"),
126121
"--version",
127122
"1",
128123
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ARG region
22
FROM 763104351884.dkr.ecr.$region.amazonaws.com/pytorch-inference:1.6.0-cpu-py3
33

4+
RUN git clone https://github.com/pytorch/serve/ && cd serve/model-archiver/ && git checkout patch_release_0_3_1 && pip install . && cd -
5+
46
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz
57
RUN pip install --upgrade --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \
68
rm /sagemaker_pytorch_inference.tar.gz
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ARG region
22
FROM 763104351884.dkr.ecr.$region.amazonaws.com/pytorch-inference:1.6.0-gpu-py3
33

4+
RUN git clone https://github.com/pytorch/serve/ && cd serve/model-archiver/ && git checkout patch_release_0_3_1 && pip install . && cd -
5+
46
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz
57
RUN pip install --upgrade --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \
68
rm /sagemaker_pytorch_inference.tar.gz

test/container/1.6.0/Dockerfile.pytorch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ RUN useradd -m model-server \
3838
COPY artifacts/ts-entrypoint.py /usr/local/bin/dockerd-entrypoint.py
3939
COPY artifacts/config.properties /home/model-server
4040

41+
RUN git clone https://github.com/pytorch/serve/ && cd serve/model-archiver/ && git checkout patch_release_0_3_1 && pip install . && cd -
42+
4143
RUN chmod +x /usr/local/bin/dockerd-entrypoint.py
4244

4345
EXPOSE 8080 8081

test/integration/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@
2828
model_cpu_dir = os.path.join(mnist_path, cpu_sub_dir)
2929
mnist_cpu_script = os.path.join(model_cpu_dir, code_sub_dir, 'mnist.py')
3030
model_cpu_tar = file_utils.make_tarfile(mnist_cpu_script,
31-
os.path.join(model_cpu_dir, "model.pth"),
31+
os.path.join(model_cpu_dir, "torch_model.pth"),
3232
model_cpu_dir,
3333
script_path="code")
3434

3535
model_cpu_1d_dir = os.path.join(model_cpu_dir, '1d')
3636
mnist_1d_script = os.path.join(model_cpu_1d_dir, code_sub_dir, 'mnist_1d.py')
3737
model_cpu_1d_tar = file_utils.make_tarfile(mnist_1d_script,
38-
os.path.join(model_cpu_1d_dir, "model.pth"),
38+
os.path.join(model_cpu_1d_dir, "torch_model.pth"),
3939
model_cpu_1d_dir,
4040
script_path="code")
4141

4242
model_gpu_dir = os.path.join(mnist_path, gpu_sub_dir)
4343
mnist_gpu_script = os.path.join(model_gpu_dir, code_sub_dir, 'mnist.py')
4444
model_gpu_tar = file_utils.make_tarfile(mnist_gpu_script,
45-
os.path.join(model_gpu_dir, "model.pth"),
45+
os.path.join(model_gpu_dir, "torch_model.pth"),
4646
model_gpu_dir,
4747
script_path="code")
4848

4949
model_eia_dir = os.path.join(mnist_path, eia_sub_dir)
5050
mnist_eia_script = os.path.join(model_eia_dir, 'mnist.py')
5151
model_eia_tar = file_utils.make_tarfile(mnist_eia_script,
52-
os.path.join(model_eia_dir, "model.pth"),
52+
os.path.join(model_eia_dir, "torch_model.pth"),
5353
model_eia_dir)
5454

5555
call_model_fn_once_script = os.path.join(model_cpu_dir, code_sub_dir, 'call_model_fn_once.py')
5656
call_model_fn_once_tar = file_utils.make_tarfile(call_model_fn_once_script,
57-
os.path.join(model_cpu_dir, "model.pth"),
57+
os.path.join(model_cpu_dir, "torch_model.pth"),
5858
model_cpu_dir,
5959
"model_call_model_fn_once.tar.gz",
6060
script_path="code")

test/resources/mnist/model_cpu/1d/code/mnist_1d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ def forward(self, x):
4242

4343
def model_fn(model_dir):
4444
model = torch.nn.DataParallel(Net())
45-
with open(os.path.join(model_dir, 'model.pth'), 'rb') as f:
45+
with open(os.path.join(model_dir, 'torch_model.pth'), 'rb') as f:
4646
model.load_state_dict(torch.load(f))
4747
return model

test/resources/mnist/model_cpu/code/mnist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ def forward(self, x):
5252
def model_fn(model_dir):
5353
logger.info('model_fn')
5454
model = torch.nn.DataParallel(Net())
55-
with open(os.path.join(model_dir, 'model.pth'), 'rb') as f:
55+
with open(os.path.join(model_dir, 'torch_model.pth'), 'rb') as f:
5656
model.load_state_dict(torch.load(f))
5757
return model

test/resources/mnist/model_eia/mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def model_fn(model_dir):
3838
logger.info('model_fn: Loading model with TorchScript from {}'.format(model_dir))
3939
# Scripted model is serialized with torch.jit.save().
4040
# No need to instantiate model definition then load state_dict
41-
model = torch.jit.load('model.pth')
41+
model = torch.jit.load('torch_model.pth')
4242
return model
4343

4444

4545
def save_model(model, model_dir):
4646
logger.info("Saving the model to {}.".format(model_dir))
47-
path = os.path.join(model_dir, 'model.pth')
47+
path = os.path.join(model_dir, 'torch_model.pth')
4848
torch.jit.save(model, path)

test/resources/mnist/model_gpu/code/mnist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ def forward(self, x):
5252
def model_fn(model_dir):
5353
logger.info('model_fn')
5454
model = torch.nn.DataParallel(Net())
55-
with open(os.path.join(model_dir, 'model.pth'), 'rb') as f:
55+
with open(os.path.join(model_dir, 'torch_model.pth'), 'rb') as f:
5656
model.load_state_dict(torch.load(f))
5757
return model

0 commit comments

Comments
 (0)