Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 | 亚马逊网络服务

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 | 亚马逊网络服务

今天,我们很高兴地宣布 Meta 开发的 Llama 2 基础模型可供客户通过 亚马逊SageMaker JumpStart。 Llama 2 系列大型语言模型 (LLM) 是预先训练和微调的生成文本模型的集合,其规模从 7 亿到 70 亿个参数不等。 经过微调的 LLM,称为 Llama-2-chat,针对对话用例进行了优化。 您可以轻松尝试这些模型并将其与 SageMaker JumpStart 结合使用,SageMaker JumpStart 是一个机器学习 (ML) 中心,可提供对算法、模型和 ML 解决方案的访问,以便您可以快速开始使用 ML。

在这篇文章中,我们将介绍如何通过 SageMaker JumpStart 使用 Llama 2 模型。

什么是骆驼 2

Llama 2 是一种使用优化的 Transformer 架构的自回归语言模型。 Llama 2 旨在用于英语商业和研究用途。 它具有一系列参数大小(7 亿、13 亿和 70 亿)以及预训练和微调的变量。 根据 Meta 的说法,调整后的版本使用监督微调(SFT)和带有人类反馈的强化学习(RLHF)来符合人类对帮助和安全的偏好。 Llama 2 使用来自公开来源的 2 万亿个代币数据进行了预训练。 调整后的模型旨在用于类似助理的聊天,而预训练的模型可适用于各种自然语言生成任务。 无论开发人员使用哪个版本的模型, Meta 的负责任使用指南 可以帮助指导通过适当的安全缓解措施定制和优化模型可能需要的额外微调。

什么是 SageMaker JumpStart

借助 SageMaker JumpStart,机器学习从业者可以从多种开源基础模型中进行选择。 机器学习从业者可以将基础模型部署到专用的 亚马逊SageMaker 来自网络隔离环境的实例,并使用 SageMaker 自定义模型进行模型训练和部署。

您现在只需点击几下即可发现并部署 Llama 2 亚马逊SageMaker Studio 或通过 SageMaker Python SDK 以编程方式,使您能够利用 SageMaker 功能导出模型性能和 MLOps 控制,例如 Amazon SageMaker管道, Amazon SageMaker调试器,或容器日志。 该模型部署在 AWS 安全环境中并受您的 VPC 控制,有助于确保数据安全。 Llama 2 模型现已在 Amazon SageMaker Studio 中提供,最初在 us-east 1us-west 2 地区。

探索型号

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

SageMaker Studio 是一个集成开发环境 (IDE),提供基于 Web 的单一可视化界面,您可以在其中访问专用工具来执行所有 ML 开发步骤,从准备数据到构建、训练和部署 ML 模型。 有关如何开始和设置 SageMaker Studio 的更多详细信息,请参阅 亚马逊SageMaker Studio.

进入 SageMaker Studio 后,您可以访问 SageMaker JumpStart,其中包含预训练的模型、笔记本和预构建的解决方案,位于 预构建和自动化解决方案.

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。

在 SageMaker JumpStart 登录页面中,您可以浏览解决方案、模型、笔记本和其他资源。 您可以在以下位置找到两款旗舰 Llama 2 型号: 基础型号: 文本生成 旋转木马。 如果您没有看到 Llama 2 模型,请通过关闭并重新启动来更新您的 SageMaker Studio 版本。 有关版本更新的更多信息,请参阅 关闭并更新 Studio 应用程序.

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。

您还可以通过选择找到其他四种型号变体 探索所有文本生成模型 或搜寻 llama 在搜索框中。

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。

您可以选择模型卡来查看有关模型的详细信息,例如许可证、用于训练的数据以及如何使用。 您还可以找到两个按钮, 部署打开笔记本,这可以帮助您使用该模型。

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。

当您选择任一按钮时,弹出窗口将显示最终用户许可协议和可接受的使用政策,供您确认。

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。

确认后,您将继续下一步使用该模型。

部署模型

当你选择 部署 并确认条款,模型部署将开始。 或者,您可以通过选择显示的示例笔记本进行部署 打开笔记本。 该示例笔记本提供了有关如何部署模型进行推理和清理资源的端到端指导。

要使用笔记本进行部署,我们首先选择适当的模型,由 model_id。 您可以使用以下代码在 SageMaker 上部署任何选定的模型:

from sagemaker.jumpstart.model import JumpStartModel
my_model = JumpStartModel(model_id = "meta-textgeneration-llama-2-70b-f")
predictor = my_model.deploy()

这会使用默认配置(包括默认实例类型和默认 VPC 配置)在 SageMaker 上部署模型。 您可以通过在中指定非默认值来更改这些配置 快速启动模型。 部署后,您可以通过 SageMaker 预测器对部署的终端节点运行推理:

