![](/img/trans.png)
[英]how to run a batch transform job in sagemaker pipeline via custom inference code?
[英]How to deploy the hugging face model via sagemaker pipeline
下面是从 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
)
如何通过 sagemaker 管道部署此 model。
如何将此代码包含在 sagemaker 管道中。
SageMaker 管道提供许多具有大量功能的不同组件。 您的问题很笼统,需要针对特定问题进行上下文化。
你必须先从建立管道开始。 请参阅完整指南“ 定义管道”。
我的答案是遵循这份准确回答您问题的官方 AWS 指南:
SageMaker Pipelines:训练 Hugging Face model,用 Lambda 步骤部署它
基本上,您需要使用所需的组件构建管道架构,并在Model Registry中注册经过训练的 model。
接下来,您可以遵循两条路径:
register_step.properties.ModelPackageArn
或使用 boto3 的外部脚本中获取它(例如使用list_model_packages )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.