

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 亚马逊 SageMaker JumpStart 基金会模型
<a name="jumpstart-foundation-models"></a>

Amaz state-of-the-art on SageMaker JumpStart 为内容编写、代码生成、问题解答、文案撰写、摘要、分类、信息检索等用例提供基础模型。使用 JumpStart 基础模型构建自己的生成式 AI 解决方案，并将自定义解决方案与其他 SageMaker AI 功能集成。有关更多信息，请参阅 [Amazon 入门 SageMaker JumpStart](https://aws.amazon.com/sagemaker/jumpstart/getting-started/)。

基础模型是一种大型的预训练模型，可进行调整以用于许多下游任务，通常用作开发更专业化模型的起点。基础模型的示例包括 ma LLa -3-70b、BLOOM 176B、FLAN-T5 XL 或 GPT-J 6B，它们已针对大量文本数据进行了预训练，可以针对特定的语言任务进行微调。

Amaz SageMaker JumpStart on 载入并维护公开可用的基础模型，供您访问、自定义和集成到您的机器学习生命周期中。有关更多信息，请参阅 [公开可用的基础模型](jumpstart-foundation-models-latest.md#jumpstart-foundation-models-latest-publicly-available)。Amazon SageMaker JumpStart 还包括来自第三方提供商的专有基础模型。有关更多信息，请参阅 [专有基础模型](jumpstart-foundation-models-latest.md#jumpstart-foundation-models-latest-proprietary)。

要开始探索和尝试可用模型，请参阅[JumpStart 基础模型用法](jumpstart-foundation-models-use.md)。所有基础模型均可通过编程方式与 SageMaker Python SDK 一起使用。有关更多信息，请参阅 [在 SageMaker Python SDK 中使用基础模型](jumpstart-foundation-models-use-python-sdk.md)。

有关选择模型时注意事项的更多信息，请参阅[示范源和许可协议](jumpstart-foundation-models-choose.md)。

有关自定义和微调基础模型的具体信息，请参阅[基础模型自定义](jumpstart-foundation-models-customize.md)。

有关基础模型的更多一般信息，请参阅白皮书[关于基础模型的机遇和风险](https://arxiv.org/abs/2108.07258)。

**Topics**
+ [

# 可用的基础模型
](jumpstart-foundation-models-latest.md)
+ [

# JumpStart 基础模型用法
](jumpstart-foundation-models-use.md)
+ [

# 示范源和许可协议
](jumpstart-foundation-models-choose.md)
+ [

# 基础模型自定义
](jumpstart-foundation-models-customize.md)
+ [

# 评估 Studio 中的文本生成基础模型
](jumpstart-foundation-models-evaluate.md)
+ [

# 示例笔记本
](jumpstart-foundation-models-example-notebooks.md)

# 可用的基础模型
<a name="jumpstart-foundation-models-latest"></a>

Amazon SageMaker JumpStart 提供 state-of-the-art内置的公开可用和专有基础模型，用于自定义并集成到您的生成式 AI 工作流程中。

## 公开可用的基础模型
<a name="jumpstart-foundation-models-latest-publicly-available"></a>

Amaz SageMaker JumpStart on 载入并维护来自第三方来源的开源基础模型。要开始使用其中一种公开可用的模型，请查看[JumpStart 基础模型用法](jumpstart-foundation-models-use.md)或浏览可用的[示例笔记本](jumpstart-foundation-models-example-notebooks.md)之一。在公开可用模型的给定示例笔记本中，尝试切换模型 ID，以实验同一模型系列中的不同模型。

有关使用软件开发 SageMaker Python工具包部署公开 JumpStart 基础模型的模型 IDs 和资源的更多信息，请参阅[在 SageMaker Python SDK 中使用基础模型](jumpstart-foundation-models-use-python-sdk.md)。

按照定义，基础模型可以根据多种下游任务进行调整。基础模型在大量的通用领域数据上进行训练，可以针对多种使用案例实施相同的模型或进行自定义。选择基础模型时，首先要定义一项特定任务，例如文本生成或映像生成。

### 公开可用的时间序列预测模型
<a name="jumpstart-foundation-models-choose-task-time-series-forecasting"></a>

时间序列预测模型旨在分析和预测一段时间内的序列数据。这些模型可应用于金融、天气预报或能源需求预测等多个领域。Chronos 模型专为时间序列预测任务定制，可根据历史数据规律进行准确预测。


| 模型名称 | 模型 ID | 模型来源 | 可微调 | 
| --- | --- | --- | --- | 
| Chronos T5 Small | autogluon-forecasting-chronos-t5-small | Amazon | 否 | 
| Chronos T5 Base | autogluon-forecasting-chronos-t5-base | Amazon | 否 | 
| Chronos T5 Large | autogluon-forecasting-chronos-t5-large | Amazon | 否 | 
| Chronos-Bolt Small | autogluon-forecasting-chronos-bolt-small | Amazon |  否  | 
| Chronos-Bolt Base | autogluon-forecasting-chronos-bolt-base | Amazon |  否  | 

### 公开可用的文本生成模型
<a name="jumpstart-foundation-models-choose-task-text-generation"></a>

文本生成基础模型可用于多种下游任务，包括文本摘要、文本分类、问题回答、长篇内容生成、简短文案写作、信息提取等。

要探索最新的文本生成 JumpStart 基础模型，请使用 [Amazon 入门 SageMaker JumpStart](https://aws.amazon.com/sagemaker/jumpstart/getting-started/?sagemaker-jumpstart-cards.sort-by=item.additionalFields.priority&sagemaker-jumpstart-cards.sort-order=asc&awsf.sagemaker-jumpstart-filter-product-type=product-type%23foundation-model&awsf.sagemaker-jumpstart-filter-text=ml-task-type%23text-generation&awsf.sagemaker-jumpstart-filter-vision=*all&awsf.sagemaker-jumpstart-filter-tabular=*all&awsf.sagemaker-jumpstart-filter-audio-tasks=*all&awsf.sagemaker-jumpstart-filter-multimodal=*all&awsf.sagemaker-jumpstart-filter-RL=*all&awsm.page-sagemaker-jumpstart-cards=1)产品描述页面上的 “**文本生成**” 筛选器。您也可以直接在 Amazon SageMaker Studio 用户界面或 SageMaker Studio Classic 用户界面中根据任务探索基础模型。只有一部分公开可用的文本生成模型可供微调。 JumpStart有关更多信息，请参阅 [在 Amazon SageMaker Studio 经典版中使用基础模型](jumpstart-foundation-models-use-studio.md)。

### 公开可用的映像生成模型
<a name="jumpstart-foundation-models-choose-task-image-generation"></a>

JumpStart 提供了各种各样的 Stable Diffusion 图像生成基础模型，包括来自 Stability AI 的基础模型以及用于特定 text-to-image任务的预训练模型。Hugging Face如果你需要微调 text-to-image基础模型，你可以使用 Stability AI 中的 Stable Diffusion 2.1 基础版。如果您想探索已经接受过特定美术风格训练的模型，可以Hugging Face直接在 Amazon SageMaker Studio 用户界面或 SageMaker Studio Classic 用户界面中探索众多第三方模型中的一个。

要探索最新的图片生成 JumpStart 基础模型，请使用 [Amazon 入门 SageMaker JumpStart](https://aws.amazon.com/sagemaker/jumpstart/getting-started/?sagemaker-jumpstart-cards.sort-by=item.additionalFields.priority&sagemaker-jumpstart-cards.sort-order=asc&awsf.sagemaker-jumpstart-filter-product-type=product-type%23foundation-model&awsf.sagemaker-jumpstart-filter-text=*all&awsf.sagemaker-jumpstart-filter-vision=*all&awsf.sagemaker-jumpstart-filter-tabular=*all&awsf.sagemaker-jumpstart-filter-audio-tasks=*all&awsf.sagemaker-jumpstart-filter-multimodal=ml-task-type%23txt2img&awsf.sagemaker-jumpstart-filter-RL=*all&awsm.page-sagemaker-jumpstart-cards=1)产品描述页面上的 “**文字转图片**” 筛选器。要开始使用您选择 text-to-image的基础模型，请参阅[JumpStart 基础模型用法](jumpstart-foundation-models-use.md)。

## 专有基础模型
<a name="jumpstart-foundation-models-latest-proprietary"></a>

亚马逊允许访问第三方 SageMaker JumpStart 提供商提供的专有基础模型，例如[AI21 实验室](https://www.ai21.com/)、[Coher](https://cohere.com/) e 和。[LightOn](https://www.lighton.ai/)

要开始使用这些专有模型之一，请参阅[JumpStart 基础模型用法](jumpstart-foundation-models-use.md)。要使用专有基础模型，您必须先在 AWS Marketplace中订阅该模型。订阅模型后，在 Studio 或 SageMaker Studio Classic 中找到基础模型。有关更多信息，请参阅 [SageMaker JumpStart 预训练模型](studio-jumpstart.md)。

要探索适用于各种用例的最新专有基础模型，请参阅 [Amazon 入门 SageMaker JumpStart](https://aws.amazon.com/sagemaker/jumpstart/getting-started/?sagemaker-jumpstart-cards.sort-by=item.additionalFields.priority&sagemaker-jumpstart-cards.sort-order=asc&awsf.sagemaker-jumpstart-filter-product-type=product-type%23foundation-model&awsf.sagemaker-jumpstart-filter-text=*all&awsf.sagemaker-jumpstart-filter-vision=*all&awsf.sagemaker-jumpstart-filter-tabular=*all&awsf.sagemaker-jumpstart-filter-audio-tasks=*all&awsf.sagemaker-jumpstart-filter-multimodal=*all&awsf.sagemaker-jumpstart-filter-RL=*all&sagemaker-jumpstart-cards.q=proprietary&sagemaker-jumpstart-cards.q_operator=AND)。

# JumpStart 基础模型用法
<a name="jumpstart-foundation-models-use"></a>

通过 Amazon Studio 或 Amazon SageMaker Studio Class SageMaker ic 选择、训练或部署 JumpStart 基础模型，通过 SageMaker Python软件开发工具包以编程方式使用 JumpStart 基础模型，或者直接通过 SageMaker AI 控制台发现基础模型。

**Topics**
+ [

# 在 Studio 中使用基础模型
](jumpstart-foundation-models-use-studio-updated.md)
+ [

# 在 Amazon SageMaker Studio 经典版中使用基础模型
](jumpstart-foundation-models-use-studio.md)
+ [

# 在 SageMaker Python SDK 中使用基础模型
](jumpstart-foundation-models-use-python-sdk.md)
+ [

# 在 SageMaker AI 控制台中探索基础模型
](jumpstart-foundation-models-use-console.md)

# 在 Studio 中使用基础模型
<a name="jumpstart-foundation-models-use-studio-updated"></a>

Amazon SageMaker Studio 允许您直接通过 Studio 用户界面微调、部署和评估公开和专有 JumpStart 基础模型。

**重要**  
截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。以下部分专门介绍如何使用更新后的 Studio 体验。有关使用 Studio Classic 应用程序的信息，请参阅 [亚马逊 SageMaker Studio 经典版](studio.md)。

要开始使用，请导航至 Amazon SageMaker Studio 的 JumpStart 登录页面。您可以从**主页**页面或左侧面板菜单访问它。在**JumpStart**登录页面上，您可以浏览公开和专有模型提供商提供的模型中心，并搜索模型。

在每个模型中心中，您可以按**最喜欢次数**、**下载次数最多**、**最近更新次数**对模型进行排序，也可以按任务对模型进行筛选。选择一个模型，查看其详情卡。在模型详情卡上，您可以根据可用选项选择**微调**、**部署**或**评估**模型。请注意，并非所有模型都可用于微调或评估。

有关开始使用 Amazon SageMaker Studio 的更多信息，请参阅[亚马逊 SageMaker Studio](studio-updated.md)。

**Topics**
+ [

# 在 Studio 中微调模型
](jumpstart-foundation-models-use-studio-updated-fine-tune.md)
+ [

# 在 Studio 中部署模型
](jumpstart-foundation-models-use-studio-updated-deploy.md)
+ [

# 在 Studio 中评估模型
](jumpstart-foundation-models-use-studio-updated-evaluate.md)
+ [

# 在 Amazon Bedrock 中使用你的 SageMaker JumpStart 模型
](jumpstart-foundation-models-use-studio-updated-register-bedrock.md)

# 在 Studio 中微调模型
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune"></a>

微调过程在新数据集上训练已经预训练的模型，而无需从头开始训练。这个过程也称为转移学习，可以使用较小数据集和较短的训练时间生成准确模型。要微调 JumpStart基础模型，请导航到 Studio 用户界面中的模型详细信息卡。有关如何在 Studio JumpStart 中打开的更多信息，请参阅[JumpStart 在工作室中打开](studio-jumpstart.md#jumpstart-open-studio)。导航到您选择的模型详情卡后，选择右上角的**训练**。请注意，并非所有模型都有微调功能。

**重要**  
有些基础模型要求在微调前明确接受最终用户许可协议 (EULA)。有关更多信息，请参阅 [亚马逊 SageMaker Studio 接受最终用户许可协议](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula-studio)。

## 模型设置
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-model"></a>

在 Amazon SageMaker Studio 中使用预训练 JumpStart 的基础模型时，默认情况下会填充**模型构件位置（Amazon S3 URI）**。要编辑默认的 Amazon S3 URI，请选择**输入模型构件位置**。并非所有模型都支持更改模型构件的位置。

## 数据设置
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-data"></a>

在**数据**字段中，提供指向您的训练数据集位置的 Amazon S3 URI。默认的 Amazon S3 URI 指向一个示例训练数据集。要编辑默认的 Amazon S3 URI，请选择**输入训练数据集**并更改 URI。请务必查看 Amazon SageMaker Studio 中的模型详情卡，了解有关格式化训练数据的信息。

## 超参数
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-hyperparameters"></a>

您可以自定义用于微调模型的训练作业的超参数。每个可微调模型的可用超参数因模型而异。

以下超参数在模型中很常见：
+ **纪元** – 一个纪元是遍历整个数据集的一个周期。通过多个时间间隔完成一个批次，通过多个批次最终完成一个纪元。系统运行多个纪元，直到模型的准确性达到可接受的水平，或者说当错误率降至可接受的水平以下时。
+ **学习率** – 各个纪元之间应该变化的值的数量。随着模型的优化，其内部权重将被调整，并检查错误率以确定模型是否有所改善。典型的学习率为 0.1 或 0.01，其中 0.01 是一个小得多的调整，可能会导致训练需要很长时间才能收敛，而 0.1 则要大得多，可能会导致训练过度。这是在训练模型时可能会调整的主要超参数之一。请注意，对于文本模型，小得多的学习率（BERT 为 5e-5）可以生成更准确的模型。
+ **Batch siz** e — 要从数据集中为每个间隔选择的记录数量，然后发送到 GPUs 进行训练。

查看 Studio 用户界面中模型详情卡的工具提示和其他信息，了解所选模型特定超参数的更多信息。

有关可用超参数的更多信息，请参阅 [通常支持的微调超参数](jumpstart-foundation-models-fine-tuning.md#jumpstart-foundation-models-fine-tuning-hyperparameters)。

## 部署
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-instance"></a>

为训练作业指定训练实例类型和输出构件位置。在微调 Studio 用户界面中，您只能选择与所选模型兼容的实例。默认输出项目位置是 SageMaker AI 默认存储桶。要更改输出构件位置，请选择**输入输出构件位置**，然后更改 Amazon S3 URI。

## 安全性
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-security"></a>

指定用于训练任务的安全设置，包括 A SageMaker I 用于训练模型的 IAM 角色、您的训练作业是否应连接到虚拟私有云 (VPC)，以及用于保护数据的任何加密密钥。

## 附加信息
<a name="jumpstart-foundation-models-use-studio-updated-fine-tune-additional-info"></a>

在**其他信息**字段中，您可以编辑训练作业名称。您还可以添加和删除键值对形式的标签，以帮助组织和分类您的微调训练作业。

提供微调配置信息后，选择**提交**。如果您选择微调的预训练基础模型要求在训练前明确同意最终用户许可协议 (EULA)，则会在弹出窗口中提供 EULA。要接受 EULA 的条款，请选择**接受**。在下载或使用模型之前，您有责任查看和遵守任何适用的许可证条款，并确保您的使用场景可以接受这些条款。

# 在 Studio 中部署模型
<a name="jumpstart-foundation-models-use-studio-updated-deploy"></a>

要部署 JumpStart 基础模型，请导航到 Studio 用户界面中的模型详细信息卡。有关如何在 Studio JumpStart 中打开的更多信息，请参阅[JumpStart 在工作室中打开](studio-jumpstart.md#jumpstart-open-studio)。导航到所选模型的详情页面后，在 Studio 用户界面的右上角选择**部署**。然后，按照[使用 SageMaker Studio 部署模型中的步骤进行](https://docs.aws.amazon.com/sagemaker/latest/dg/realtime-endpoints-deploy-models.html#deploy-models-studio)操作。

**重要**  
一些基础模型在部署之前，要求明确接受最终用户许可协议 (EULA)。有关更多信息，请参阅 [亚马逊 SageMaker Studio 接受最终用户许可协议](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula-studio)。

# 在 Studio 中评估模型
<a name="jumpstart-foundation-models-use-studio-updated-evaluate"></a>

亚马逊 SageMaker JumpStart 已与 Studio 中的 Cl SageMaker arify 基础模型评估 (FME) 集成。如果 JumpStart 模型具有内置评估功能，则可以在 JumpStart Studio 用户界面中模型详情页面的右上角选择**评估**。有关更多信息，请参阅[评估基础模型](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-models-evaluate.html)。

# 在 Amazon Bedrock 中使用你的 SageMaker JumpStart 模型
<a name="jumpstart-foundation-models-use-studio-updated-register-bedrock"></a>

您可以将已从亚马逊部署的模型注册 SageMaker JumpStart 到 Amazon Bedrock。您可通过 Amazon Bedrock，在多个端点后面托管模型。您还可以使用 Amazon Bedrock 特征，例如座席和知识库。有关使用 Amazon Bedrock 模型的更多信息，请参阅 [https://docs.aws.amazon.com/bedrock/latest/userguide/amazon-bedrock-marketplace.html](https://docs.aws.amazon.com/bedrock/latest/userguide/amazon-bedrock-marketplace.html)。

**重要**  
要将您的模型迁移到 Amazon Bedrock，我们建议将[AmazonBedrockFullAccess](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AmazonBedrockFullAccess.html)策略附加到您的 IAM 角色。如果无法附加托管策略，请确保您的 IAM 角色拥有下列权限：  

****  

```
{
    	"Version":"2012-10-17",		 	 	 
    	"Statement": [
    		{
    			"Sid": "BedrockAll",
    			"Effect": "Allow",
    			"Action": [
    				"bedrock:*"
    			],
    			"Resource": "*"
    		},
    		{
    			"Sid": "DescribeKey",
    			"Effect": "Allow",
    			"Action": [
    				"kms:DescribeKey"
    			],
    			"Resource": "arn:*:kms:*:::*"
    		},
    		{
    			"Sid": "APIsWithAllResourceAccess",
    			"Effect": "Allow",
    			"Action": [
    				"iam:ListRoles",
    				"ec2:DescribeVpcs",
    				"ec2:DescribeSubnets",
    				"ec2:DescribeSecurityGroups"
    			],
    			"Resource": "*"
    		},
    		{
    			"Sid": "MarketplaceModelEndpointMutatingAPIs",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:CreateEndpoint",
    				"sagemaker:CreateEndpointConfig",
    				"sagemaker:CreateModel",
    				"sagemaker:CreateInferenceComponent",
    				"sagemaker:DeleteInferenceComponent",
    				"sagemaker:DeleteEndpoint",
    				"sagemaker:UpdateEndpoint"
    			],
    			"Resource": [
    				"arn:aws:sagemaker:*:*:endpoint/*",
    				"arn:aws:sagemaker:*:*:endpoint-config/*",
    				"arn:aws:sagemaker:*:*:model/*"
    			],
    			"Condition": {
    				"StringEquals": {
    					"aws:CalledViaLast": "bedrock.amazonaws.com"
    				}
    			}
    		},
    		{
    			"Sid": "BedrockEndpointTaggingOperations",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:AddTags",
    				"sagemaker:DeleteTags"
    			],
    			"Resource": [
    				"arn:aws:sagemaker:*:*:endpoint/*",
    				"arn:aws:sagemaker:*:*:endpoint-config/*",
    				"arn:aws:sagemaker:*:*:model/*"
    			]
    		},
    		{
    			"Sid": "MarketplaceModelEndpointNonMutatingAPIs",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:DescribeEndpoint",
    				"sagemaker:DescribeEndpointConfig",
    				"sagemaker:DescribeModel",
    				"sagemaker:DescribeInferenceComponent",
    				"sagemaker:ListEndpoints",
    				"sagemaker:ListTags"
    			],
    			"Resource": [
    				"arn:aws:sagemaker:*:*:endpoint/*",
    				"arn:aws:sagemaker:*:*:endpoint-config/*",
    				"arn:aws:sagemaker:*:*:model/*"
    			],
    			"Condition": {
    				"StringEquals": {
    					"aws:CalledViaLast": "bedrock.amazonaws.com"
    				}
    			}
    		},
    		{
    			"Sid": "BedrockEndpointInvokingOperations",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:InvokeEndpoint",
    				"sagemaker:InvokeEndpointWithResponseStream"
    			],
    			"Resource": [
    				"arn:aws:sagemaker:*:*:endpoint/*"
    			],
    			"Condition": {
    				"StringEquals": {
    					"aws:CalledViaLast": "bedrock.amazonaws.com"
    				}
    			}
    		},
    		{
    			"Sid": "DiscoveringMarketplaceModel",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:DescribeHubContent"
    			],
    			"Resource": [
    				"arn:aws:sagemaker:*:aws:hub-content/SageMakerPublicHub/Model/*",
    				"arn:aws:sagemaker:*:aws:hub/SageMakerPublicHub"
    			]
    		},
    		{
    			"Sid": "AllowMarketplaceModelsListing",
    			"Effect": "Allow",
    			"Action": [
    				"sagemaker:ListHubContents"
    			],
    			"Resource": "arn:aws:sagemaker:*:aws:hub/SageMakerPublicHub"
    		},
    		{
    			"Sid": "RetrieveSubscribedMarketplaceLicenses",
    			"Effect": "Allow",
    			"Action": [
    				"license-manager:ListReceivedLicenses"
    			],
    			"Resource": [
    				"*"
    			]
    		},
    		{
    			"Sid": "PassRoleToSageMaker",
    			"Effect": "Allow",
    			"Action": [
    				"iam:PassRole"
    			],
    			"Resource": [
    				"arn:aws:iam::*:role/*Sagemaker*ForBedrock*"
    			],
    			"Condition": {
    				"StringEquals": {
    					"iam:PassedToService": [
    						"sagemaker.amazonaws.com",
    						"bedrock.amazonaws.com"
    					]
    				}
    			}
    		},
    		{
    			"Sid": "PassRoleToBedrock",
    			"Effect": "Allow",
    			"Action": [
    				"iam:PassRole"
    			],
    			"Resource": "arn:aws:iam::*:role/*AmazonBedrock*",
    			"Condition": {
    				"StringEquals": {
    					"iam:PassedToService": [
    						"bedrock.amazonaws.com"
    					]
    				}
    			}
    		}
    	]
    }
```
Amazon Bedrock Full Access 策略仅提供对 Amazon Bedrock API 的权限。要在中使用 Amazon Bedrock AWS 管理控制台，您的 IAM 角色还必须具有以下权限：  

```
{
        "Sid": "AllowConsoleS3AccessForBedrockMarketplace",
        "Effect": "Allow",
        "Action": [
          "s3:GetObject",
          "s3:GetBucketCORS",
          "s3:ListBucket",
          "s3:ListBucketVersions",
          "s3:GetBucketLocation"
        ],
        "Resource": "*"
    }
```
如果您要自行编写策略，则必须附上支持对资源执行 Amazon Bedrock Marketplace 操作的策略声明。例如，以下策略支持 Amazon Bedrock 对已部署到端点的模型使用 `InvokeModel` 操作。  

****  

```
{
    
        "Version":"2012-10-17",		 	 	 
        "Statement": [
            {
                "Sid": "BedrockAll",
                "Effect": "Allow",
                "Action": [
                    "bedrock:InvokeModel"
                ],
                "Resource": [
                "arn:aws:bedrock:us-east-1:111122223333:marketplace/model-endpoint/all-access"
                ]
            },
            {
                "Sid": "VisualEditor1",
                "Effect": "Allow",
                "Action": ["sagemaker:InvokeEndpoint"],
                "Resource": "arn:aws:sagemaker:us-east-1:111122223333:endpoint/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/project": "example-project-id",
                        "aws:CalledViaLast": "bedrock.amazonaws.com"
                    }
                }
            }
        ]
    
}
```

部署模型后，您可能就能够在 Amazon Bedrock 中使用该模型了。要查看是否可以在 Amazon Bedrock 中使用该模型，请导航至 Studio 用户界面中的模型详情卡。如果模型卡片上写着 **Bedrock 就绪**，则可以在 Amazon Bedrock 中注册该模型。

**重要**  
默认情况下，Amazon SageMaker JumpStart 会禁用您部署的模型的网络访问权限。如果您启用了网络访问权限，则将无法在 Amazon Bedrock 中使用该模型。如果您想在 Amazon Bedrock 中使用该模型，则必须在禁用网络访问权限的情况下重新部署该模型。

要在 Amazon Bedrock 中使用该模型，请导航至**端点详细信息**页面，然后在 Studio 用户界面右上角选择**配合 Bedrock 使用**。看到弹出窗口后，选择**注册到 Bedrock**。

# 在 Amazon SageMaker Studio 经典版中使用基础模型
<a name="jumpstart-foundation-models-use-studio"></a>

您可以通过 Studio Classic 用户界面微调和部署公开和专有 JumpStart基础模型。

**重要**  
截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。以下部分专门介绍如何使用 Studio Classic 应用程序。有关使用更新的 Studio 体验的信息，请参阅 [亚马逊 SageMaker Studio](studio-updated.md)。  
Studio Classic 仍针对现有工作负载进行维护，但不再可供入门使用。您只能停止或删除现有的 Studio Classic 应用程序，不能创建新的应用程序。我们建议您将[工作负载迁移到全新 Studio 体验](studio-updated-migrate.md)。

要通过 Studio Classic 开始使用，请参阅 [推出亚马逊 SageMaker Studio 经典版](studio-launch.md)。

 ![\[JumpStart foundation models available in Amazon SageMaker Studio Classic.\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/jumpstart/jumpstart-fm-studio.png) 

打开 Amazon SageMaker Studio Classic 后**，在导航窗格的 SageMaker JumpStart 部分选择型号、笔记本电脑、解决方案**。然后，根据您的使用案例，向下滚动以找到**基础模型：文本生成**或**基础模型：图像生成**部分。

您可以在建议的基础模型卡片上选择**查看模型**，也可以选择**浏览所有模型**以查看所有可用于文本生成或图像生成的基础模型。如果您选择查看所有可用模型，则可以按任务、数据类型、内容类型或框架进一步筛选可用模型。您还可以直接在**搜索栏**中搜索模型名称。如果您需要有关选择模型的指导，请参阅[可用的基础模型](jumpstart-foundation-models-latest.md)。

**重要**  
某些基础模型要求明确接受最终用户许可协议 (EULA)。有关更多信息，请参阅 [亚马逊 SageMaker Studio 接受最终用户许可协议](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula-studio)。

当您在 Studio Classic 中为所选基础模型选择了**查看模型**后，可以部署该模型。有关更多信息，请参阅 [部署模型](jumpstart-deploy.md)。

您也可以选择**在笔记本中运行**部分中的**打开笔记本**，直接在 Studio Classic 中运行基础模型的示例笔记本。

**注意**  
要在 Studio Classic 中部署专有基础模型，您必须先在 AWS Marketplace中订阅该模型。该 AWS Marketplace 链接在 Studio Classic 中的相关示例笔记本中提供。

如果模型可以微调，您也可以对模型进行微调。有关更多信息，请参阅 [微调模型](jumpstart-fine-tune.md)。有关哪些 JumpStart 基础模型可以微调的列表，请参阅。[用于微调的基础模型和超参数](jumpstart-foundation-models-fine-tuning.md)

# 在 SageMaker Python SDK 中使用基础模型
<a name="jumpstart-foundation-models-use-python-sdk"></a>

所有 JumpStart 基础模型均可用于使用 SageMaker Python SDK 进行编程部署。

要部署公开可用的基础模型，您可以使用其模型 ID。您可以在[带有预训练模型表 IDs 的内置算法中找到所有公开基础模型的模型](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html)。在**搜索**栏中搜索基础模型名称。使用**显示条目**下拉列表或分页控件浏览可用的模型。

在 AWS Marketplace中订阅模型后，必须使用模型软件包信息部署专有模型。

您可以在中找到 JumpStart 可用型号的列表[可用的基础模型](jumpstart-foundation-models-latest.md)。

**重要**  
某些基础模型要求明确接受最终用户许可协议 (EULA)。有关更多信息，请参阅 [使用 SDK 接受最终用户许可协议 SageMaker Python](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula-python-sdk)。

下面几节将介绍如何使用 `JumpStartEstimator` 类微调公开可用的基础模型，使用 `JumpStartModel` 类部署公开可用的基础模型，以及使用 `ModelPackage` 类部署专有基础模型。

**Topics**
+ [

# 使用 `JumpStartEstimator` 类微调公开可用的基础模型
](jumpstart-foundation-models-use-python-sdk-estimator-class.md)
+ [

# 使用 `JumpStartModel` 类部署公开可用的基础模型
](jumpstart-foundation-models-use-python-sdk-model-class.md)
+ [

# 使用 `ModelPackage` 类部署专有基础模型
](jumpstart-foundation-models-use-python-sdk-proprietary.md)

# 使用 `JumpStartEstimator` 类微调公开可用的基础模型
<a name="jumpstart-foundation-models-use-python-sdk-estimator-class"></a>

**注意**  
有关在私有策管中心微调基础模型的说明，请参阅 [微调策管中心模型](jumpstart-curated-hubs-fine-tune.md)。

使用 SDK，您只需几行代码即可对内置算法或预训练模型进行微调。 SageMaker Python

1. 首先，在[内置算法与预训练模型表](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html)中找到所选模型的模型 ID。

1. 使用模型 ID 将您的训练作业定义为 JumpStart估算器。

   ```
   from sagemaker.jumpstart.estimator import JumpStartEstimator
   
   model_id = "huggingface-textgeneration1-gpt-j-6b"
   estimator = JumpStartEstimator(model_id=model_id)
   ```

1. 在模型上运行 `estimator.fit()`，指向用于微调的训练数据。

   ```
   estimator.fit(
       {"train": training_dataset_s3_path, "validation": validation_dataset_s3_path}
   )
   ```

1. 然后，使用 `deploy` 方法自动部署模型进行推理。在此示例中，我们使用 Hugging Face 的 GPT-J 6B 模型。

   ```
   predictor = estimator.deploy()
   ```

1. 然后，您就可以使用 `predict` 方法对已部署的模型进行推理。

   ```
   question = "What is Southern California often abbreviated as?"
   response = predictor.predict(question)
   print(response)
   ```

**注意**  
此示例使用基础模型 GPT-J 6B，该模型适用于各种文本生成使用场景，包括问题解答、命名实体识别、摘要等。有关模型使用场景的更多信息，请参阅 [可用的基础模型](jumpstart-foundation-models-latest.md)。

创建 `JumpStartEstimator` 时，您可以选择指定模型版本或实例类型。有关该`JumpStartEstimator `类及其参数的更多信息，请参见[JumpStartEstimator](https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.jumpstart.estimator.JumpStartEstimator)。

## 检查默认实例类型
<a name="jumpstart-foundation-models-use-python-sdk-estimator-class-instance-types"></a>

在使用 `JumpStartEstimator` 类对预训练模型进行微调时，您可以选择包含特定的模型版本或实例类型。所有 JumpStart 模型都有默认的实例类型。使用以下代码读取默认训练实例类型：

```
from sagemaker import instance_types

instance_type = instance_types.retrieve_default(
    model_id=model_id,
    model_version=model_version,
    scope="training")
print(instance_type)
```

您可以使用`instance_types.retrieve()`方法查看给定 JumpStart 模型的所有支持的实例类型。

## 检查默认超参数
<a name="jumpstart-foundation-models-use-python-sdk-estimator-class-hyperparameters"></a>

要检查用于训练的默认超参数，可以使用 `hyperparameters` 类中的 `retrieve_default()` 方法。

```
from sagemaker import hyperparameters

my_hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)
print(my_hyperparameters)

# Optionally override default hyperparameters for fine-tuning
my_hyperparameters["epoch"] = "3"
my_hyperparameters["per_device_train_batch_size"] = "4"

# Optionally validate hyperparameters for the model
hyperparameters.validate(model_id=model_id, model_version=model_version, hyperparameters=my_hyperparameters)
```

有关可用超参数的更多信息，请参阅 [通常支持的微调超参数](jumpstart-foundation-models-fine-tuning.md#jumpstart-foundation-models-fine-tuning-hyperparameters)。

## 检查默认指标定义
<a name="jumpstart-foundation-models-use-python-sdk-estimator-class-metric-definitions"></a>

您还可以检查默认指标定义：

```
print(metric_definitions.retrieve_default(model_id=model_id, model_version=model_version))
```

# 使用 `JumpStartModel` 类部署公开可用的基础模型
<a name="jumpstart-foundation-models-use-python-sdk-model-class"></a>

使用 SageMaker Python SDK，只需几行代码即可将内置算法或预训练模型部署到 SageMaker AI 终端节点。

1. 首先，在[内置算法与预训练模型表](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html)中找到所选模型的模型 ID。

1. 使用模型 ID 将您的模型定义为 JumpStart 模型。

   ```
   from sagemaker.jumpstart.model import JumpStartModel
   
   model_id = "huggingface-text2text-flan-t5-xl"
   my_model = JumpStartModel(model_id=model_id)
   ```

1. 使用 `deploy` 方法自动部署模型进行推理。在本例中，我们使用了来自 Hugging Face 的 FLAN-T5 XL 模型。

   ```
   predictor = my_model.deploy()
   ```

1. 然后，您就可以使用 `predict` 方法对已部署的模型进行推理。

   ```
   question = "What is Southern California often abbreviated as?"
   response = predictor.predict(question)
   print(response)
   ```

**注意**  
此示例使用的基础模型 FLAN-T5 XL 适用于各种文本生成使用场景，包括问题解答、摘要、聊天机器人创建等。有关模型使用场景的更多信息，请参阅 [可用的基础模型](jumpstart-foundation-models-latest.md)。

有关该`JumpStartModel `类及其参数的更多信息，请参见[JumpStartModel](https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.jumpstart.model.JumpStartModel)。

## 检查默认实例类型
<a name="jumpstart-foundation-models-use-python-sdk-model-class-instance-types"></a>

在使用 `JumpStartModel` 类对预训练模型进行部署时，您可以选择包含特定的模型版本或实例类型。所有 JumpStart 模型都有默认的实例类型。使用以下代码读取默认部署实例类型：

```
from sagemaker import instance_types

instance_type = instance_types.retrieve_default(
    model_id=model_id,
    model_version=model_version,
    scope="inference")
print(instance_type)
```

使用`instance_types.retrieve()`方法查看给定 JumpStart 模型的所有支持的实例类型。

## 使用推理组件将多个模型部署到共享端点
<a name="jumpstart-foundation-models-use-python-sdk-model-class-endpoint-types"></a>

推理组件是一个 SageMaker AI 托管对象，可用于将一个或多个模型部署到终端节点，以提高灵活性和可扩展性。您必须将 JumpStart 模型更改`endpoint_type`为， inference-component-based而不是默认的基于模型的端点。

```
predictor = my_model.deploy(
    endpoint_name = 'jumpstart-model-id-123456789012', 
    endpoint_type = EndpointType.INFERENCE_COMPONENT_BASED
)
```

有关使用推理组件创建端点和部署 SageMaker AI 模型的更多信息，请参阅[多种模式的资源共享利用](realtime-endpoints-deploy-models.md#deployed-shared-utilization)。

## 检查有效的输入和输出推理格式
<a name="jumpstart-foundation-models-use-python-sdk-model-class-input-output"></a>

要检查有效的数据输入和输出格式以进行推理，您可以使用 `Serializers` 和 `Deserializers` 类中的 `retrieve_options()` 方法。

```
print(sagemaker.serializers.retrieve_options(model_id=model_id, model_version=model_version))
print(sagemaker.deserializers.retrieve_options(model_id=model_id, model_version=model_version))
```

## 检查支持的内容和接受类型
<a name="jumpstart-foundation-models-use-python-sdk-model-class-content-types"></a>

同样，您也可以使用 `retrieve_options()` 方法来检查模型支持的内容和接受类型。

```
print(sagemaker.content_types.retrieve_options(model_id=model_id, model_version=model_version))
print(sagemaker.accept_types.retrieve_options(model_id=model_id, model_version=model_version))
```

有关实用程序的更多信息，请参阅[实用工具 APIs](https://sagemaker.readthedocs.io/en/stable/api/utility/index.html)。

# 使用 `ModelPackage` 类部署专有基础模型
<a name="jumpstart-foundation-models-use-python-sdk-proprietary"></a>

在 AWS Marketplace中订阅模型后，必须使用模型软件包信息部署专有模型。有关 SageMaker 人工智能和的更多信息 AWS Marketplace，请参阅[中的买入和出售 Amazon SageMaker AI 算法和模型 AWS Marketplace](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-marketplace.html)。要查找最新专有机型的 AWS Marketplace 链接，请参阅 [Amazon 入门 SageMaker JumpStart](https://aws.amazon.com/sagemaker/jumpstart/getting-started/?sagemaker-jumpstart-cards.sort-by=item.additionalFields.priority&sagemaker-jumpstart-cards.sort-order=asc&awsf.sagemaker-jumpstart-filter-product-type=product-type%23foundation-model&awsf.sagemaker-jumpstart-filter-text=*all&awsf.sagemaker-jumpstart-filter-vision=*all&awsf.sagemaker-jumpstart-filter-tabular=*all&awsf.sagemaker-jumpstart-filter-audio-tasks=*all&awsf.sagemaker-jumpstart-filter-multimodal=*all&awsf.sagemaker-jumpstart-filter-RL=*all&sagemaker-jumpstart-cards.q=proprietary&sagemaker-jumpstart-cards.q_operator=AND)。

在中订阅您选择的模型后 AWS Marketplace，您可以使用与模型提供者关联的 SageMaker Python SDK 和软件开发工具包来部署基础模型。例如， AI21 Labs、Cohere 和 Cohere 分别 LightOn 使用`"ai21[SM]"``cohere-sagemaker`、和`lightonsage`软件包。

例如，要使用 AI21实验室中的 Jurassic-2 Jumbo Instruct 定义 JumpStart 模型，请使用以下代码：

```
import sagemaker
import ai21

role = get_execution_role()
sagemaker_session = sagemaker.Session()
model_package_arn = "arn:aws:sagemaker:us-east-1:865070037744:model-package/j2-jumbo-instruct-v1-1-43-4e47c49e61743066b9d95efed6882f35"

my_model = ModelPackage(
    role=role, model_package_arn=model_package_arn, sagemaker_session=sagemaker_session
)
```

 step-by-step例如，在 SageMaker Studio Classic 中查找并运行与您选择的专有基础型号相关的笔记本电脑。请参阅[在 Amazon SageMaker Studio 经典版中使用基础模型](jumpstart-foundation-models-use-studio.md)了解更多信息。有关 SageMaker Python SDK 的更多信息，请参阅[https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.model.ModelPackage](https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.model.ModelPackage)。

# 在 SageMaker AI 控制台中探索基础模型
<a name="jumpstart-foundation-models-use-console"></a>

您可以直接通过 Amazon A SageMaker I 控制台探索 JumpStart 基础模型。

1. 打开 Amazon A SageMaker I 控制台，网址为[https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)。

1. 在左侧导航面板**JumpStart**上查找，然后选择**基础模型**。

1. 浏览模型或搜索特定模型。如果您需要有关选择模型的指导，请参阅[可用的基础模型](jumpstart-foundation-models-latest.md)。选择**查看模型**可查看所选基础模型的模型详情页面。

1. 如果模型是专有模型，请在模型详细信息页面右上角选择**订阅**以在 AWS Marketplace中订阅该模型。您应该会收到一封确认您订阅了所选模型的电子邮件。有关 SageMaker 人工智能和的更多信息 AWS Marketplace，请参阅[中的买入和出售 Amazon SageMaker AI 算法和模型 AWS Marketplace](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-marketplace.html)。公开可用的基础模型不需要订阅。

1. 要在中查看示例笔记本 GitHub，请选择模型详情页面右上角的**查看代码**。

1. 要直接在 Amazon SageMaker Studio Classic 中查看和运行示例**笔记本，请选择模型详情页面右上角的 “在 Studio 中打开笔记本**”。

# 示范源和许可协议
<a name="jumpstart-foundation-models-choose"></a>

Amaz SageMaker JumpStart on 允许访问来自第三方来源和合作伙伴的数百种公开和专有的基础模型。你可以直接在 SageMaker AI 控制台、Studio 或 Studio Classic 中浏览 JumpStart 基础模型的选择。

## 许可证和模型来源
<a name="jumpstart-foundation-models-choose-source"></a>

Amazon SageMaker JumpStart 提供对公开和专有基础模型的访问权限。基础模型由第三方开源和专有提供商载入和维护。因此，它们在根据模型来源指定的不同许可证下发布。请确保检查您使用的任何基础模型的许可证。在下载或使用内容之前，您有责任查看和遵守任何适用的许可证条款，并确保您的使用案例可以接受这些条款。常见基础模型许可证的一些示例包括：
+ Alexa Teacher Model
+ Apache 2.0
+ BigScience 负责任的人工智能许可证 v1.0
+ CreativeML Open RAIL\$1\$1-M 许可证

同样，对于任何专有基础模型，请确保查看并遵守模型提供商的任何使用条款和使用指南。如果您对特定专有模型的许可证信息有疑问，请直接联系模型提供商。在 AWS Marketplace中，您可以在每个模型的**支持**选项卡中找到模型提供商的联系信息。

## 最终用户许可协议
<a name="jumpstart-foundation-models-choose-eula"></a>

某些 JumpStart 基础模型要求在使用前明确接受最终用户许可协议 (EULA)。

### 亚马逊 SageMaker Studio 接受最终用户许可协议
<a name="jumpstart-foundation-models-choose-eula-studio"></a>

在 Studio 中微调、部署或评估 JumpStart 基础模型之前，系统可能会提示您接受最终用户许可协议。要开始使用 Studio 中的 JumpStart 基础模型，请参阅[在 Studio 中使用基础模型](jumpstart-foundation-models-use-studio-updated.md)。

**重要**  
截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。以下部分专门介绍如何使用更新后的 Studio 体验。有关使用 Studio Classic 应用程序的信息，请参阅 [亚马逊 SageMaker Studio 经典版](studio.md)。

某些 JumpStart 基础模型要求在部署之前接受最终用户许可协议。如果这适用于您选择使用的基础模型，Studio 会提示您一个包含 EULA 内容的窗口。在下载或使用模型之前，您有责任查看和遵守任何适用的许可证条款，并确保您的使用场景可以接受这些条款。

#### 亚马逊 SageMaker Studio 经典版接受最终用户许可协议
<a name="jumpstart-foundation-models-choose-eula-studio-classic"></a>

在 Studio Classic 中部署 JumpStart 基础模型或打开基础型号笔记本电脑之前， JumpStart 系统可能会提示您接受最终用户许可协议。要开始使用 Studio Classic 中的 JumpStart 基础模型，请参阅[在 Amazon SageMaker Studio 经典版中使用基础模型](jumpstart-foundation-models-use-studio.md)。

**重要**  
截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。以下部分专门介绍如何使用 Studio Classic 应用程序。有关使用更新的 Studio 体验的信息，请参阅 [亚马逊 SageMaker Studio](studio-updated.md)。  
Studio Classic 仍针对现有工作负载进行维护，但不再可供入门使用。您只能停止或删除现有的 Studio Classic 应用程序，不能创建新的应用程序。我们建议您将[工作负载迁移到全新 Studio 体验](studio-updated-migrate.md)。

某些 JumpStart 基础模型要求在部署之前接受最终用户许可协议。如果您选择使用的基础模型也有此要求，则在您选择**部署**或**打开笔记本**之后，Studio Classic 会显示一个标题为**查看以下最终用户许可协议 (EULA) 和可接受使用政策 (AUP)** 的窗口。在下载或使用模型之前，您有责任查看和遵守任何适用的许可证条款，并确保您的使用场景可以接受这些条款。

### 使用 SDK 接受最终用户许可协议 SageMaker Python
<a name="jumpstart-foundation-models-choose-eula-python-sdk"></a>

以下各节介绍如何在使用 SDK 部署或微调 JumpStart 模型时明确声明接受 EULA。 SageMaker Python有关使用 SageMaker Python SDK 开始使用 JumpStart 基础模型的更多信息，请参阅[在 SageMaker Python SDK 中使用基础模型](jumpstart-foundation-models-use-python-sdk.md)。

在开始之前，请确保完成了以下操作：
+ 升级到您使用的模型的最新版本。
+ 安装最新版本的 SageMaker Python SDK。

**重要**  
要使用以下工作流程，必须安装版本为 [2.198.0](https://github.com/aws/sagemaker-python-sdk/releases/tag/v2.198.0) 或更高版本的 SDK。 SageMaker Python

#### 部署模型时接受最终用户许可协议 JumpStart
<a name="jumpstart-foundation-models-choose-eula-python-sdk-deploy"></a>

对于需要接受最终用户许可协议的型号，您必须在部署 JumpStart模型时明确声明接受最终用户许可协议。

```
from sagemaker.jumpstart.model import JumpStartModel
model_id = "meta-textgeneration-llama-2-13b"
my_model = JumpStartModel(model_id=model_id)

# Declare EULA acceptance when deploying your JumpStart model
predictor = my_model.deploy(accept_eula=True)
```

默认情况下 `accept_eula` 的值为 `None`，并且必须明确重新定义为 `True` 以接受最终用户许可协议。有关更多信息，请参阅 [JumpStartModel](https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.jumpstart.model.JumpStartModel)。

#### 微调模型时接受 EULA JumpStart
<a name="jumpstart-foundation-models-choose-eula-python-sdk-fine-tune"></a>

对于需要接受最终用户许可协议的微调模型，在为估算器运行该`fit()`方法时，必须明确声明接受 EULA。 JumpStart 对预训练模型进行微调后，原始模型的权重会发生变化。因此，以后部署微调的模型时，无需接受 EULA。

**注意**  
以下示例设置 `accept_eula=False`。要接受 EULA，您应该手动将该值更改为 `True`。

```
from sagemaker.jumpstart.estimator import JumpStartEstimator
model_id = "meta-textgeneration-llama-2-13b"

# Declare EULA acceptance when defining your JumpStart estimator
estimator = JumpStartEstimator(model_id=model_id)
estimator.fit(accept_eula=False,
{"train": training_dataset_s3_path, "validation": validation_dataset_s3_path}
)
```

默认情况下 `accept_eula` 的值为 `None`，并且必须明确在 `fit()` 方法中重新定义为 `"true"` 以接受最终用户许可协议。有关更多信息，请参阅 [JumpStartEstimator](https://sagemaker.readthedocs.io/en/stable/api/training/estimators.html#sagemaker.jumpstart.estimator.JumpStartEstimator)。

#### EULA 接受 SageMaker Python SDK 版本低于 2.198.0
<a name="jumpstart-foundation-models-choose-eula-python-sdk-previous-version"></a>

**重要**  
使用低于 [2.198.0](https://github.com/aws/sagemaker-python-sdk/releases/tag/v2.198.0) 的 SageMaker Python SDK 版本时，必须使用 SageMaker `Predictor`类来接受模型最终用户许可协议。

使用 SageMaker Python SDK 以编程方式部署 JumpStart 基础模型后，您可以使用类对已部署的终端节点进行推理。 SageMaker `[Predictor](https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html)`对于需要接受最终用户许可协议的模型，您必须在调用 `Predictor` 类时明确声明接受 EULA：

```
predictor.predict(payload, custom_attributes="accept_eula=true")
```

默认情况下 `accept_eula` 的值为 `false`，并且必须明确重新定义为 `true` 以接受最终用户许可协议。如果在 `accept_eula` 设置为 `false` 时尝试运行推理，则预测器会返回错误信息。有关使用 SageMaker Python SDK 开始使用 JumpStart 基础模型的更多信息，请参阅[在 SageMaker Python SDK 中使用基础模型](jumpstart-foundation-models-use-python-sdk.md)。

**重要**  
`custom_attributes` 参数接受 `"key1=value1;key2=value2"` 格式的键值对。如果您多次使用同一个键，则推理服务器将使用与该键关联的最后一个值。例如，如果您将 `"accept_eula=false;accept_eula=true"` 传递给 `custom_attributes` 参数，则推理服务器会将值 `true` 与 `accept_eula` 键相关联。

# 基础模型自定义
<a name="jumpstart-foundation-models-customize"></a>

基础模型是非常强大的模型，能够处理各种任务。为了有效地解决大多数任务，这些模型需要进行某种形式的自定义。

根据特定使用案例，推荐用于自定义基础模型的第一种方法是通过提示工程。为基础模型提供精心设计、具有丰富上下文的提示可以帮助实现预期的结果，而无需微调或对模型权重进行任何更改。有关更多信息，请参阅 [适用于基础模型的提示工程](jumpstart-foundation-models-customize-prompt-engineering.md)。

如果仅靠提示工程不足以根据特定任务自定义基础模型，则可以根据其他特定于领域的数据对基础模型进行微调。有关更多信息，请参阅 [用于微调的基础模型和超参数](jumpstart-foundation-models-fine-tuning.md)。微调过程涉及到更改模型权重。

如果您想使用知识库中的信息自定义模型而不进行任何重新训练，请参阅[检索增强生成](jumpstart-foundation-models-customize-rag.md)。

# 适用于基础模型的提示工程
<a name="jumpstart-foundation-models-customize-prompt-engineering"></a>

提示工程是针对语言模型，设计和完善提示或输入刺激以生成特定类型输出的过程。提示工程涉及到选择适当的关键字、提供上下文，并以促进模型生成所需响应的方式塑造输入，这是一项主动塑造基础模型行为和输出的重要技术。

有效的提示工程对于指导模型行为和实现所需的响应至关重要。通过提示工程，您可以控制模型的语气、风格和领域专业知识，而无需进行诸如微调之类的更多自定义措施。我们建议您在考虑根据其他数据对模型进行微调之前，专门用一些时间来设计提示工程。目标是为模型提供足够的背景信息和指导，使其能够对没见过或有限数据的场景进行概括并有好的表现。

## 零样本学习
<a name="jumpstart-foundation-models-customize-prompt-engineering-zero-shot"></a>

零样本学习涉及训练模型以对没见过的类或任务进行概括和预测。要在零样本学习环境中执行提示工程，我们建议您构造提示，明确提供有关目标任务和所需输出格式的信息。例如，如果您要使用基础模型，对模型在训练期间未看到的一组类进行零样本文本分类，则良好设计的提示可能是：`"Classify the following text as either sports, politics, or entertainment: [input text]."`。通过明确指定目标类和预期的输出格式，您可以指导模型即使对没见过的类也能做出准确的预测。

## 少样本学习
<a name="jumpstart-foundation-models-customize-prompt-engineering-few-shot"></a>

少样本学习涉及使用有限的数据量训练模型，以用于新课程或任务。在少样本学习环境中，提示工程侧重于设计能够高效利用有限的可用训练数据的提示。例如，如果您使用基础模型执行图像分类任务，并且只有几个新图像类的样本，则可以设计一个提示，在其中包含可用的已标注样本，并带有用于目标类的占位符。例如，提示可能是：`"[image 1], [image 2], and [image 3] are examples of [target class]. Classify the following image as [target class]"`。通过纳入有限的已标注样本并明确指定目标类，即使训练数据极少，您也可以指导模型进行概括并做出准确的预测。

## 支持的推理参数
<a name="jumpstart-foundation-models-customize-prompt-engineering-inference-params"></a>

更改推理参数也可能会影响对提示的响应。您可以尽量为提示添加具体内容和上下文，也可以尝试使用支持的推理参数。以下是一些常用的推理参数的示例：


| 推理参数 | 说明 | 
| --- | --- | 
| `max_new_tokens` | 基础模型响应的最大输出长度。有效值：整数，范围：正整数。 | 
| `temperature` | 控制输出的随机性。较高的温度会导致输出序列中包含低概率词，而较低的温度会生成带有高概率词的输出序列。如果是 `temperature=0`，则响应只由概率最高的单词组成（贪婪解码）。有效值：浮点型，范围：正浮点数。 | 
| `top_p` | 在文本生成的每一步中在文本生成的每个步骤中，模型都会以 `top_p` 的累积概率从尽可能小的词集中采样。有效值：浮点型，范围：0.0，1.0。 | 
| `return_full_text` | 如果 `True`，则输入文本是生成的输出文本的一部分。有效值：布尔值，默认值：False。 | 

有关基础模型推理的更多信息，请参见 [使用 `JumpStartModel` 类部署公开可用的基础模型](jumpstart-foundation-models-use-python-sdk-model-class.md)。

如果提示工程不足以根据特定的业务需求、特定领域的语言、目标任务或其他要求来调整基础模型，您可以考虑根据其他数据微调模型，或者使用检索增强生成 (RAG)，通过来自存档知识来源的增强上下文来增强模型架构。有关更多信息，请参阅 [用于微调的基础模型和超参数](jumpstart-foundation-models-fine-tuning.md)或 [检索增强生成](jumpstart-foundation-models-customize-rag.md)。

# 用于微调的基础模型和超参数
<a name="jumpstart-foundation-models-fine-tuning"></a>

基础模型的计算成本很高，并且是在大型的、未标注的语料库上训练的。微调预训练的基础模型是一种经济实惠的方式，可以利用其广泛的功能，同时根据自己的小型语料库来自定义模型。微调是一种自定义方法，它涉及进一步的训练，并且会改变模型的权重。

如果您有以下要求，微调可能会很有用：
+ 根据特定业务需求自定义模型
+ 让模型可以成功处理特定于领域的语言，例如行业术语、技术术语或其他专业词汇
+ 针对特定任务增强性能
+ 在应用中提供准确、相对的和感知上下文的响应
+ 更真实、毒性更小、更符合具体要求的响应

根据使用案例和所选的基础模型，您可以采用两种主要方法进行微调。

1. 如果您有兴趣根据特定于领域数据微调模型，请参阅[利用领域适应性微调大型语言模型（LLM）](jumpstart-foundation-models-fine-tuning-domain-adaptation.md)。

1. 如果您对使用提示和响应样本进行基于指令的微调感兴趣，请参阅[使用提示指令微调大型语言模型（LLM）](jumpstart-foundation-models-fine-tuning-instruction-based.md)。

## 可进行微调的基础模型
<a name="jumpstart-foundation-models-fine-tuning-models"></a>

您可以微调以下任何 JumpStart 基础模型：
+ Bloom 3B
+ Bloom 7B1
+ BloomZ 3B FP16
+ BloomZ 7B1 FP16
+ Code Llama 13B
+ Code Llama 13B Python
+ Code Llama 34B
+ Code Llama 34B Python
+ Code Llama 70B
+ Code Llama 70B Python
+ Code Llama 7B
+ Code Llama 7B Python
+ CyberAgentLM2-7B-Chat (-7B-Chat) CALM2
+ Falcon 40B BF16
+ Falcon 40B Instruct BF16
+ Falcon 7B BF16
+ Falcon 7B Instruct BF16
+ Flan-T5 Base
+ Flan-T5 Large
+ Flan-T5 Small
+ Flan-T5 XL
+ Flan-T5 XXL
+ Gemma 2B
+ Gemma 2B Instruct
+ Gemma 7B
+ Gemma 7B Instruct
+ GPT-2 XL
+ GPT-J 6B
+ GPT-Neo 1.3B
+ GPT-Neo 125M
+ GPT-NEO 2.7B
+ LightGPT Instruct 6B
+ Llama 2 13B
+ Llama 2 13B Chat
+ Llama 2 13B Neuron
+ Llama 2 70B
+ Llama 2 70B Chat
+ Llama 2 7B
+ Llama 2 7B Chat
+ Llama 2 7B Neuron
+ Mistral 7B
+ Mixtral 8x7B
+ Mixtral 8x7B Instruct
+ RedPajama Incite Base 3B V1
+ RedPajama Incite Base 7B V1
+ RedPajama INCITE Chat 3B V1
+ RedPajama INCITE Chat 7B V1
+ RedPajama INCITE Instruct 3B V1
+ RedPajama INCITE Instruct 7B V1
+ Stable Diffusion 2.1

## 通常支持的微调超参数
<a name="jumpstart-foundation-models-fine-tuning-hyperparameters"></a>

微调时，不同的基础模型支持不同的超参数。以下是常用的超参数，可在训练过程中进一步自定义模型：


| 推理参数 | 说明 | 
| --- | --- | 
| `epoch` | 模型在训练过程中通过微调数据集的次数。必须是大于 1 的整数。 | 
| `learning_rate` |  完成每批微调训练样本后，更新模型权重的速度。必须是大于 0 的正浮点数。 | 
| `instruction_tuned` |  是否对模型进行指令训练。必须为 `'True'` 或 `'False'`。 | 
| `per_device_train_batch_size` |  用于训练的每个 GPU 内核或 CPU 的批量大小。其值必须为正整数。 | 
| `per_device_eval_batch_size` |  用于评估的每个 GPU 内核或 CPU 的批量大小。其值必须为正整数。 | 
| `max_train_samples` |  为了调试或加快训练速度，请将训练样本的数量截断为该值。值 -1 表示模型使用了所有训练样本。必须是正整数或 -1。 | 
| `max_val_samples` |  为了调试或加快训练速度，请将验证样本的数量截断为该值。值 -1 表示模型使用了所有验证样本。必须是正整数或 -1。 | 
| `max_input_length` |  令牌化后输入序列的最大总长度。长度超过此值的序列将被截断。如果为 -1，`max_input_length` 将被设置为 1024 和分词器定义的 `model_max_length` 的最小值。如果设置为正值，`max_input_length` 将被设置为所提供值和分词器定义的 `model_max_length` 的最小值。必须是正整数或 -1。 | 
| `validation_split_ratio` |  如果没有验证通道，则训练 - 验证的比例将从训练数据中拆分。必须介于 0 和 1 之间。 | 
| `train_data_split_seed` |  如果不存在验证数据，则将输入的训练数据随机拆分为模型使用的训练数据和验证数据。必须是整数。 | 
| `preprocessing_num_workers` |  用于预处理的进程数。如果 `None`，则使用主进程进行预处理。 | 
| `lora_r` |  低秩适应 (LoRA) r 值，作为权重更新的缩放因子。其值必须为正整数。 | 
| `lora_alpha` |  低秩适应 (LoRA) 阿尔法值，作为权重更新的缩放因子。一般是 `lora_r` 的 2 到 4 倍。其值必须为正整数。 | 
| `lora_dropout` |  低秩适应 (LoRA) 层的释放参数必须是介于 0 和 1 之间的正浮点数。 | 
| `int8_quantization` |  如果 `True`，则模型将以 8 位精度加载，以进行训练。 | 
| `enable_fsdp` |  如果 `True`，则训练使用完全分片数据并行。 | 

在 Studio 中微调模型时，您可以指定超参数值。有关更多信息，请参阅 [在 Studio 中微调模型](jumpstart-foundation-models-use-studio-updated-fine-tune.md)。

使用 SDK 微调模型时，您也可以覆盖默认的超参数值。 SageMaker Python有关更多信息，请参阅 [使用 `JumpStartEstimator` 类微调公开可用的基础模型](jumpstart-foundation-models-use-python-sdk-estimator-class.md)。

# 利用领域适应性微调大型语言模型（LLM）
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation"></a>

通过领域适应微调，您可以利用预先训练的基础模型，并使用有限的特定于领域的数据，根据特定任务来调整模型。如果通过提示工程无法提供足够的自定义，则可以使用领域适应微调，让您的模型处理特定于领域的语言，例如行业术语、技术术语或其他专业数据。这个微调过程修改模型的权重。

要在特定领域的数据集上微调模型：

1. 准备训练数据。有关说明，请参阅[准备和上传训练数据以进行领域适应微调](#jumpstart-foundation-models-fine-tuning-domain-adaptation-prepare-data)。

1. 创建您的微调训练作业。有关说明，请参阅[创建基于指令的微调的训练作业](#jumpstart-foundation-models-fine-tuning-domain-adaptation-train)。

您可以在中找到 end-to-end示例[示例笔记本](#jumpstart-foundation-models-fine-tuning-domain-adaptation-examples)。

领域适应微调适用于以下基础模型：

**注意**  
一些 JumpStart 基础模型，例如 Llama 2 7B，要求在微调和执行推理之前接受最终用户许可协议。有关更多信息，请参阅 [最终用户许可协议](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula)。
+ Bloom 3B
+ Bloom 7B1
+ BloomZ 3B FP16
+ BloomZ 7B1 FP16
+ GPT-2 XL
+ GPT-J 6B
+ GPT-Neo 1.3B
+ GPT-Neo 125M
+ GPT-NEO 2.7B
+ Llama 2 13B
+ Llama 2 13B Chat
+ Llama 2 13B Neuron
+ Llama 2 70B
+ Llama 2 70B Chat
+ Llama 2 7B
+ Llama 2 7B Chat
+ Llama 2 7B Neuron

## 准备和上传训练数据以进行领域适应微调
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation-prepare-data"></a>

域适应微调的训练数据可以采用 CSV、JSON 或 TXT 文件格式提供。所有训练数据必须放在单个文件夹内的单个文件中。

训练数据取自 CSV 或 JSON 训练数据文件的**文本**列。如果没有标记为**文本**的列，则训练数据将从 CSV 或 JSON 训练数据文件的第一列中获取。

以下是用于微调的 TXT 文件正文示例：

```
This report includes estimates, projections, statements relating to our
business plans, objectives, and expected operating results that are “forward-
looking statements” within the meaning of the Private Securities Litigation
Reform Act of 1995, Section 27A of the Securities Act of 1933, and Section 21E
of ....
```

### 拆分数据用于训练和测试
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation-split-data"></a>

您可以选择提供另一个包含验证数据的文件夹。此文件夹还应包含一个 CSV、JSON 或 TXT 文件。如果未提供验证数据集，则会留出一定量的训练数据用于验证。在选择用于微调模型的超参数时，可以调整用于验证的训练数据比例。

### 将微调数据上传到 Amazon S3
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation-upload-data"></a>

将准备好的数据上传到亚马逊简单存储服务 (Amazon S3)，以便在微调 JumpStart 基础模型时使用。您可以使用以下命令上传数据：

```
from sagemaker.s3 import S3Uploader
import sagemaker
import random

output_bucket = sagemaker.Session().default_bucket()
local_data_file = "train.txt"
train_data_location = f"s3://{output_bucket}/training_folder"
S3Uploader.upload(local_data_file, train_data_location)
S3Uploader.upload("template.json", train_data_location)
print(f"Training data: {train_data_location}")
```

## 创建基于指令的微调的训练作业
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation-train"></a>

将数据上传到 Amazon S3 后，您可以微调和部署 JumpStart 基础模型。要在 Studio 中微调您的模型，请参阅 [在 Studio 中微调模型](jumpstart-foundation-models-use-studio-updated-fine-tune.md)。要使用 SageMaker Python SDK 微调模型，请参阅[使用 `JumpStartEstimator` 类微调公开可用的基础模型](jumpstart-foundation-models-use-python-sdk-estimator-class.md)。

## 示例笔记本
<a name="jumpstart-foundation-models-fine-tuning-domain-adaptation-examples"></a>

有关域适应微调的更多信息，请参阅以下示例笔记本：
+ [SageMaker JumpStart 基础模型——微调特定领域数据集上的文本生成 GPT-J 6B 模型](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/domain-adaption-finetuning-gpt-j-6b.html)
+ [微调 LLa MA 2 机型 JumpStart](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/llama-2-finetuning.html)

# 使用提示指令微调大型语言模型（LLM）
<a name="jumpstart-foundation-models-fine-tuning-instruction-based"></a>

基于指令的微调使用已标注的样本，提高预训练基础模型在特定任务上的性能。已标注样本采用提示和响应对的格式，可解析为指令。这个微调过程修改模型的权重。有关基于指令的微调的更多信息，请参阅 [FLAN 简介：具有指令微调的更具通用性的语言模型](https://ai.googleblog.com/2021/10/introducing-flan-more-generalizable.html)和[缩放指令微调语言模型](https://arxiv.org/abs/2210.11416)。

经过微调的 LAnguage 网络 (FLAN) 模型使用指令调整来使模型更适合解决一般的下游 NLP 任务。Amazon 在 FLAN 模型系列中 SageMaker JumpStart 提供了许多基础模型。例如，FLAN-T5 模型针对广泛的任务进行了指令微调，以提高各种常见使用案例的零样本性能。通过额外的数据和微调，基于指令的模型可以针对在预训练期间未考虑过的更具体的任务进一步进行调整。

要在特定任务中使用提示 - 响应对任务指令对 LLM 进行微调：

1. 在 JSON 文件中编写指令。有关提示 - 响应对文件所需格式和数据文件夹结构的更多信息，请参阅 [准备并上传训练数据，以便进行基于指令的微调](#jumpstart-foundation-models-fine-tuning-instruction-based-prepare-data)。

1. 创建您的微调训练作业。有关说明，请参阅[创建基于指令的微调的训练作业](#jumpstart-foundation-models-fine-tuning-instruction-based-train)。

您可以在中找到 end-to-end示例[示例笔记本](#jumpstart-foundation-models-fine-tuning-instruction-based-examples)。

只有一部分 JumpStart 基础模型与基于指令的微调兼容。基于指令的微调适用于以下基础模型：

**注意**  
一些 JumpStart 基础模型，例如 Llama 2 7B，要求在微调和执行推理之前接受最终用户许可协议。有关更多信息，请参阅 [最终用户许可协议](jumpstart-foundation-models-choose.md#jumpstart-foundation-models-choose-eula)。
+ Flan-T5 Base
+ Flan-T5 Large
+ Flan-T5 Small
+ Flan-T5 XL
+ Flan-T5 XXL
+ Llama 2 13B
+ Llama 2 13B Chat
+ Llama 2 13B Neuron
+ Llama 2 70B
+ Llama 2 70B Chat
+ Llama 2 7B
+ Llama 2 7B Chat
+ Llama 2 7B Neuron
+ Mistral 7B
+ RedPajama Incite Base 3B V1
+ RedPajama Incite Base 7B V1
+ RedPajama INCITE Chat 3B V1
+ RedPajama INCITE Chat 7B V1
+ RedPajama INCITE Instruct 3B V1
+ RedPajama INCITE Instruct 7B V1

## 准备并上传训练数据，以便进行基于指令的微调
<a name="jumpstart-foundation-models-fine-tuning-instruction-based-prepare-data"></a>

基于指令的微调所需的训练数据必须以 JSON 行文本文件格式提供，其中每一行都是一个字典。所有训练数据必须放在一个文件夹中。此文件夹可包含多个 .jsonl 文件。

训练文件夹还可以包含一个模板 JSON 文件 (`template.json`)，用于描述数据的输入和输出格式。如果未提供模板文件，则使用以下模板文件：

```
{
  "prompt": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{context}",
  "completion": "{response}"
}
```

根据 `template.json` 文件，训练数据的每个 .jsonl 条目必须包括 `{instruction}`、`{context}` 和 `{response}` 字段。

如果您提供了自定义模板 JSON 文件，请使用 `"prompt"` 和 `"completion"` 键定义自己的必填字段。根据以下自定义模板 JSON 文件，训练数据的每个 .jsonl 条目必须包括 `{question}`、`{context}` 和 `{answer}` 字段：

```
{
  "prompt": "question: {question} context: {context}",
  "completion": "{answer}"
}
```

### 拆分数据用于训练和测试
<a name="jumpstart-foundation-models-fine-tuning-instruction-based-split-data"></a>

您可以选择提供另一个包含验证数据的文件夹。此文件夹还应包含一个或多个 .jsonl 文件。如果未提供验证数据集，则会留出一定量的训练数据用于验证。在选择用于微调模型的超参数时，可以调整用于验证的训练数据比例。

### 将微调数据上传到 Amazon S3
<a name="jumpstart-foundation-models-fine-tuning-instruction-based-upload-data"></a>

将准备好的数据上传到亚马逊简单存储服务 (Amazon S3)，以便在微调 JumpStart 基础模型时使用。您可以使用以下命令上传数据：

```
from sagemaker.s3 import S3Uploader
import sagemaker
import random

output_bucket = sagemaker.Session().default_bucket()
local_data_file = "train.jsonl"
train_data_location = f"s3://{output_bucket}/dolly_dataset"
S3Uploader.upload(local_data_file, train_data_location)
S3Uploader.upload("template.json", train_data_location)
print(f"Training data: {train_data_location}")
```

## 创建基于指令的微调的训练作业
<a name="jumpstart-foundation-models-fine-tuning-instruction-based-train"></a>

将数据上传到 Amazon S3 后，您可以微调和部署 JumpStart 基础模型。要在 Studio 中微调您的模型，请参阅 [在 Studio 中微调模型](jumpstart-foundation-models-use-studio-updated-fine-tune.md)。要使用 SageMaker Python SDK 微调模型，请参阅[使用 `JumpStartEstimator` 类微调公开可用的基础模型](jumpstart-foundation-models-use-python-sdk-estimator-class.md)。

## 示例笔记本
<a name="jumpstart-foundation-models-fine-tuning-instruction-based-examples"></a>

有关基于指令的微调的更多信息，请参阅以下示例笔记本：
+ [微调 LLa MA 2 机型 JumpStart](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/llama-2-finetuning.html)
+ [简介 SageMaker JumpStart -使用 Mistral 模型生成文本](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/mistral-7b-instruction-domain-adaptation-finetuning.html)
+ [简介 SageMaker JumpStart -使用 Falcon 模型生成文本](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/falcon-7b-instruction-domain-adaptation-finetuning.html)
+ [SageMaker JumpStart 基础模型- HuggingFace Text2Text 指令微调](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/instruction-fine-tuning-flan-t5.html)

# 检索增强生成
<a name="jumpstart-foundation-models-customize-rag"></a>

基础模型通常是离线训练的，这使得模型不了解在模型训练后创建的任何数据。此外，基础模型在非常通用的领域语料库上训练，这使得它们在特定于领域的任务中的效率较低。您可以使用检索增强生成 (RAG) 在基础模型的外部检索数据，并通过在上下文中添加检索到的相关数据来增强提示。有关 RAG 模型架构的更多信息，请参阅[知识密集型 NLP 任务的检索增强生成](https://arxiv.org/abs/2005.11401)。

使用 RAG，用于增强提示的外部数据可以来自多个数据源，例如文档存储库、数据库或。 APIs第一步是将您的文档和任何用户查询转换为兼容的格式，以执行相关性搜索。为了使格式兼容，需要使用嵌入式语言模型，将文档集合或知识库以及用户提交的查询转换为数字表示形式。*嵌入*是在向量空间中对文本进行数字表示的过程。RAG 模型架构比较知识库向量中用户查询的嵌入情况。然后，将知识库中类似文档的相关上下文附加到原始用户提示中。接下来，此增强提示将发送到基础模型。您可以异步更新知识库及其相关嵌入。

 ![\[A model architecture diagram of Retrieval Augmented Generation (RAG).\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/jumpstart/jumpstart-fm-rag.jpg) 

检索到的文件应足够大，以便包含有用的上下文，帮助增强提示信息，但又应足够小，以适应提示信息的最大序列长度。您可以使用特定于任务的 JumpStart 模型（例如中的通用文本嵌入 (GTE) 模型）来为提示和知识库文档提供嵌入内容。Hugging Face在比较提示和文档嵌入找到最相关的文档后，利用补充上下文构建新的提示。然后，将增强后的提示传递给您选择的文本生成模型。

## 示例笔记本
<a name="jumpstart-foundation-models-customize-rag-examples"></a>

有关 RAG 基础模型解决方案的更多信息，请参阅以下示例笔记本：
+ [检索增强生成：使用 LangChain和 Cohere 的生成和嵌入模型进行问答 SageMaker JumpStart](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_Cohere+langchain_jumpstart.html)
+ [检索增强生成：使用- LLama 2、Pinecone 和自定义数据集回答问题](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_pinecone_llama-2_jumpstart.html)
+ [检索增强生成：基于开源库的自定义数据集问答 LangChain ](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_langchain_jumpstart.html)
+ [检索增强生成：基于自定义数据集的问题回答](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_jumpstart_knn.html)
+ [检索增强生成：使用 Llama-2 和文本嵌入模型进行问题解答](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_text_embedding_llama-2_jumpstart.html)
+ [Amazon SageMaker JumpStart -文本嵌入和句子相似度](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/text-embedding-sentence-similarity.html)

您可以克隆 [Amazon A SageMaker I 示例存储库](https://github.com/aws/amazon-sagemaker-examples/tree/main/introduction_to_amazon_algorithms/jumpstart-foundation-models)，以便在 Studio 中您选择的 Jupyter 环境中运行可用的 JumpStart 基础模型示例。有关可用于在 SageMaker AI 中创建和访问 Jupyter 的应用程序的更多信息，请参阅。[Amazon SageMaker Studio 支持的应用程序](studio-updated-apps.md)

# 评估 Studio 中的文本生成基础模型
<a name="jumpstart-foundation-models-evaluate"></a>

**注意**  
基础模型评估 (FMEval) 是 Amazon Clarif SageMaker y 的预览版，可能会发生变化。

**重要**  
要使用 Clari SageMaker fy 基础模型评估，您必须升级到全新的 Studio 体验。截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。基础评估功能只能在更新的体验中使用。有关如何更新 Studio 的信息，请参阅 [从亚马逊 SageMaker Studio 经典版迁移](studio-updated-migrate.md)。有关使用 Studio Classic 应用程序的信息，请参阅 [亚马逊 SageMaker Studio 经典版](studio.md)。

亚马逊 SageMaker JumpStart 已与 Studio 中的 C SageMaker larify 基础模型评估 (FMEval) 集成。如果 JumpStart 模型具有内置评估功能，则可以在 JumpStart Studio 用户界面中模型详情页面的右上角选择**评估**。有关在 JumpStart Studio 用户界面中导航的更多信息，请参阅 [JumpStart 在工作室中打开](studio-jumpstart.md#jumpstart-open-studio)

使用 Amazon SageMaker JumpStart 来评估基于文本的基础模型。 FMEval您可以使用这些模型评估来比较一个模型、两个模型之间或同一模型的不同版本之间的模型质量和责任指标，以帮助您量化模型风险。 FMEval 可以评估执行以下任务的基于文本的模型：
+  **开放式生成**：对没有预先定义结构的文本做出自然的人类反应。
+  **文本摘要**：生成简明扼要的摘要，同时保留长文本中的含义和关键信息。
+  **问题解答**：用自然语言回答问题。
+  **分类**：根据文本内容，将文本段落分为 `negative` 类和 `positive` 类。

您可以使用 FMEval 根据特定基准自动评估模型响应。您还可以使用自己的提示数据集，根据自己的标准评估模型响应。 FMEval 提供了一个用户界面 (UI)，可指导您完成评估任务的设置和配置。您也可以在自己的代码中使用该 FMEval 库。

每次评估都需要两个实例的配额：
+ 托管实例：托管和部署 LLM 的实例。
+ 评估实例：用于在主机实例上提示和执行 LLM 评估的实例。

如果您的 LLM 已部署，请提供终端节点， SageMaker AI 将使用您的**托管实例来托管**和部署 LLM。

如果您正在评估尚未部署到您的账户的 JumpStart 模型，请在您的账户中为您 FMEval 创建一个临时**托管实例**，并且仅在评估期间保持部署状态。 FMEval 使用为所选 LLM JumpStart 推荐的默认实例作为您的托管实例。您必须拥有足够的配额才能使用此推荐实例。

每次评估都会使用评估实例来提示 LLM 的响应并为其打分。您还必须拥有足够的配额和内存来运行评估算法。评估实例的配额和内存需求通常小于托管实例的需求。我们建议选择 `ml.m5.2xlarge` 实例。有关配额和内存的更多信息，请参阅 [解决在 Amazon A SageMaker I 中创建模型评估任务时出现的错误](clarify-foundation-model-evaluate-troubleshooting.md)。

自动评估可用于对以下维度 LLMs 进行评分：
+ 准确性：适用于文本摘要、问答和文本分类
+ 语义稳健性：适用于开放式生成、文本摘要和文本分类任务
+ 事实知识：适用于开放式一代
+ 提示定式：适用于开放式一代 
+  毒性：适用于开放式生成、文本摘要和问答

您还可以使用人工评估来手动评估模型响应。 FMEval 用户界面将引导您完成选择一个或多个模型、配置资源、为员工编写说明和联系员工的工作流程。人体评估完成后，结果将显示在中 FMEval。

您可以通过 Studio 的 JumpStart 登录页面访问模型评估，方法是选择要评估的模型，然后选择**评估**。请注意，并非所有 JumpStart 模型都具有可用的评估功能。有关如何配置、配置和运行的更多信息 FMEval，请参阅[什么是基础模型评估？](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-foundation-model-evaluate.html)

# 示例笔记本
<a name="jumpstart-foundation-models-example-notebooks"></a>

有关如何在 SageMaker Python SDK 中使用公开 JumpStart 基础模型的 step-by-step示例，请参阅以下关于文本生成、图像生成和模型自定义的笔记本。

**注意**  
专有和公开 JumpStart 的基础模型具有不同的 SageMaker AI Python SDK 部署工作流程。通过 Amazon SageMaker Studio Classic 或 A SageMaker I 控制台探索专有的基础模型示例笔记本电脑。有关更多信息，请参阅 [JumpStart 基础模型用法](jumpstart-foundation-models-use.md)。

您可以克隆 [Amazon A SageMaker I 示例存储库](https://github.com/aws/amazon-sagemaker-examples/tree/main/introduction_to_amazon_algorithms/jumpstart-foundation-models)，以便在 Studio 中您选择的 Jupyter 环境中运行可用的 JumpStart 基础模型示例。有关可用于在 SageMaker AI 中创建和访问 Jupyter 的应用程序的更多信息，请参阅。[Amazon SageMaker Studio 支持的应用程序](studio-updated-apps.md)

## 时间序列预测
<a name="jumpstart-foundation-models-example-notebooks-time-series"></a>

您可以使用 Chronos 模型来预测时间序列数据。它们基于语言模型架构。使用 [Chronos 笔记本上的时间序列预测简介](https://github.com/aws/amazon-sagemaker-examples/blob/default/%20%20%20%20generative_ai/sm-jumpstart_time_series_forecasting.ipynb)开始使用。 SageMaker JumpStart 

有关可用的 Chronos 更多信息，请参阅 [可用的基础模型](jumpstart-foundation-models-latest.md)。

## 文本生成
<a name="jumpstart-foundation-models-example-notebooks-text-generation"></a>

探索文本生成示例笔记本，包括一般文本生成工作流、多语言文本分类、实时批量推理、少样本学习、聊天机器人交互等方面的指导。
+ [SageMaker JumpStart 基础模型——以 FLAN-T5 XL 为例生成 HuggingFace Text2Text](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/text2text-generation-flan-t5.html)
+ [SageMaker JumpStart 基础模型——BloomZ：多语言文本分类、问答、代码生成、段落改写等](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/text2text-generation-bloomz.html)
+ [SageMaker JumpStart 基础模型- HuggingFace Text2Text 生成批量转换和实时批量推理](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/text2text-generation-Batch-Transform.html)
+ [SageMaker JumpStart 基础模型——GPT-J、GPT-neo Few-shot Learning](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/text-generation-few-shot-learning.html)
+ [SageMaker JumpStart 基础模型-聊天机器人](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/text-generation-chatbot.html)
+ [简介 SageMaker JumpStart -使用 Mistral 模型生成文本](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/mistral-7b-instruction-domain-adaptation-finetuning.html)
+ [简介 SageMaker JumpStart -使用 Falcon 模型生成文本](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/falcon-7b-instruction-domain-adaptation-finetuning.html)

## 图像生成
<a name="jumpstart-foundation-models-example-notebooks-image-generation"></a>

开始使用 text-to-image稳定扩散模型，学习如何部署修复模型，并尝试使用简单的工作流程来生成狗的图像。
+ [简介 JumpStart -文字转图像](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart_text_to_image/Amazon_JumpStart_Text_To_Image.html)
+ [ JumpStart 图像编辑简介-稳定扩散修复术](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart_inpainting/Amazon_JumpStart_Inpainting.html)
+ [为您的狗生成有趣的图片](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart_text_to_image/custom_dog_image_generator.html)

## 模型自定义
<a name="jumpstart-foundation-models-example-notebooks-model-customization"></a>

有时，您的使用案例需要针对特定任务进行更多的基础模型自定义。有关模型自定义方法的更多信息，请参阅[基础模型自定义](jumpstart-foundation-models-customize.md)或浏览以下示例笔记本之一。
+ [SageMaker JumpStart 基础模型——微调特定领域数据集上的文本生成 GPT-J 6B 模型](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/domain-adaption-finetuning-gpt-j-6b.html)
+ [SageMaker JumpStart 基础模型- HuggingFace Text2Text 指令微调](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/instruction-fine-tuning-flan-t5.html)
+ [检索增强生成：使用 LangChain 和 Cohere 的生成和嵌入模型进行问答 SageMaker JumpStart](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_Cohere+langchain_jumpstart.html)
+ [检索增强生成：使用- LLama 2、Pinecone 和自定义数据集回答问题](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_pinecone_llama-2_jumpstart.html)
+ [检索增强生成：基于开源库的自定义数据集问答 LangChain ](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_langchain_jumpstart.html)
+ [检索增强生成：基于自定义数据集的问题回答](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_jumpstart_knn.html)
+ [检索增强生成：使用 Llama-2 和文本嵌入模型进行问题解答](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/question_answering_text_embedding_llama-2_jumpstart.html)
+ [Amazon SageMaker JumpStart -文本嵌入和句子相似度](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/jumpstart-foundation-models/question_answering_retrieval_augmented_generation/text-embedding-sentence-similarity.html)