payload = { “inputs”: [ [ {"role": "system", "content": "Always answer with Haiku"}, {"role": "user", "content": "I am going to Paris, what should I see?"}, ] ], "parameters":{"max_new_tokens":256, "top_p":0.9, "temperature":0.6}
}

微调的聊天模型(Llama-2-7b-chat、Llama-2-13b-chat、Llama-2-70b-chat)接受用户和聊天助手之间的聊天历史记录,并生成后续聊天。 预训练模型(Llama-2-7b、Llama-2-13b、Llama-2-70b)需要字符串提示并根据提供的提示执行文本完成。 请看下面的代码:

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

请注意,默认情况下, accept_eula 设置为 false。 你需要设置 accept_eula=true 成功调用端点。 通过这样做,您接受前面提到的用户许可协议和可接受的使用政策。 你也可以 下载 许可协议。

Custom_attributes 用于传递 EULA 的是键/值对。 键和值之间用 分隔 = 并且对之间由 ;。 如果用户多次传递相同的键,则保留最后一个值并将其传递给脚本处理程序(即,在本例中,用于条件逻辑)。 例如,如果 accept_eula=false; accept_eula=true 被传递到服务器,然后  accept_eula=true 被保留并传递给脚本处理程序。

推理参数控制端点处的文本生成过程。 最大新令牌控制是指模型生成的输出的大小。 请注意,这与单词数不同,因为模型的词汇表与英语词汇不同,并且每个标记可能不是英语单词。 温度控制输出的随机性。 较高的温度会产生更多的创造性和幻觉输出。 所有推理参数都是可选的。

下表列出了 SageMaker JumpStart 中可用的所有 Llama 模型以及 model_ids、默认实例类型以及每个模型支持的最大总令牌数(输入令牌数与生成令牌数之和)。

型号名称 型号ID 最大总代币数 默认实例类型
骆驼-2-7b 元文本生成-llama-2-7b 4096 ml.g5.2xlarge
Llama-2-7b-聊天 元文本生成-llama-2-7b-f 4096 ml.g5.2xlarge
骆驼-2-13b 元文本生成-llama-2-13b 4096 ml.g5.12xlarge
Llama-2-13b-聊天 元文本生成-llama-2-13b-f 4096 ml.g5.12xlarge
骆驼-2-70b 元文本生成-llama-2-70b 4096 ml.g5.48xlarge
Llama-2-70b-聊天 元文本生成-llama-2-70b-f 4096 ml.g5.48xlarge

请注意,SageMaker 端点的超时限制为 60 秒。 因此,即使模型可能能够生成 4096 个令牌,但如果文本生成时间超过 60 秒,请求将会失败。 对于 7B、13B 和 70B 型号,我们建议设置 max_new_tokens 分别不超过1500、1000、500,同时保持代币总数小于4K。

Llama-2-70b 的推理和示例提示

您可以使用 Llama 模型来完成任何文本片段的文本补全。 通过文本生成,您可以执行各种任务,例如回答问题、语言翻译、情感分析等等。 端点的输入有效负载类似于以下代码:

payload = { “inputs”: str, (optional)"parameters":{"max_new_tokens":int, "top_p":float, "temperature":float}
}

以下是一些示例提示和模型生成的文本。 所有输出均使用推理参数生成 {"max_new_tokens":256, "top_p":0.9, "temperature":0.6}.

