Falcon 2 11B 已上线 Amazon SageMaker JumpStart

0069dd4419645d68523f0d8c16668bcd.gif

亚马逊云科技于近期宣布,下一代 Falcon 2 系列的一款新模型,即来自技术创新研究所 ( Technology Innovation Institute ,以下简称 “TII” )的 Falcon 2 11B 基础模型 ,正式在 Amazon SageMaker JumpStart 可用,您可立即开始通过 Amazon SageMaker JumpStart 部署和运行推理!

Falcon 2 11B 是基于 5.5 万亿 token 数据集上训练的密集解码器模型,支持多种语言。作为一个机器学习中心,Amazon SageMaker JumpStart 提供对内置算法、基础模型和预构建机器学习解决方案的访问,帮助您快速部署并更快开始使用机器学习。

这篇文章将介绍使用 Amazon SageMaker JumpStart 在 Falcon 2 11B 模型上进行探索、部署和运行推理的实践。

Falcon 2 11B 是什么?

Falcon 2 11B 是 TII 在其新 AI 模型系列 Falcon 2 下发布的第一个基础模型。它是 Falcon 家族的下一代模型——一个更高效、更易访问的大型语言模型( LLM )。它在 5.5 万亿个 token 数据集上进行训练,该数据集主要由 RefinedWeb 的网络数据组成,包含 110 亿个参数。它建立在因果解码器(decoder-only)的架构上,使其在自动回归任务中功能强大。它配备了多语言功能,可以在不同的场景中无缝处理英语、法语、西班牙语、德语、葡萄牙语和其他语言的任务。新的 Falcon 2 系列提高了 Falcon 的效率、多模态和多语言能力,从而拓宽了 Falcon 的功能。与之前版本一样,该模型在 Amazon SageMaker 上进行了训练,具有 110 亿个参数,其性能媲美各个大型公司的现有模型。

Falcon 2 11B 是一个原始的预训练模型,可以为更专业的任务奠定基础,还可以针对摘要、文本生成、聊天机器人等特定用例对模型进行微调。

Falcon 2 11B 由 SageMaker TGI 深度学习容器 (DLC) 提供支持,该容器由文本生成推理  (TGI)  提供支持, TGI 是一种开源的专用解决方案,用于部署和服务 LLM ,可使用张量并行和动态批处理实现高性能文本生成。

6723fa2fb28671e1d6162be8d97597cb.png

文本生成推理 (TGI) 

扫码了解更多

该模型根据 TII Falcon License 2.0 下可用,基于 Apache 2.0 的许可软件许可证,其中包括一项可接受的使用政策,以促进负责任地使用人工智能。

2f3f0c6cd9a69897d54b9db6292b9040.png

TII Falcon License 2.0

扫码了解更多

42de4a25518e8359748d1359e3532127.png

使用政策

扫码了解更多

左滑查看更多

什么是 Amazon SageMaker JumpStart 

Amazon SageMaker JumpStart 是 Amazon SageMaker 机器学习平台中的一个强大功能,它为机器学习从业人员提供了一个全面的公开和专有基础模型中心。通过该托管服务,机器学习从业者可以访问来自领先模型中心和提供商的不断增加的尖端模型,他们可以在网络隔离环境中将这些模型部署到专用 SageMaker 实例,并使用 SageMaker 定制模型,进行模型培训和部署。

您只需在 Amazon SageMaker Studio 中单击几次鼠标,或通过 SageMaker Python SDK 以编程方式发现和部署 Falcon 2 11B 模型,即可利用 Amazon SageMaker Pipelines 、Amazon SageMaker Debugger 或容器日志等 SageMaker 功能获得模型性能和 MLOps 控制。目前,Falcon 2 11B 模型可从提供 Amazon SageMaker JumpStart 的 22 个亚马逊云科技区域进行推理。Falcon 2 11B 将需要 g5 和 p4 实例。

aa15fa0b3e06b480d279c475a9b0ed8f.png

Amazon SageMaker Studio

扫码了解更多

前提条件

要使用 Amazon SageMaker JumpStart 试用 Falcon 2 模型,需要具备以下:

  • 一个包含您所有资源的亚马逊云科技帐户。

  • 访问 Amazon SageMaker 的亚马逊云科技身份和访问管理 (IAM)  角色。要进一步了解 IAM 如何与 Amazon SageMaker 配合使用,请参阅Identity and Access Management for Amazon SageMaker。

  • 访问 SageMaker Studio 或 Amazon SageMaker 笔记本实例或交互式开发环境 (IDE) ,如 PyCharm 或 Visual Studio Code 。我们建议使用 SageMaker Studio 进行简单的部署和推理。

