I am creating an sagemaker endpoint and loading a pretrained model from an s3 bucket. the model -> model.tar.gz file has directory structure as documented here, https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#model-directory-structure
model.tar.gz/
|- model.pth
|- code/
|- inference.py
|- requirements.txt # only for versions 1.3.1 and higher
I have put few dependencies in requirements.txt, is there a way to verify that all the dependencies were installed correctly?
Since SageMaker's deployments are serverless, it is not possible to get access or SSH into the machine that's running your deployment. So, one way is to assert the versions of your dependencies in the model_fn
inside "inference.py" by doing something like below.
if your requirements.txt looks like this:
numpy==1.20.3
pandas==1.3.4
get the versions and assert them in `model_fn like below:
import os
### your other code ###
def model_fn(model_dir):
# assuming you have numpy and pandas
assert os.popen("python3 -m pip freeze | grep -E 'numpy|pandas'").read() == 'numpy==1.20.3\npandas==1.3.4\n'
### your other code ###
return xxxx
### your other code ###