How to specify requirement for a decord Python library to SageMaker?

I did some exploration to deploy a videoMAE model on SageMaker. I managed to deploy but I was unable to confirm if I have done it correctly as I encountered some errors using it to do predictions.

For preliminaries, I replicated the steps verbatim at https://huggingface.co/docs/sagemaker/inference#deploy-a-model-from-the-hub

I was able to successfully do this and the prediction works.

I duplicated this notebook and change the model_id and task to

‘HF_MODEL_ID’:‘hocheewai/videomae-base-finetuned-ucf101-subset’

‘HF_TASK’:‘video-classification’

This model (i.e., 'hocheewai/videomae-base-finetuned-ucf101-subset) is a just a duplicate of another model and has been deployed on Hugging Faces spaces, https://huggingface.co/spaces/hocheewai/hocheewai-videomae-base-finetuned-ucf101-subset. This model works in the Hugging Face Spaces environment.

Next, I attempted to deploy to SageMaker. I was also able to deploy to Sagemaker. However, when I attempt a prediction, I encounter an error,

““message”: “\nVideoClassificationPipeline requires the decord library but it was not found in your environment. You can install it with pip: pip install\ndecord. Please note that you may need to restart your runtime after installation.\n”.

It seems as if this Python library is missing from the environment that the SageMaker endpoint is pointing to.

Therefore, during deployment, how can I specify that there is a requirements for this library to SageMaker? Is it something to do with the following?

from sagemaker.huggingface import HuggingFaceModel

# Hub Model configuration. https://huggingface.co/models
hub = {
  'HF_MODEL_ID':'hocheewai/videomae-base-finetuned-ucf101-subset', # model_id from hf.co/models
  'HF_TASK':'video-classification' # NLP task you want to use for predictions
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
   env=hub,
   role=role, # iam role with permissions to create an Endpoint
   transformers_version="4.26", # transformers version used
   pytorch_version="1.13", # pytorch version used
   py_version="py39", # python version of the DLC
)

The problem has been resolved. The solution is to extend the pre-built container

763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-inference:2.0.0-transformers4.28.1-cpu-py310-ubuntu20.04

by following the procedure at Extend a Pre-built Container - Amazon SageMaker

The “extension” is just to add RUN pip install decord.

Also ensure the IAM role attached to your Sagemaker notebook has this permission,

AmazonEC2ContainerRegistryFullAccess

If not, proceed to add it.

Once I did these, I was able to predict successfully.