Skip to content

Commit 2ed051c

Browse files
dk19yUbuntu
and
Ubuntu
authored
Update TS Archiver to v0.3.1 / Integ tests (#95)
* Update Archiver to v0.3.1 / Integ tests * Fix Unit tests * Integ test error : .dockercfg: /home/ubuntu is not defined * Install git ? * Git install * Fix path * Fix unit tests * Ignore GPU tests * Disable more tests * Update Dockerfile.dlc.cpu * Update Dockerfile.pytorch * Update Dockerfile.dlc.gpu * Update buildspec.yml * Update Dockerfile for Model Archiver 0.3.1 * Update boto>=1.10.44 Co-authored-by: Ubuntu <[email protected]>
1 parent 6936c08 commit 2ed051c

File tree

15 files changed

+22
-24
lines changed

15 files changed

+22
-24
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def read(fname):
5454
# different packages for different variants
5555
install_requires=['numpy', 'retrying', 'sagemaker-inference>=1.3.1'],
5656
extras_require={
57-
'test': ['boto3==1.10.32', 'coverage==4.5.3', 'docker-compose==1.23.2', 'flake8==3.7.7', 'Flask==1.1.1',
57+
'test': ['boto3>=1.10.44', 'coverage==4.5.3', 'docker-compose==1.23.2', 'flake8==3.7.7', 'Flask==1.1.1',
5858
'mock==2.0.0', 'pytest==4.4.0', 'pytest-cov==2.7.1', 'pytest-xdist==1.28.0', 'PyYAML==3.10',
5959
'sagemaker==1.56.3', 'sagemaker-containers>=2.5.4', 'six==1.12.0', 'requests==2.20.0',
6060
'requests_mock==1.6.0', 'torch==1.6.0', 'torchvision==0.7.0', 'tox==3.7.0']

src/sagemaker_pytorch_serving_container/torchserve.py

Lines changed: 2 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,14 +116,12 @@ 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",
123+
"--extra-files",
124+
os.path.join(environment.model_dir)
128125
]
129126

130127
logger.info(model_archiver_cmd)
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 pip install --upgrade torch-model-archiver==0.3.1
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 pip install --upgrade torch-model-archiver==0.3.1
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ FROM pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime
33
LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true
44
LABEL com.amazonaws.sagemaker.capabilities.multi-models=true
55

6-
ARG TS_VERSION=0.1.1
6+
ARG TS_VERSION=0.3.1
7+
ARG TS_ARCHIVER_VERSION=0.3.1
78

89
ENV SAGEMAKER_SERVING_MODULE sagemaker_pytorch_serving_container.serving:main
910
ENV TEMP=/home/model-server/tmp
@@ -25,7 +26,7 @@ RUN conda install -c conda-forge opencv==4.0.1 \
2526
&& ln -s /opt/conda/bin/pip /usr/local/bin/pip3
2627

2728
RUN pip install torchserve==$TS_VERSION \
28-
&& pip install torch-model-archiver==$TS_VERSION
29+
&& pip install torch-model-archiver==$TS_ARCHIVER_VERSION
2930

3031
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz
3132
RUN pip install --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \

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

test/unit/test_model_server.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,12 @@ def test_adapt_to_ts_format(path_exists, make_dir, subprocess_check_call, set_py
145145
torchserve.DEFAULT_TS_MODEL_NAME,
146146
"--handler",
147147
handler_service,
148-
"--serialized-file",
149-
os.path.join(environment.model_dir, torchserve.DEFAULT_TS_MODEL_SERIALIZED_FILE),
150148
"--export-path",
151149
torchserve.DEFAULT_TS_MODEL_DIRECTORY,
152-
"--extra-files",
153-
os.path.join(environment.model_dir,
154-
torchserve.DEFAULT_TS_CODE_DIR,
155-
environment.Environment().module_name + ".py"),
156150
"--version",
157151
"1",
152+
"--extra-files",
153+
environment.model_dir
158154
]
159155

160156
subprocess_check_call.assert_called_once_with(model_archiver_cmd)

0 commit comments

Comments
 (0)