Amazon SageMaker 文档
参考
并获得增强的文档体验
开始使用
参考
深度学习容器
您可以在下面找到当前可用的 Hugging Face DLC 的版本表。该表不包含完整的 image_uri
,这里有两个示例说明如何在需要时构建它们。
手动构建 image_uri
{dlc-aws-account-id}.dkr.ecr.{region}.amazonaws.com/huggingface-{framework}-{(training | inference)}:{framework-version}-transformers{transformers-version}-{device}-{python-version}-{device-tag}
dlc-aws-account-id
: 拥有 ECR 仓库的 AWS 账户 ID。您可以在这里找到它们region
: 您想要使用的 AWS 区域。framework
: 您想要使用的框架,pytorch
或tensorflow
。(training | inference)
: 训练或推理模式。framework-version
: 您想要使用的框架版本。transformers-version
: 您想要使用的 transformers 库的版本。device
: 您想要使用的设备,cpu
或gpu
。python-version
: DLC 的 python 版本。device-tag
: 您想要使用的设备标签。设备标签可以包括操作系统版本和 cuda 版本
示例 1:PyTorch 训练: 763104351884.dkr.ecr.us-west-2.amazonaws.com/huggingface-pytorch-training:1.6.0-transformers4.4.2-gpu-py36-cu110-ubuntu18.04
示例 2:Tensorflow 推理: 763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-tensorflow-inference:2.4.1-transformers4.6.1-cpu-py37-ubuntu18.04
训练 DLC 概述
训练 DLC 概述包括所有已发布和可用的 Hugging Face 训练 DLC。它包括用于 GPU 的 PyTorch 和 TensorFlow 风格版本。
🤗 Transformers 版本 | 🤗 Datasets 版本 | PyTorch/TensorFlow 版本 | 类型 | 设备 | Python 版本 |
---|---|---|---|---|---|
4.4.2 | 1.5.0 | PyTorch 1.6.0 | 训练 | GPU | 3.6 |
4.4.2 | 1.5.0 | TensorFlow 2.4.1 | 训练 | GPU | 3.7 |
4.5.0 | 1.5.0 | PyTorch 1.6.0 | 训练 | GPU | 3.6 |
4.5.0 | 1.5.0 | TensorFlow 2.4.1 | 训练 | GPU | 3.7 |
4.6.1 | 1.6.2 | PyTorch 1.6.0 | 训练 | GPU | 3.6 |
4.6.1 | 1.6.2 | PyTorch 1.7.1 | 训练 | GPU | 3.6 |
4.6.1 | 1.6.2 | TensorFlow 2.4.1 | 训练 | GPU | 3.7 |
4.10.2 | 1.11.0 | PyTorch 1.8.1 | 训练 | GPU | 3.6 |
4.10.2 | 1.11.0 | PyTorch 1.9.0 | 训练 | GPU | 3.8 |
4.10.2 | 1.11.0 | TensorFlow 2.4.1 | 训练 | GPU | 3.7 |
4.10.2 | 1.11.0 | TensorFlow 2.5.1 | 训练 | GPU | 3.7 |
4.11.0 | 1.12.1 | PyTorch 1.9.0 | 训练 | GPU | 3.8 |
4.11.0 | 1.12.1 | TensorFlow 2.5.1 | 训练 | GPU | 3.7 |
4.12.3 | 1.15.1 | PyTorch 1.9.1 | 训练 | GPU | 3.8 |
4.12.3 | 1.15.1 | TensorFlow 2.5.1 | 训练 | GPU | 3.7 |
4.17.0 | 1.18.4 | PyTorch 1.10.2 | 训练 | GPU | 3.8 |
4.17.0 | 1.18.4 | TensorFlow 2.6.3 | 训练 | GPU | 3.8 |
4.26.0 | 2.9.0 | PyTorch 1.13.1 | 训练 | GPU | 3.9 |
推理 DLC 概述
推理 DLC 概述包括所有已发布和可用的 Hugging Face 推理 DLC。它包括用于 CPU、GPU 和 AWS Inferentia 的 PyTorch 和 TensorFlow 风格版本。
🤗 Transformers 版本 | PyTorch/TensorFlow 版本 | 类型 | 设备 | Python 版本 |
---|---|---|---|---|
4.6.1 | PyTorch 1.7.1 | 推理 | CPU | 3.6 |
4.6.1 | PyTorch 1.7.1 | 推理 | GPU | 3.6 |
4.6.1 | TensorFlow 2.4.1 | 推理 | CPU | 3.7 |
4.6.1 | TensorFlow 2.4.1 | 推理 | GPU | 3.7 |
4.10.2 | PyTorch 1.8.1 | 推理 | GPU | 3.6 |
4.10.2 | PyTorch 1.9.0 | 推理 | GPU | 3.8 |
4.10.2 | TensorFlow 2.4.1 | 推理 | GPU | 3.7 |
4.10.2 | TensorFlow 2.5.1 | 推理 | GPU | 3.7 |
4.10.2 | PyTorch 1.8.1 | 推理 | CPU | 3.6 |
4.10.2 | PyTorch 1.9.0 | 推理 | CPU | 3.8 |
4.10.2 | TensorFlow 2.4.1 | 推理 | CPU | 3.7 |
4.10.2 | TensorFlow 2.5.1 | 推理 | CPU | 3.7 |
4.11.0 | PyTorch 1.9.0 | 推理 | GPU | 3.8 |
4.11.0 | TensorFlow 2.5.1 | 推理 | GPU | 3.7 |
4.11.0 | PyTorch 1.9.0 | 推理 | CPU | 3.8 |
4.11.0 | TensorFlow 2.5.1 | 推理 | CPU | 3.7 |
4.12.3 | PyTorch 1.9.1 | 推理 | GPU | 3.8 |
4.12.3 | TensorFlow 2.5.1 | 推理 | GPU | 3.7 |
4.12.3 | PyTorch 1.9.1 | 推理 | CPU | 3.8 |
4.12.3 | TensorFlow 2.5.1 | 推理 | CPU | 3.7 |
4.12.3 | PyTorch 1.9.1 | 推理 | Inferentia | 3.7 |
4.17.0 | PyTorch 1.10.2 | 推理 | GPU | 3.8 |
4.17.0 | TensorFlow 2.6.3 | 推理 | GPU | 3.8 |
4.17.0 | PyTorch 1.10.2 | 推理 | CPU | 3.8 |
4.17.0 | TensorFlow 2.6.3 | 推理 | CPU | 3.8 |
4.26.0 | PyTorch 1.13.1 | 推理 | CPU | 3.9 |
4.26.0 | PyTorch 1.13.1 | 推理 | GPU | 3.9 |
Hugging Face Transformers Amazon SageMaker 示例
示例 Jupyter 笔记本,演示如何使用 Hugging Face Transformers 和 Amazon SageMaker 以及 Amazon SageMaker Python SDK 构建、训练和部署模型。
笔记本 | 类型 | 描述 |
---|---|---|
01 PyTorch 入门 | 训练 | 关于如何使用 PyTorch 微调预训练的 Hugging Face Transformer 以进行文本分类的入门端到端示例 |
02 TensorFlow 入门 | 训练 | 关于如何使用 TensorFlow 微调预训练的 Hugging Face Transformer 以进行文本分类的入门端到端示例 |
03 分布式训练:数据并行 | 训练 | 关于如何使用分布式训练和数据并行策略,使用 Amazon SageMaker 数据并行性微调预训练的 Hugging Face Transformer 以进行问答的端到端示例 |
04 分布式训练:模型并行 | 训练 | 关于如何使用分布式训练和模型并行策略,使用 Amazon SageMaker 模型并行性预训练 Hugging Face Transformer 的端到端示例 |
05 如何使用 Spot Instances 和检查点 | 训练 | 关于如何使用 Spot Instances 和检查点来降低训练成本的端到端示例 |
06 使用 SageMaker Metrics 进行实验跟踪 | 训练 | 关于如何使用 SageMaker 指标跟踪您的实验和训练作业的端到端示例 |
07 分布式训练:数据并行 | 训练 | 关于如何将 Amazon SageMaker 数据并行性与 TensorFlow 一起使用的端到端示例 |
08 分布式训练:使用 T5/BART 进行摘要 | 训练 | 关于如何使用 Amazon SageMaker 数据并行性微调 BART/T5 以进行摘要的端到端示例 |
09 视觉:微调 ViT | 训练 | 关于如何微调 Vision Transformer 以进行图像分类的端到端示例 |
10 从 Amazon S3 部署 HF Transformer | 推理 | 关于如何从 Amazon S3 部署模型的端到端示例 |
11 从 Hugging Face Hub 部署 HF Transformer | 推理 | 关于如何从 Hugging Face Hub 部署模型的端到端示例 |
12 使用 Amazon SageMaker Batch Transform 进行批量处理 | 推理 | 关于如何使用 Amazon SageMaker Batch Transform 进行批量处理的端到端示例 |
13 自动缩放 SageMaker Endpoints | 推理 | 关于如何对 HF Endpoint 使用自动缩放的端到端示例 |
14 微调并推送到 Hub | 训练 | 关于如何使用 Hugging Face Hub 作为 MLOps 后端以在训练期间保存检查点的端到端示例 |
15 训练编译器 | 训练 | 关于如何使用 Amazon SageMaker 训练编译器来加速训练时间的端到端示例 |
16 异步推理 | 推理 | 关于如何将 Amazon SageMaker 异步推理端点与 Hugging Face Transformers 一起使用的端到端示例 |
17 自定义 inference.py 脚本 | 推理 | 关于如何为 Sentence Transformers 和句子嵌入创建自定义 inference.py 的端到端示例 |
18 AWS Inferentia | 推理 | 关于如何使用 AWS Inferentia 来加速推理时间的端到端示例 |
推理工具包 API
推理工具包接受 inputs
键中的输入,并支持 parameters
键中的其他 pipelines
参数。您可以提供来自 pipelines
的任何受支持的 kwargs
作为 parameters
。
推理工具包 API 支持的任务包括
文本分类
情感分析
token 分类
特征提取
填充掩码
摘要
翻译_xx_到_yy
text2text 生成
文本生成
音频分类
自动语音识别
对话
图像分类
图像分割
物体检测
表格问答
零样本分类
零样本图像分类
请参阅以下请求示例以了解某些任务
文本分类
{
"inputs": "This sound track was beautiful! It paints the senery in your mind so well I would recomend it
even to people who hate vid. game music!"
}
情感分析
{
"inputs": "Don't waste your time. We had two different people come to our house to give us estimates for
a deck (one of them the OWNER). Both times, we never heard from them. Not a call, not the estimate, nothing."
}
token 分类
{
"inputs": "My name is Sylvain and I work at Hugging Face in Brooklyn."
}
问答
{
"inputs": {
"question": "What is used for inference?",
"context": "My Name is Philipp and I live in Nuremberg. This model is used with sagemaker for inference."
}
}
零样本分类
{
"inputs": "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
"parameters": {
"candidate_labels": ["refund", "legal", "faq"]
}
}
表格问答
{
"inputs": {
"query": "How many stars does the transformers repository have?",
"table": {
"Repository": ["Transformers", "Datasets", "Tokenizers"],
"Stars": ["36542", "4512", "3934"],
"Contributors": ["651", "77", "34"],
"Programming language": ["Python", "Python", "Rust, Python and NodeJS"]
}
}
}
参数化请求
{
"inputs": "Hugging Face, the winner of VentureBeat’s Innovation in Natural Language Process/Understanding Award for 2021, is looking to level the playing field. The team, launched by Clément Delangue and Julien Chaumond in 2016, was recognized for its work in democratizing NLP, the global market value for which is expected to hit $35.1 billion by 2026. This week, Google’s former head of Ethical AI Margaret Mitchell joined the team.",
"parameters": {
"repetition_penalty": 4.0,
"length_penalty": 1.5
}
}
推理工具包环境变量
推理工具包实现了各种额外的环境变量以简化部署。下面显示了 Hugging Face 特定环境变量的完整列表
HF_TASK
HF_TASK
定义了 🤗 Transformers 管道使用的任务。有关任务的完整列表,请参阅此处。
HF_TASK="question-answering"
HF_MODEL_ID
HF_MODEL_ID
定义了模型 ID,该模型 ID 在创建 SageMaker 端点时自动从 hf.co/models 加载。所有 🤗 Hub 的 10,000 多个模型都可通过此环境变量获得。
HF_MODEL_ID="distilbert-base-uncased-finetuned-sst-2-english"
HF_MODEL_REVISION
HF_MODEL_REVISION
是 HF_MODEL_ID
的扩展,允许您定义或固定模型修订版本,以确保您始终在 SageMaker 端点上加载相同的模型。
HF_MODEL_REVISION="03b4d196c19d0a73c7e0322684e97db1ec397613"
HF_API_TOKEN
HF_API_TOKEN
定义了您的 Hugging Face 授权令牌。 HF_API_TOKEN
用作远程文件(如私有模型)的 HTTP Bearer 授权。您可以在您的 Hugging Face 帐户的设置下找到您的令牌。
HF_API_TOKEN="api_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"