You can have a HuggingFace model up and running on SageMaker in just a few lines of code.
===
First, you need to import the necessary modules:
from sagemaker import get_execution_role
from sagemaker.huggingface.model import HuggingFaceModel
Set up the necessary environment variables, including the model ID, instance type, and versions.
= "baai-bge-large-en-v1-5"
ENDPOINT_NAME
= {
HF_ENV 'HF_MODEL_ID':'BAAI/bge-large-en-v1.5',
'HF_TASK':'feature-extraction'
}
= "ml.m5.xlarge"
INSTANCE_TYPE
= "4.26"
TRANSFORMER_VER
= "py39"
PY_VERSION
= "1.13" PYTORCH_VERSION
Create a HuggingFaceModel model with the specified configurations.
Here we are using SageMaker’s built-in container images with specific versions of python, pytorch and transformers. A full list of available images can be found here.
= HuggingFaceModel(
huggingface_model =HF_ENV,
env=get_execution_role(),
role=TRANSFORMER_VER,
transformers_version=PYTORCH_VERSION,
pytorch_version=PY_VERSION,
py_version )
Then use the .deploy
method.
= huggingface_model.deploy(
predictor =ENDPOINT_NAME,
endpoint_name=1,
initial_instance_count=INSTANCE_TYPE
instance_type )
And that’s it! With just a few lines of code, your HuggingFace model is live on AWS SageMaker. It’s incredibly fast to get started and deploy.