Input: Simply put, the theory of relativity states that Output: 1) the laws of physics are the same for all observers in uniform motion relative to one another, and 2) the speed of light is the same for all observers, regardless of their relative motion or of the motion of the source of the light.
In the late 1800s, scientists believed that light travelled through a medium they called the luminiferous ether. But in 1887, Albert Michelson and Edward Morley designed an experiment to measure the speed of light in the ether, and found that the speed of light was the same no matter how they oriented their equipment. This result seemed to contradict the idea of the ether, and Michelson and Morley’s experiment became one of the most famous failed experiments in history.
In 1905, Albert Einstein published a paper that used the results of the Michelson-Morley experiment to develop the theory of special relativity. In 1915, Einstein published a paper on general relativity, which is a theory of gravitation.
In physics, the speed of light is considered to be a constant, and its value is 299,792,458 metres Input: I believe the meaning of life is Output: to be happy, to find joy in life, to love and be loved. To have the courage to be yourself and to be kind to others. To be able to express yourself, to create and to be inspired. To be able to give and receive. To be able to learn and grow. To be able to find beauty in the world and to be able to appreciate it. To be able to find peace and contentment. To be able to find meaning and purpose. To be able to make a difference in the world. To be able to find joy in the simple things. To be able to find joy in the difficult things. To be able to find joy in the journey. To be able to find joy in the destination. To be able to find joy in the present moment. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy Input: A brief message congratulating the team on the launch: Hi everyone, I just Output: wanted to send a quick note to congratulate everyone on the launch of our new website. I know it’s been a long time coming and I’m sure we’re all relieved that it’s finally out there. Thanks to everyone for their hard work and dedication over the last few months. I know it wasn’t always easy, but I think we can all be proud of the final product. I’m looking forward to seeing how our users respond to the new site and I’m confident that it will be a success. Thanks again, and enjoy the rest of your day! Best, [Your Name] [Your Title] [Your Company] [Your Email] [Your Phone Number] [Your Website] [Your Social Media Handles] [Your Address] [Your City, State, Zip Code] [Your Country] [Your Postal Code] [Your Website] [

在下一个示例中,我们将展示如何使用 Llama 模型进行少量上下文学习,其中我们为模型提供可用的训练样本。 请注意,我们仅对已部署的模型进行推断,在此过程中,模型权重不会改变。

Input: Translate English to French: sea otter => loutre de mer peppermint => menthe poivrée plush girafe => girafe peluche cheese => Output: fromage chocolate => chocolat car => voiture hamster => hamster beer => bière bicycle => bicyclette banana => banane strawberry => fraise pizza => pizza cheeseburger => cheeseburger pineapple => ananas carrot => carotte watermelon => pastèque whale => baleine eggplant => aubergine cat => chat penguin => manchot lion => lion elephant => éléphant panda => panda tiger => tigre salmon => saumon squirrel => écureuil kangaroo => kangourou turtle => tortue octopus => poulpe frog => grenouille pig => cochon goldfish => poisson rouge tiger shark => requin tigre gorilla => gorille dol

Llama-2-70b-chat 的推理和示例提示

对于针对对话用例进行了优化的 Llama-2-Chat 模型,聊天模型端点的输入是聊天助手和用户之间的先前历史记录。 您可以提出与目前所发生的对话相关的问题。 您还可以提供系统配置,例如定义聊天助理行为的角色。 端点的输入有效负载类似于以下代码:

payload = { “inputs”: [ [ (optional){"role": "system", "content": str}, (repeated k times) {"role": "user", "content": str}, {"role": "assistant", "content": str}, {"role": "user", "content": str}, ] ], (optional)"parameters":{"max_new_tokens":int, "top_p":float, "temperature":float}
}

以下是一些示例提示和模型生成的文本。 所有输出均使用推理参数生成 {"max_new_tokens": 512, "top_p": 0.9, "temperature": 0.6}.

Input:
User: what is the recipe of mayonnaise? Output:
Assistant: Sure, I can help you with that! Mayonnaise is a thick, creamy condiment made from a mixture of egg yolks, oil, vinegar or lemon juice, and seasonings. Here's a basic recipe for homemade mayonnaise: Ingredients: * 2 egg yolks
* 1/2 cup (120 ml) neutral-tasting oil, such as canola or grapeseed
* 1 tablespoon (15 ml) vinegar or lemon juice
* 1/2 teaspoon salt
* 1/4 teaspoon black pepper Instructions: 1. In a medium-sized bowl, whisk together the egg yolks, salt, and black pepper until well combined.
2. Slowly pour the oil into the bowl while continuously whisking the mixture. It's important to add the oil very slowly, otherwise the mixture can break and you'll end up with a separated, curdled mess.
3. Continue whisking until the mixture thickens and emulsifies, which should take about 5-7 minutes. You'll know it's ready when the mixture has doubled in volume and has a thick, creamy consistency.
4. Add the vinegar or lemon juice and continue whisking for another minute or two, until the flavors are fully incorporated.
5. Taste the mayonnaise and adjust the seasoning as needed. You can add more salt, pepper, or acid if desired.
6. Cover the bowl with plastic wrap and refrigerate the mayonnaise for at least 30 minutes before serving. This will allow the flavors to meld together and the mayonnaise to thicken further. That's it! This recipe makes about 1 1/2 cups (360 ml) of mayonnaise, which should be enough for a small to medium-sized batch of sandwiches or salads. You can also customize the recipe by adding different flavorings, such as garlic, mustard, or herbs, to create a unique taste. Enjoy!

在以下示例中,用户与助理就巴黎的旅游景点进行了对话。 接下来,用户询问聊天助手推荐的第一个选项。

Input:
User: I am going to Paris, what should I see?
Assistant: Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris: 1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows. These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.
User: What is so great about #1? Output:
Assistant: The Eiffel Tower is a world-renowned iconic landmark that symbolizes Paris and France. It was built for the World's Fair in 1889 and was initially intended to be a temporary structure, but it has become a permanent part of the Parisian skyline. Here are some reasons why the Eiffel Tower is so great: 1. Engineering marvel: The Eiffel Tower was a groundbreaking feat of engineering at the time of its construction. It stands at 324 meters (1,063 feet) tall and was the tallest structure in the world for over 40 years.
2. Iconic design: The Eiffel Tower's distinctive shape and design make it instantly recognizable. It has been the subject of countless works of art, photographs, and films, and has become a symbol of Paris and France.
3. Panoramic views: The Eiffel Tower offers breathtaking views of the city from its observation decks. Visitors can enjoy a 360-degree view of Paris, including famous landmarks such as the Seine River, the Arc de Triomphe, and the Montmartre neighborhood.
4. Historical significance: The Eiffel Tower has played a significant role in Paris's history, having been the site of numerous important events, including the famous "Battle of the Eiffel Tower" during World War II.
5. Cultural impact: The Eiffel Tower has had a significant impact on popular culture, inspiring countless works of art, literature, and music. It has also been the subject of numerous documentaries and films, including the classic movie "An American in Paris."
6. Romantic setting: The Eiffel Tower is known for its romantic atmosphere, making it a popular destination for couples and newlyweds. It has been the site of countless marriage proposals and has been featured in numerous romantic films and literature.
7. Accessibility: The Eiffel Tower is easily accessible by public transportation, making it a convenient destination for visitors. It is also wheelchair-friendly, with elevators and ramps providing access to all levels. Overall, the Eiffel Tower is a must-see destination for anyone visiting Paris, offering a unique and unforgettable experience that combines history, culture, engineering, and rom

在以下示例中,我们设置系统的配置:

Input:
System: Always answer with Haiku
User: I am going to Paris, what should I see? Output:
Assistant: Eiffel Tower high
Art in the Louvre Museum
River Seine flows Input:
System: Always answer with emojis
User: How to go from Beijing to NY? Output:
Assistant: Here are the emojis that represent the steps to go from Beijing to New York: 🇨🇳🛫🛬🇺🇸🗽🏙️🚕💨🛩️🛬🛫😴💤🛩️🛬🛫😍

清理

运行完笔记本后,请确保删除所有资源,以便删除在此过程中创建的所有资源并停止计费:

predictor.delete_model()
predictor.delete_endpoint()

结论

在这篇文章中,我们向您展示了如何在 SageMaker Studio 中开始使用 Llama 2 模型。 这样,您就可以访问包含数十亿个参数的六个 Llama 2 基础模型。 由于基础模型是预先训练的,因此它们还可以帮助降低培训和基础设施成本,并支持针对您的用例进行定制。 要开始使用 SageMaker JumpStart,请访问以下资源:


关于作者

Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。六月赢了 是 SageMaker JumpStart 的产品经理。 他专注于使基础模型易于发现和使用,以帮助客户构建生成式人工智能应用程序。 他在亚马逊的经验还包括移动购物应用程序和最后一英里送货。

维维克·马丹 Vivek Madan 博士 是 Amazon SageMaker JumpStart 团队的一名应用科学家。 他在伊利诺伊大学厄巴纳-香槟分校获得博士学位,并且是乔治亚理工学院的博士后研究员。 他是机器学习和算法设计方面的活跃研究员,并在 EMNLP、ICLR、COLT、FOCS 和 SODA 会议上发表过论文。 Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。 凯尔乌尔里希博士 是 Amazon SageMaker JumpStart 团队的应用科学家。 他的研究兴趣包括可扩展的机器学习算法、计算机视觉、时间序列、贝叶斯非参数和高斯过程。 他拥有杜克大学博士学位,并在 NeurIPS、Cell 和 Neuron 上发表过论文。 Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。 Ashish Khetan 博士 是 Amazon SageMaker JumpStart 的高级应用科学家,帮助开发机器学习算法。 他在伊利诺伊大学厄巴纳-香槟分校获得博士学位。 他是机器学习和统计推断领域的活跃研究员,并在 NeurIPS、ICML、ICLR、JMLR、ACL 和 EMNLP 会议上发表了多篇论文。 Meta 的 Llama 2 基础模型现已在 Amazon SageMaker JumpStart 中提供 |亚马逊网络服务柏拉图区块链数据智能。垂直搜索。人工智能。 桑达尔·兰加纳坦 是 AWS GenAI/Frameworks GTM 专家的全球主管。 他专注于为大型语言模型、GenAI 和跨 AWS 服务(例如 Amazon EC2、EKS、EFA、AWS Batch 和 Amazon SageMaker)的大规模 ML 工作负载制定 GTM 策略。 他的经验包括在 NetApp、Micron Technology、Qualcomm 和 Mentor Graphics 的产品管理和产品开发中担任领导职务。

时间戳记:

更多来自 AWS机器学习