在 Amazon Bedrock 上使用 Meta Llama 3 模型

Amazon Bedrock
0
0
![1.webp.jpg](https://dev-media.amazoncloud.cn/a577b2e1bc084ade9407535a9098eaad_1.webp.jpg "1.webp.jpg") Meta 的 Llama 3 模型已在 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 中正式可用。Meta Llama 3 旨在让您能够构建、试验和负责任地扩展您的生成式 AI 应用程序。新的 Llama 3 模型能够支持各种广泛用例,在推理、代码生成和指令方面均有改进。 根据 Meta 关于 Llama 3 的公告,Llama 3 模型家族是一组预训练和指令调优的大型语言模型(LLMs),参数量为 8B 和 70B。这些模型都接受了超过 15 万亿个标记数据的训练,相比 Llama 2 模型使用的训练数据集大七倍,其中包含四倍于 Llama 2 的代码数据,支持 8K 的上下文长度,是 Llama 2 的两倍。 现在您可以在 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 中使用两种新的 Llama 3 模型,进一步增加了 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 中的模型选择。这些模型使您能够轻松尝试和评估更多顶级基础模型(FMs),以满足您的使用案例: * **Llama 3 8B** 非常适合有限的计算能力和资源以及边缘设备。该模型擅长文本摘要、文本分类、情感分析和语言翻译。 * **Llama 3 70B** 非常适合内容创作、对话式 AI、语言理解、研发和企业应用。该模型擅长文本摘要和准确性、文本分类和细微差别、情感分析和细微推理、语言建模、对话系统、代码生成和遵循指令。 此外,Meta 目前正在训练参数超过 400B 的其他 Llama 3 模型。这些 400B 模型将具有新的能力,包括多模态、多语言支持和更长的上下文窗口。一旦发布,这些模型将非常适合内容创作、对话式 AI、语言理解、研发和企业应用。 ### **Llama 3 模型实践** 如果您是第一次使用 Meta 模型,请访问 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 控制台,并在左下方窗格中选择**模型访问**: https\://console.aws.amazon.com/bedrock/?trk=cndc-detail 要访问 Meta 最新的 Llama 3 模型,请分别请求访问 **Llama 3 8B Instruct** 或 **Llama 3 70B Instruct**。 ![2.webp.jpg](https://dev-media.amazoncloud.cn/fb6e232f177f483eb677b5977f98b213_2.webp.jpg "2.webp.jpg") 要在 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 控制台中测试 Meta Llama 3 模型,请在左侧菜单窗格中选择**游乐场下的文本**或**聊天**。然后选择**选择模型**,并将类别设置为 **Meta**,将模型设置为 **Llama 8B Instruct** 或 **Llama 3 70B Instruct**。 ![3.webp.jpg](https://dev-media.amazoncloud.cn/b79794e61a044553b3e3c88e3be6dabd_3.webp.jpg "3.webp.jpg") 通过选择**查看 API 请求**,您还可以使用亚马逊云科技命令行界面(Amazon CLI)和 Amazon SDK 中的代码示例来访问该模型。您可以使用诸如 meta.llama3-8b-instruct-v1 或 meta.llama3-70b-instruct-v1 这样的模型 ID。 这是一个 Amazon CLI 命令样本: **Bash** ``` \$ amazon 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](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 的代码示例: https\://docs.aws.amazon.com/bedrock/latest/userguide/service_code_examples.html?trk=cndc-detail 利用 Amazon SDK 用各种编程语言构建您的应用程序。下面的 Python 代码示例展示了如何在 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 中调用 Llama 3 Chat 模型进行文本生成。 **Python** ``` 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 模型进行小批量上下文学习的示例,我们向模型提供了可用的训练样本。 **Markup** ``` 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 指令模型。指令模型端点的输入是助手和用户之前的对话历史。因此,您可以提问与已发生的对话相关的上下文性问题,并提供定义聊天助手行为的系统配置,如个性化等,格式如下: **Markup** ``` <|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|> ``` 在以下示例中,用户与助手以巴黎的旅游景点为话题进行了对话。然后,用户询问了助手推荐的第一个选项。 ![4.webp.jpg](https://dev-media.amazoncloud.cn/cafd273e271142bcb82ec709b79b5ec5_4.webp.jpg "4.webp.jpg") **Markup** ``` 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 新的提示模板和特殊标记的更多信息,请查看 Meta 的模型卡和提示格式: https\://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3?trk=cndc-detail 或 GitHub 存储库中的 Llama Recipes(配套资源): https\://github.com/meta-llama/llama-recipes?trk=cndc-detail ### **现已推出** Meta 的 Llama 3 模型已在美国东部(弗吉尼亚北部)和美国西部(俄勒冈州)地区的 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 上推出。请查看完整地区列表以获取未来更新: https\://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3?trk=cndc-detail 欲了解更多信息,请查看 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 中的 Llama 产品页面和定价页面: https\://github.com/meta-llama/llama-recipes?trk=cndc-detail 现在就在 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 控制台上试用 Llama 3,并通过亚马逊云科技 re:Post for [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail) 或您的常用亚马逊云科技支持渠道反馈意见: https\://repost.aws/tags/TAQeKlaPaNRQ2tWB6P7KrMag/amazon-bedrock?trk=cndc-detail 您还可以访问亚马逊云科技的社区,找到深入的技术内容,了解我们的开发者如何在他们的解决方案中使用 [Amazon Bedrock](https://aws.amazon.com/cn/bedrock/?trk=cndc-detail): https\://community.aws/generative-ai?trk=e8665609-785f-4bbe-86e8-750a3d3e9e61\&sc_channel=el?trk=cndc-detail **点击阅读原文查看博客,获得更详细内容**! [![df08bd101cedf028fb6730ca2db8167.png](https://dev-media.amazoncloud.cn/3b618e93e0ee4d66a1927ddbd94385ba_df08bd101cedf028fb6730ca2db8167.png "df08bd101cedf028fb6730ca2db8167.png")](https://summit.amazoncloud.cn/2024/register.html?source=DSJAVfG2GS7gEk2Osm6kYXAa+8HnSEVdbCVjkuit7lE= )
0
目录
关闭