You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyTorch 1.6.0 Inference packaging skips dependencies, other model artefacts #1909
Describe the bug
Model artefacts packagedin model.tar.gz are skipped when the model object is converted into a TorchServe model. Similarly, dependencies included are also dropped.
To reproduce
Add any extra file to model.tar.gz that is not model.pth, and it won't show up in the container. Similarly, any of the extra depenencies specified during the initialization of a PyTorchModel object are dropped.
Expected behavior
Model package would include all of the extra files and dependencies, as described in the API documentation.
Screenshots or logs
Tried os.walk in the model_dir and realized artefacts I was expecting were missing. The below log shows the files in model_dir. I had an extra .pkl object in there which was not included.
Similarly, the directories log is missing the extra dependencies specified while creating the PyTorchModel object under model_dir/lib (#1832 another bug) or model_dir (as specified in API documentation) both.
But, at runtime, the only files and directories in the model_dir the container are: inference.py, model.pth and handler_service.py (see logs in the opening comment).
Why does an extra repackaging step occur that creates a difference between what is made available on S3 at code_location and what is in the final inference service? This further makes it more difficult to understand (and diagnose) what's happening on the container since the model tarball produced by SageMaker drifts away from the expected (which was repackaged by the SDK!).
Why is everything being dropped from the container?
@setu4993, I have experienced similar issues with that. From the source code, I believe the following line might be the one that's causing what you are experiencing (and me as well):
This makes inference.py the only (custom) py file in the model directory. I believe this container should support adding extra/custom artifacts (e.g., model companion objects, model architecture).
Activity
chuyang-deng commentedon Sep 21, 2020
Hi @setu4993,
Could you provide the python sdk code and
source_dirstructure so we could rootcause the issue?setu4993 commentedon Sep 21, 2020
A short example to reproduce the issue (X and Y are other directories on the file system):
After the re-packaging step occurs and a
model.tar.gzis created on S3 at thecode_location:But, at runtime, the only files and directories in the
model_dirthe container are:inference.py,model.pthandhandler_service.py(see logs in the opening comment).setu4993 commentedon Sep 21, 2020
The problem here is multi-fold:
code_locationand what is in the final inference service? This further makes it more difficult to understand (and diagnose) what's happening on the container since the model tarball produced by SageMaker drifts away from the expected (which was repackaged by the SDK!).setu4993 commentedon Sep 24, 2020
@ChuyangDeng : Any update on this?
jonsnowseven commentedon Oct 14, 2020
@setu4993, I have experienced similar issues with that. From the source code, I believe the following line might be the one that's causing what you are experiencing (and me as well):
https://github.com/aws/sagemaker-pytorch-inference-toolkit/blob/9a6869ea3af1ebf9292da0a8d752b0c3389ecdec/src/sagemaker_pytorch_serving_container/torchserve.py#L125
This makes
inference.pythe only (custom) py file in the model directory. I believe this container should support adding extra/custom artifacts (e.g., model companion objects, model architecture).Furthermore, Sagemaker Python SDK example with PyTorch (with the code here) does not work with this serving container (because the model has a companion object).
setu4993 commentedon Oct 14, 2020
Thanks @jonsnowseven. +1, I think I found the same line earlier :).
In my case, it all works with 1.5.0, so I'm sticking to it and updating to 1.6 with requirements.txt.
ldong87 commentedon Feb 5, 2021
After almost 4 months from the last comment, this bug still persists....
jonsnowseven commentedon Feb 5, 2021
Yes @ldong87. Any news regarding this?
declark1 commentedon Feb 18, 2021
Same issue here. Have been trying to work around this for 2 days now with no luck.
setu4993 commentedon Feb 18, 2021
Wanted to share that @amaharek found a potential solution and posted it on the supplementary issue on the
sagemaker-pytorch-inference-toolkitrepo here: aws/sagemaker-pytorch-inference-toolkit#85 (comment)agurtovoy commentedon Feb 23, 2021
@dectl One (ugly) workaround is to copy/load the missing model files from
/opt/ml/model/, which apparently is a documented decompressed model location: https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html#your-algorithms-inference-code-load-artifactslxning commentedon Jun 23, 2021
This issue was fixed in TS0.3.1 and toolkitv2.0.5.. These fixes are available in latest SM DLC.
setu4993 commentedon Jun 24, 2021
Thank you, @lxning! Can confirm that it works and the packages now contain all artifacts as expected.
Master model customization to keynote 3 v3 (#1925)