Amazon Bedrock 上的 Meta Llama 3 模型现已可用

2024/4/24
|
关键词:
Amazon Bedrock
AWS 机器学习
人工智能
功能
生成式 AI

今天,我们宣布 Amazon Bedrock 上的 Meta Llama 3 模型 已正式可用。Meta Llama 3 旨在帮助您构建、试验和可靠地扩展您的 生成式人工智能 (AI) 应用。新的 Llama 3 模型具备改进的推理、代码生成和指令功能,能够支持广泛的用例。

根据 Meta 的 Llama 3 公告,Llama 3 模型系列是一组在 8B 和 70B 参数上进行了预训练和指令调整的大型语言模型 (LLMs)。这些模型已在超过 15 万亿个 Token 上进行了训练——训练数据集的规模是 Llama 2 模型 所使用的七倍,其中包含四倍的代码量,支持相较于Llama 2 容量翻倍的 8K 上下文长度。

您可以在 Amazon Bedrock 中使用两个新的 Llama 3 模型,Amazon Bedrock 现在有了更多的模型选择。这些模型让您能够轻松试验和评估更多的顶级基础模型 (FMs) 以适应您的用例:

  • Llama 3 8B 适用于有限的计算能力和资源,以及边缘设备。该模型擅长于文本摘要、文本分类、情感分析和语言翻译。
  • Llama 3 70B 适用于内容创建、对话式 AI、语言理解、研究与开发以及企业应用。该模型在文本摘要和准确性、文本分类和细微差别、情感分析和细微推理、语言建模、对话系统、代码生成和遵循指令方面表现出色。

Meta 还正在训练超过 400B 参数大小的其它 Llama 3 模型。这些 400B 模型将具备新的功能,包括多模态、多语言支持和更长的上下文窗口。这些模型在发布后将适用于内容创建、对话式 AI、语言理解、研究与开发 (R&D) 以及企业应用。

Llama 3 模型的实际应用

如果您是首次使用 Meta 模型,请转到 Amazon Bedrock 控制台,并选择左下角的“模型访问”。若需访问来自 Meta 的最新 Llama 3 模型,请分别请求访问 Llama 3 8B InstructLlama 3 70B Instruct

若需在 Amazon Bedrock 控制台中测试 Meta Llama 3 模型,请在左侧菜单窗格中的“场合”选择“文本”或“聊天”。然后选择“选择模型”,并选择类别为“Meta”,模型为“Llama 8B Instruct”或“Llama 3 70B Instruct”。

通过选择“查看 API 请求”,您还可以使用 亚马逊云科技命令行界面 (AWS CLI) 和 AWS SDK 中的代码示例访问模型。您可以通过模型 ID 进行访问,例如 meta.llama3-8b-instruct-v1  或 meta.llama3-70b-instruct-v1。

以下是 AWS CLI 命令示例:

$ aws bedrock-runtime invoke-model \
  --model-id meta.llama3-8b-instruct-v1:0 \
  --body "{\"prompt\":\"Simply put, the theory of relativity states that\\n the laws of physics are the same everywhere in the universe, and that the passage of time and the length of objects can vary depending on their speed and position in a gravitational field \",\"max_gen_len\":512,\"temperature\":0.5,\"top_p\":0.9}" \
  --cli-binary-format raw-in-base64-out \
  --region us-east-1 \
  invoke-model-output.txt

您可以借助 Amazon Bedrock的代码示例,使用支持各种编程语言的 AWS SDK 构建您的应用程序。以下的 Python 代码示例演示了如何在 Amazon Bedrock 中调用 Llama 3 Chat 模型进行文本生成。

def invoke_llama3(self, prompt):
        try:
            body = {
                "prompt": prompt,
                "temperature": 0.5,
                "top_p": 0.9,
                "max_gen_len": 512,
            }

            response = self.bedrock_runtime_client.invoke_model(
                modelId="meta.llama3-8b-instruct-v1:0", body=json.dumps(body)
            )

            response_body = json.loads(response["body"].read())
            completion = response_body["generation"]

            return completion

        except ClientError:
            logger.error("Couldn't invoke Llama 3")
            raise

您可以将这些 Llama 3 模型应用于各种任务,例如问答、语言翻译、情感分析等。以下是一个带有 few-shot 上下文学习的 Llama 3 模型示例,我们在其中提供了模型可用的训练样本。

