亚马逊AWS官方博客

Meta 的 Llama 3 模型现已在 Amazon Bedrock 中推出



今天,我们宣布在 Amazon Bedrock 中正式提供 Meta 的 Llama 3 模型。Meta Llama 3 专为您构建、实验和负责任地扩展生成式人工智能(AI)应用程序而设计。新的 Llama 3 模型在推理、代码生成和指令方面进行了改进,因此能够支持更广泛的用例。

根据 Meta 的 Llama 3 公告,Llama 3 模型系列是一组参数大小为 8B 和 70B 的预训练和指令调整的大型语言模型(LLM)。这些模型已经在超过15 万亿个数据令牌上进行了训练,该训练数据集是 Llama 2 模型所用数据集的七倍(其中,代码数量是后者的四倍多),它支持 8K 上下文长度,容量较 Llama 2 翻了一番。

您现在可以在 Amazon Bedrock 中使用两种新的 Llama 3 模型,这进一步增加了 Amazon Bedrock 中的模型选择。这些模型使您能够针对您的用例轻松试验和评估更多顶级基础模型(FM):

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

Meta 目前还在训练其他大小超过 400B 参数的 Llama 3 模型。这些 400B 模型将具有新功能,包括多模态、多语言支持和更长的上下文窗口。这些模型发布后,将成为内容创作、对话式人工智能、语言理解、研发(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 InstructLlama 3 70B Instruct 作为模型。

您还可以选择查看 API 请求,使用 AWS 命令行界面(AWS CLI)和 AWS SDK 中的代码示例访问模型。您可以使用模型 ID,如 meta.llama3-8b-instruct-v1meta.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

您可以使用 AWS SDK,通过 Amazon Bedrock 的代码示例以各种编程语言构建应用程序。以下 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 模型用于各种任务,例如问答、语言翻译、情感分析等。以下是带有少量情境学习的 Llama 3 模型的示例,我们在其中为模型提供了可用的训练样本。

输入:Translate English to French:
sea otter => loutre de mer
peppermint => menthe poivrée
plush girafe => girafe peluche
cheese =>
输出: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 指令模型。指令模型端点的输入是聊天助手和用户之间的先前历史记录。因此,您可以提出与迄今为止发生的对话相关的问题,并提供系统配置,例如角色,它按以下格式定义聊天助手的行为:

<|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|>

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

输入:<|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
输出: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 的新提示模板和特殊标记的更多信息,请查看 Meta 的模型卡和提示格式或 GitHub 存储库中的 Llama 配方

现已推出
美国东部(弗吉尼亚州北部)和美国西部(俄勒冈州)区域目前已在 Amazon Bedrock 中提供 Meta 的 Llama 3 模型。查看完整区域列表以了解将来的更新。要了解更多信息,请查看 Amazon Bedrock 中的 Llama 产品页面定价页面

立即在 Amazon Bedrock 控制台中试用 Llama 3,并将反馈发送至 AWS re:Post for Amazon Bedrock 或通过您常用的 AWS Support 联系方式发送。

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

Channy