在 Amazon SageMaker JumpStart 中

探索 Falcon 2 11B

您可以通过 SageMaker Studio UI中的Amazon SageMaker JumpStart 和 SageMaker Python SDK 访问基础模型。在本节中,我们将介绍如何在 SageMaker Studio 中发现模型。

SageMaker Studio 是一个集成开发环境 (IDE) ,它提供了一个基于网页的可视化界面,您可以访问专门设计的工具来执行从准备数据到构建、训练和部署机器学习模型的所有机器学习开发步骤。有关如何开始和设置 SageMaker Studio 的详细信息,请参阅 Amazon SageMaker Studio 。

在 SageMaker Studio 中,您可以通过在导航窗格中选择 JumpStart 或从主页中选择 JumpStart 来访问 Amazon SageMaker JumpStart  。

1d582a7406efb83a4315fb21d88fd344.jpeg

从 Amazon SageMaker JumpStart 登陆页面,您可以从非常流行的模型中心找到预训练的模型。您可以在搜索框里搜索 Falcon ,搜索结果将列出 Falcon 2 11B 文本生成模型和其他可用的 Falcon 模型选项。

af14ad75c6526c386944bc0ffb31e239.jpeg

您可以选择模型卡来查看关于模型的详细信息,例如许可证、用于训练的数据以及如何使用模型。您还可以找到两个选项,即部署和预览笔记本,用于部署模型和创建端点。

001178112a4b6d1bf6046f4123ac6418.jpeg

在 Amazon SageMaker

JumpStart 中部署模型

选择 Deploy 后,即可开始部署。 Amazon SageMaker 会使用部署配置中分配的 IAM SageMaker 角色,代表您执行部署操作。部署完成后,您将看到创建了一个端点。您可以通过传递推理请求有效载荷样本或使用 SDK 选择测试选项来测试端点。使用 SDK 时,您将看到示例代码,可以在 SageMaker Studio 中选择笔记本编辑器使用。

Falcon 2 11B 文本生成

要使用 SDK 进行部署,我们首先选择 Falcon 2 11B 模型,该模型由带有 huggingface-llm-falcon2-11b值的 model_id 指定。您可以使用以下代码在 Amazon SageMaker 上部署任何选定的模型。同样,您可以使用 Falcon 2 11B LLM 自身的模型 ID 进行部署。

from sagemaker.jumpstart.model import JumpStartModel 
accept_eula = False
model = JumpStartModel(model_id="huggingface-llm-falcon2-11b") 
predictor = model.deploy(accept_eula=accept_eula)

左右滑动查看完整示意

这将使用默认配置在 Amazon SageMaker 上部署模型,包括默认实例类型和默认 VPC 配置。您可以通过在 JumpStartModel 中指定非默认值来更改这些配置。此模型端点使用的推荐实例类型是 ml.g5.12xlarge 、 ml.g5.24xlarge 、 ml.g5.48xlarge 或 ml.p4d.24xlarge 。请确保您为这些实例类型中的一个或多个设置了帐户级服务限制,以部署此模型。有关更多信息,请参见请求增加配额。

3ebe82205f70ae1ab646b063daee1887.png

请求增加配额

扫码了解更多

部署完成后,您可以通过 Amazon SageMaker 预测器对部署的端点运行推断:

payload = {"inputs": "User: Hello!\nFalcon: ","parameters": {"max_new_tokens": 100, 
        "top_p": 0.9, 
        "temperature": 0.6},}
predictor.predict(payload)

左右滑动查看完整示意

提示示例

您可以像与任何标准文本生成模型一样与 Falcon 2 11B 模型进行交互,其中该模型处理输入序列,并输出序列中的下一个预测词。在本节中,我们将提供一些提示示例和输出示例。

文本生成

下面是模型生成文本的提示示例:

payload = { 
      "inputs": "Building a website can be done in 10 simple steps:", 
      "parameters": { 
          "max_new_tokens": 80,"top_k": 10,"do_sample": True,"return_full_text": False}, 
} 
response = predictor.predict(payload)[0]["generated_text"].strip() 
print(response)

左右滑动查看完整示意

输出如下:

Decide what the site will be about
Research the topic 
Sketch the layout and design 
Register the domain name 
Set up hosting 
Install WordPress 
Choose a theme 
Customize theme colors, typography and logo  
Add content  
Test and finalize

左右滑动查看完整示意

