I am trying to deploy a multi model endpoint on aws sagemaker. However some of my models have additional dependencies. I am following the huggingface's documentation on creating user-defined-code and requirements.
My zipped artifacts have a code directory with requirements.txt and yet when I deploy the model and try invoking it with the python aws sdk. I get ModuleNotFound errors during my imports.
I know its finding my inference.py file since its failing to find those modules that I import.
It should be noted that these models I am deploying are trained and made outside of sagemaker and I am trying to bring them into sagemaker.
The container image I am using is
'763104351884.dkr.ecr.ca-central-1.amazonaws.com/huggingface-pytorch-inference:2.1.0-transformers4.37.0-cpu-py310-ubuntu22.04'
Hey Lucas
It seems to me that you're confusing/mixing two different methods to deploy models in SageMaker.
If you want to create a Multi-Model Endpoint, unfortunately, you'll need to create a Docker Image that adheres to SageMaker's requirements (e.g. which ports to expose, etc.). You can read more on this here.
The HuggingFace guide you've been following is designed for single-model endpoints, and does indeed enable you to use custom dependencies. You may wish to simply create single-model endpoints for all of your models, by following the below steps:
code/directory (within the model dir) and add aninference.pyfilemodel_fn()andpredict_fn(). The former is used only when the endpoint is initialised, and must return the model & tokeniser, the latter is called for each inference request. You can use thepredict_fn()to include custom logic.model.tar.gz) with all the model artefacts (incl. your custom inference code). It should be formatted as below.There's a great notebook from Hugging Face covering this whole process. It's the best guide I've been able to find so far. If you copy it word-for-word, and only modify the
inference.pyscript, you should be successful.Here's an example of an
inference.pyI've used previously, as you can see, Hugging Face Pipelines work too!