sagemaker-python-sdk: `requirements.txt` not working for PytorchModel
There is no way to install dependencies for PytorchModel
, unless one uses the trick of installing within the python script using subprocess
.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (9 by maintainers)
I have a pre-trained model, now trying to create an endpoint using Sagemaker, my folder structure like this “model.tar.gz” looks like this:
model |- config.json |- pytorch_model.bin |- special_tokens_map.json |- spiece.model |- tokenizer_config.json |- training_args.bin code |- inference.py | - requirements.txt
running following script to create endpoint:
pytorch_model = PyTorchModel( model_data='s3://mck-dl-ai-studio/answer_card/answercard.tar.gz', role=role, entry_point='inference.py', framework_version="1.3.1")
predictor = pytorch_model.deploy(instance_type='ml.t2.medium', initial_instance_count=1)
An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message “No module named ‘transformers’”. See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/pytorch-inference-2020-07-20-16-45-51-564 in account xxxxxx for more information.
what I am missing here tried adding source_dir and py_version but no success
@Serhiy-Shekhovtsov right.
@laurenyu, it looks like we can’t store anything under
/code
of model.tar since the entire directory tree undercode
is always removed during repacking: https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/utils.py#L518The only way to get it working is to point
source_dir
to a folder containingrequirements.txt
. All the content insidesource_dir
is copied toopt/ml/model/code
on target machine. The file specified asentry_point
will also be coped there.Another thing - since the entire content and structure of
source_dir
is packaged and copied to the container it doesn’t make much sense to build the model tar manually every time and then create the model usingPyTorchModel.deploy
. Instead, you can store the model, requirements file and the code in a folder provided assource_dir
and only runPyTorchModel.deploy
. (model_data
is a required parameter but you can use an empty tar archive there).@vlordier howrequirements.txt
can be stored there using only Sagemaker SDK with Sagemaker’s default PyTorch image? @vlordier, could you please provide an example of how to forcePyTorchModel
to considerrequirements.txt
? My code is pretty straightforward and repeats the stages described here. @laurenyu 's suggestion of havingmodel.tar.gz
file of specific structure did not work as well.Ok, so as @vlordier wrote to be able to use
requirements.txt
you should use PyTorch serving container of version>=1.3.1
, since1.2.0
version doesn’t support requirements file (see sagemaker-inference-toolkit: support of requirements file was introduced in1.1.0
).Having requirements.txt in the /code directory with a pytorch image 1.3.1 works.
On Tue, 24 Dec 2019 at 22:33, Lenar Gabdrakhmanov notifications@github.com wrote:
those files should also be able to go under
code/
in the model tar