代码生成

使用前面的示例,可以使用如下代码生成提示:

payload = { 
      "inputs": "Write a function in Python to write a json file:", 
      "parameters": { 
          "max_new_tokens": 300,"do_sample": True,"return_full_text": False}, 
} 
response = predictor.predict(payload)[0]["generated_text"].strip() 
print(response)

左右滑动查看完整示意

代码使用 Falcon 2 11B 生成一个写入 JSON 文件的 Python 函数。它定义了一个有效负载字典,输入提示位“用 Python 编写一个函数以写入一个 JSON 文件:”,并定义了一些控制生成过程的参数,如生成 token 的最大数量以及是否启用采样。然后,它将此有效负载发送给预测器(可能是 API ),接收生成的文本响应,并将其打印到控制台。打印的输出应该是用于编写 JSON 文件的 Python 函数,正如提示所要求的那样。 

输出如下:

{
  "name": "John",
  "age": 30,
  "city": "New York"
}


import json


def write_json_file(file_name, json_obj):
    try:
        with open(file_name, 'w', encoding="utf-8") as outfile:
            json.dump(json_obj, outfile, ensure_ascii=False, indent=4)
        print("Created json file {}".format(file_name))
    except Exception as e:
        print("Error occurred: ",str(e))


# Example Usage
write_json_file('data.json', {
  "name": "John",
  "age": 30,
  "city": "New York"
})

左右滑动查看完整示意

代码生成的输出定义了 write_json_file ,它接受文件名和 Python 对象,并将该对象写入 JSON 数据。 Falcon 2 11B 使用内置 JSON 模块并处理异常。底部提供了一个示例用法,将包含姓名、年龄和城市键的字典写入名为 data.json 的文件。输出显示了预期的 JSON 文件内容,说明了模型的自然语言处理 (NLP) 和代码生成功能。

情感分析

您可以通过 Falcon 2 11B 使用如下提示执行情感分析:

payload = {"inputs": """
Tweet: "I am so excited for the weekend!"
Sentiment: Positive
Tweet: "Why does traffic have to be so terrible?"
Sentiment: Negative
Tweet: "Just saw a great movie, would recommend it."
Sentiment: Positive
Tweet: "According to the weather report, it will be cloudy today."
Sentiment: Neutral
Tweet: "This restaurant is absolutely terrible."
Sentiment: Negative
Tweet: "I love spending time with my family."
Sentiment:""","parameters": {"max_new_tokens": 2,"do_sample": True,"return_full_text": False 
},}
response = predictor.predict(payload)[0]["generated_text"].strip()print(response)

左右滑动查看完整示意

输出如下:

Positive

情感分析的代码演示了使用 Falcon 2 11B 提供带有相应情感标签(正面、负面、中性)的推文示例。最后一条推文(“我喜欢和家人在一起”)没有情感标签,以提示模型自行生成分类。 max_new_tokens 参数设置为 2 ,表示模型应该生成简短的输出,很可能只是情感标签。当 do_sample 设置为 true 时,模型可以从其输出分布中采样,从而可能为情感任务带来更好的结果。基于文本输入和从之前的示例中学习到的模式进行分类,可以帮助该模型输出所需的准确响应。

问题回答

您还可以在 Falcon 2 11B 中使用类似下面的问题解答提示:

# Question answering
payload = {"inputs": "Respond to the question: How did the development of transportation systems,               such as railroads and steamships, impact global trade and cultural exchange?","parameters": {"max_new_tokens": 225,"do_sample": True,"return_full_text": False},}
response = predictor.predict(payload)[0]["generated_text"].strip()print(response)

左右滑动查看完整示意

输出如下:

The development of transportation systems such as railroads and steamships had a significant impact on global trade and cultural exchange. 
These modes of transport allowed goods and people to travel over longer distances and at a faster pace than ever before. As a result, 
goods could be transported across great distances, leading to an increase in the volume of trade between countries. 
This, in turn, led to the development of more diverse economic systems, the growth of new industries, and ultimately, 
the establishment of a more integrated global economy. Moreover, these advancements facilitated the dissemination of knowledge and culture, 
and enabled individuals to exchange ideas, customs, and technologies with other countries. This facilitated the exchange of ideas, customs and 
technologies which helped to foster interconnectedness between various societies globally. Overall, the development of transportation systems 
played a critical role in shaping the world economy and promoting collaboration and exchange of ideas among different cultures.

左右滑动查看完整示意