Input: Translate English to French:
sea otter => loutre de mer
peppermint => menthe poivrée
plush girafe => girafe peluche
cheese =>Output:  fromage
panda => panda
penguin => pingouin
polar bear => ours polaire
puffin => macareux
sloth => paresseux
walrus => morse
whale => baleine
zebra => z\u00e8bre

Translate English to German:
sea otter => Seeotter

您也可以将经过优化的 Llama 3 instruct 模型应用于对话式用例。 instruct 模型端点的输入是聊天助手和用户之间的对话历史记录。因此,您可以提出与目前为止发生的对话相关的问题,并提供以下格式的系统配置定义聊天助手的行为,例如人物角色配置:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>
[SYSTEM_TEXT]<|eot_id|><|start_header_id|>user<|end_header_id|>
[USER_TEXT]<|eot_id|><|start_header_id|>assistant<|end_header_id|>

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

Input: <|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n
I am going to Paris, what should I see?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
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:\n\n
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.\n
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.\n
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.\n\n
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.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n
What is so great about #1?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n
Output: The Eiffel Tower! It's an iconic symbol of Paris and one of the most recognizable landmarks in the world. Here are some reasons why it's so great:\n\n
1. **Engineering marvel**: When it was built for the 1889 World's Fair, the Eiffel Tower was a groundbreaking feat of engineering. It was the tallest structure in the world at the time, standing at 324 meters (1,063 feet).\n
2. **Panoramic views**: The Eiffel Tower offers breathtaking 360-degree views of the city from its observation decks. You can see many of Paris' famous landmarks, such as the Seine River, the Louvre, and Montmartre.\n
3. **Romantic atmosphere**: The Eiffel Tower is often associated with romance and is a popular spot for proposals, weddings, and romantic dinners. The tower's iron latticework and twinkling lights at night add to its romantic ambiance.\n
4. **Historical significance**: The Eiffel Tower has played a significant role in French history, serving as a communication tower during World War I and a symbol of French culture and engineering.\n
5. **Accessibility**: The Eiffel Tower is easily accessible by public transportation or on foot, and there are various ways to experience it, including taking the stairs, elevator, or a guided tour.\n
6. **Nighttime spectacle**: The Eiffel Tower is even more magical at night, when it's illuminated with thousands of twinkling lights. The light show, known as the \"Eiffel Tower Sparkle,\" takes place every hour on the hour from dusk to midnight.\n
7. **Iconic status**: The Eiffel Tower has been featured in countless films, literature, and art, making it an instantly recognizable symbol of Paris and France.\n\n
Overall, the Eiffel Tower is a must-visit attraction in Paris, offering a unique combination of history, engineering, romance, and stunning views.

若需了解有关 Llama 3 模型的新提示模板和特殊 Token的更多信息,请查阅 Meta 的 模型卡和提示格式,或在 GitHub 存储库中查看 Llama 配方

现已可用

Meta 的 Llama 3 模型在美国东部(弗吉尼亚州)和美国西部(俄勒冈州)地区的 Amazon Bedrock 中现已可用。请查看 完整的区域支持列表 以获取未来更新。若需了解更多信息,请查看 Amazon Bedrock 产品页面中的 Llama 和 价格页面

请立即在 Amazon Bedrock 控制台 中尝试 Llama 3,并通过 AWS re:Post for Amazon Bedrock 或通过您的亚马逊云科技常用联系方式发送反馈。

请访问我们的 community.aws 网站以查找深度技术内容,并了解我们的构建者社区如何在其解决方案中使用 Amazon Bedrock。

作者简介

Channy Yun 是亚马逊云科技的首席开发者布道师,他热衷于帮助开发人员在最新的亚马逊云科技服务上构建现代应用程序。作为一个务实的开发者和博主,他热爱社区驱动的学习和技术分享,并将开发人员聚集到全球亚马逊云科技用户群体中。他的博客主题主要为开源、容器、存储、网络和安全以及物联网。请关注他的推特账号 @channyun。

新手入门

快速体验生成式 AI

无需部署,借助开箱即用的 Amazon Bedrock 一次体验多种高性能模型,包括 Claude 3, Llama 3, SDXL, Mistral 等。

快速部署管理私服游戏

一键启动所需资源,快速完成游戏私服的自动化启动,备份以及恢复。

使用生成式 AI 构建多语言问答知识库

使用多种服务,构建可汇总搜索结果的多语言知识库。

免费套餐

AWS 海外区域

拓展海外业务或个人体验
免费使用 100 余种云产品或服务, 长达 12 个月

AWS 中国区域

发展中国业务
免费使用 40 余种核心云服务产品,长达 12 个月