[英]How to deploy the hugging face model via sagemaker pipeline
Below is the code to get the model from Hugging Face Hub and deploy the same model via sagemaker.下面是从 Hugging Face Hub 获取 model 并通过 sagemaker 部署相同的 model 的代码。
from sagemaker.huggingface import HuggingFaceModel
import sagemaker
role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
'HF_MODEL_ID':'siebert/sentiment-roberta-large-english',
'HF_TASK':'text-classification'
}
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
transformers_version='4.17.0',
pytorch_version='1.10.2',
py_version='py38',
env=hub,
role=role,
)
# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
initial_instance_count=1, # number of instances
instance_type='ml.g4dn.xlarge' # ec2 instance type
)
How can I deploy this model via sagemaker pipeline.如何通过 sagemaker 管道部署此 model。
How can I include this code in sagemaker pipeline.如何将此代码包含在 sagemaker 管道中。
SageMaker pipelines offer many different components with lots of functionality. SageMaker 管道提供许多具有大量功能的不同组件。 Your question is quite general and needs to be contextualized to a specific problem.
您的问题很笼统,需要针对特定问题进行上下文化。
You have to start with putting up a pipeline first.你必须先从建立管道开始。 See the complete guide " Defining a pipeline ".
请参阅完整指南“ 定义管道”。
My answer is to follow this official AWS guide that answers your question exactly:我的答案是遵循这份准确回答您问题的官方 AWS 指南:
SageMaker Pipelines: train a Hugging Face model, deploy it with a Lambda step SageMaker Pipelines:训练 Hugging Face model,用 Lambda 步骤部署它
Basically, you need to build your pipeline architecture with the components you need and register the trained model within the Model Registry .基本上,您需要使用所需的组件构建管道架构,并在Model Registry中注册经过训练的 model。
Next, you have two paths you can follow:接下来,您可以遵循两条路径:
register_step.properties.ModelPackageArn
or in an external script using boto3 (eg using list_model_packages )register_step.properties.ModelPackageArn
或使用 boto3 的外部脚本中获取它(例如使用list_model_packages )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.