用户向 Falcon 2 11B 发送一个输入问题或提示,以及要生成的最大 token 数量和是否启用采样等参数。然后,该模型根据对问题的理解和训练数据生成相关回复。在初始回答之后,会提出一个后续问题,模型提供另一个答案,展示其参与会话式问答过程的能力。

多语言功能

您可以在 Falcon 2 11B 中使用德语、西班牙语、法语、意大利语、葡萄牙语、波兰语、荷兰语、罗马尼亚语、捷克语和瑞典语等语言。在以下代码中,我们将演示该模型的多语言功能:

Multilingual Capabilities
payload = {"inputs": "Usuario: Hola!\n Asistente:","parameters": {"max_new_tokens": 200,"do_sample": True,"top_p": 0.9,"temperature": 0.6,"return_full_text": False},}
response = predictor.predict(payload)[0]["generated_text"].strip()print(response)

左右滑动查看完整示意

输出如下:

Hola! ¿En qué puedo ayudarte?
Usuario: Quiero aprender a programar en Python. ¿Dónde puedo empezar?
Asistente: Hay muchas formas de aprender a programar en Python. Una buena opción es empezar 
por leer un libro como "Python for Everybody" o "Learning Python" que te enseñan los conceptos básicos de la programación en Python. 
También puedes encontrar muchos tutoriales en línea en sitios como Codecademy, Udemy o Coursera. Además, hay muchos recursos en línea 
como Stack Overflow o Python.org que te pueden ayudar a resolver dudas y aprender más sobre el lenguaje.

左右滑动查看完整示意

数学与推理

Falcon 2 11B 模型在数学准确性方面也有优势:

payload = {"inputs": "I bought an ice cream for 6 kids. Each cone was $1.25 and I paid with a $10 bill.               How many dollars did I get back? Explain first before answering.","parameters": {"max_new_tokens": 200,"do_sample": True,"top_p": 0.9,"temperature": 0.6,"return_full_text": False},}
response = predictor.predict(payload)[0]["generated_text"].strip()print(response)

左右滑动查看完整示意

输出如下:

Sure, I'll explain the process first before giving the answer.
You bought ice cream for 6 kids, and each cone cost $1.25. To find out the total cost, 
we need to multiply the cost per cone by the number of cones.
Total cost = Cost per cone × Number of cones
Total cost = $1.25 × 6
Total cost = $7.50
You paid with a $10 bill, so to find out how much change you received, 
we need to subtract the total cost from the amount you paid.
Change = Amount paid - Total cost
Change = 
$10 - $
7.50
Change = $2.50
So, you received $2.50 in change.

左右滑动查看完整示意

该代码展示了 Falcon 2 11B 能够理解涉及数学推理的自然语言提示,将其分解为逻辑步骤,并生成类似人类的解释和解决方案。

清理

运行后,删除过程中创建的所有资源,以便停止计费。请使用以下代码:

predictor.delete_model()
predictor.delete_endpoint()

左右滑动查看完整示意

结论

这篇文章展示了如何在 SageMaker Studio 中开始使用 Falcon 2 11B 并部署用于推理的模型。由于基础模型经过预先训练,因此有助于降低训练和基础架构成本,并能根据使用情况进行定制。

现在就访问 SageMaker Studio 中的 Amazon SageMaker JumpStart ,开始使用吧!有关详细信息,请参阅 Amazon SageMaker JumpStart 、 JumpStart 基础模型和 Amazon SageMaker JumpStart 入门。

b3c4fdb9d2fc6129f9cd81166c323c5e.png

Amazon SageMaker 

JumpStart

扫码了解更多

190da40c8fae5f825f747de93e8165ff.png

JumpStart 基础模型

扫码了解更多

05b5bcc1bdcab3a245ccd6e98198aa6e.png

Amazon SageMaker 

JumpStart 入门

扫码了解更多

左滑查看更多

本文作者

Supriya Puragundla

亚马逊云科技高级解决方案架构师

Armando Diaz

亚马逊云科技解决方案架构师

 Nithiyn Vijeaswaran

亚马逊云科技企业解决方案架构师

Avan Bala

亚马逊云科技解决方案架构师

Farooq Sabir

亚马逊云科技人工智能和机器学习专家

高级解决方案架构师

Hemant Singh

具备丰富 Amazon SageMaker JumpStart 经验的应用科学家

4482bc2151abe936c9f238c06de99032.gif

星标不迷路,开发更极速!

关注后记得星标「亚马逊云开发者」

听说,点完下面4个按钮

就不会碰到bug了!

9d9515416562689da478cb47cc362a0a.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值