链载Ai

标题: 使用 Meta 系列模型构建 [打印本页]

作者: 链载Ai    时间: 3 小时前
标题: 使用 Meta 系列模型构建

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">简介


ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">本课程将涵盖:

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;list-style: circle;">•探索两个主要的 Meta 系列模型 - Llama 3.1 和 Llama 3.2•了解每个模型的使用案例和场景•代码示例,展示每个模型的独特功能

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">Meta 系列模型


ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">在本课程中,我们将探索 Meta 系列或“Llama 群”中的两个模型 - Llama 3.1 和 Llama 3.2。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">这些模型有不同的变体,并且可以在 GitHub 模型市场上找到。以下是有关使用 GitHub 模型进行 AI 模型原型设计的更多详细信息。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">模型变体:

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;list-style: circle;">•Llama 3.1 - 70B Instruct•Llama 3.1 - 405B Instruct•Llama 3.2 - 11B Vision Instruct•Llama 3.2 - 90B Vision Instruct

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;">注意:Llama 3 也可在 GitHub 模型上找到,但本课程不涉及。

Llama 3.1


Llama 3.1 拥有 4050 亿个参数,属于开源 LLM 类别。

该模式是对早期发布的 Llama 3 的升级,提供了:

•更大的上下文窗口 - 128k 个 tokens vs 8k 个 tokens•更大的最大输出 Tokens - 4096 vs 2048•更好的多语言支持 - 由于训练 tokens 的增加

这些使 Llama 3.1 能够在构建 GenAI 应用程序时处理更复杂的用例,包括:

•本地函数调用 - 调用 LLM 工作流程之外的外部工具和函数的能力•更好的 RAG 性能 - 由于更高的上下文窗口•合成数据生成 - 创建有效数据以用于微调等任务的能力

本地函数调用

Llama 3.1 经过微调,可以更有效地进行函数或工具调用。它还具有两个内置工具,模型可以根据用户的提示识别出需要使用这些工具。这些工具是:

Brave Search- 可以通过执行网络搜索来获取最新信息,例如天气•Wolfram Alpha- 可用于更复杂的数学计算,因此不需要编写自己的函数。

你还可以创建自己的 LLM 可以调用的自定义工具。

在下面的代码示例中:

•我们在系统提示中定义了可用的工具 (brave_search, wolfram_alpha)。•发送一个询问特定城市天气情况的用户提示。•LLM 将回复一个对 Brave Search 工具的工具调用,如下所示

<|python_tag|>brave_search.call(query="Stockholm weather")

注意:此示例仅进行工具调用,如果想获得结果,您需要在 Brave API 页面上创建一个免费帐户并定义函数本身。

import osfrom azure.ai.inference import ChatCompletionsClientfrom azure.ai.inference.models import AssistantMessage, SystemMessage, UserMessagefrom azure.core.credentials import AzureKeyCredential
token = os.environ["GITHUB_TOKEN"]endpoint ="https://models.inference.ai.azure.com"model_name ="meta-llama-3.1-405b-instruct"
client = ChatCompletionsClient( endpoint=endpoint, credential=AzureKeyCredential(token),)

tool_prompt=f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Environment: ipythonTools: brave_search, wolfram_alphaCutting Knowledge Date: December 2023Today Date: 23 July 2024
You are a helpful assistant<|eot_id|>"""
messages = [ SystemMessage(content=tool_prompt), UserMessage(content="What is the weather in Stockholm?"),
]
response = client.complete(messages=messages, model=model_name)
print(response.choices[0].message.content)

Llama 3.2


尽管 Llama 3.1 是一个 LLM,但它的一个限制是多模态。也就是说,能够使用不同类型的输入,例如图像作为提示并提供响应。这种能力是 Llama 3.2 的主要功能之一。这些功能还包括:

•多模态 - 能够评估文本和图像提示•中小型变体(11B 和 90B) - 这提供了灵活的部署选项•纯文本变体(1B 和 3B) - 这允许模型部署在边缘/移动设备上,并提供低延迟

多模态支持代表了开源模型领域的一大步。下面的代码示例同时采用图像和文本提示,以从 Llama 3.2 90B 获得图像分析。

Llama 3.2 的多模态支持

importosfromazure.ai.inferenceimportChatCompletionsClientfromazure.ai.inference.modelsimport(  SystemMessage,  UserMessage,  TextContentItem,  ImageContentItem,  ImageUrl,  ImageDetailLevel,)fromazure.core.credentialsimportAzureKeyCredential
token = os.environ["GITHUB_TOKEN"]endpoint ="https://models.inference.ai.azure.com"model_name ="Llama-3.2-90B-Vision-Instruct"
client = ChatCompletionsClient( endpoint=endpoint, credential=AzureKeyCredential(token),)
response = client.complete( messages=[ SystemMessage( content="You are a helpful assistant that describes images in details." ), UserMessage( content=[ TextContentItem(text="What's in this image?"), ImageContentItem( image_url=ImageUrl.load( image_file="sample.jpg", image_format="jpg", detail=ImageDetailLevel.LOW) ), ], ), ], model=model_name,)
print(response.choices[0].message.content)

学习永不止步,继续旅程






欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5