跳到正文
Hugging Face Blog·· 2024-07-23精选AI 评分88

Meta 发布 Llama 3.1:8B、70B 与 405B,支持多语言和长上下文

Llama 3.1 - 405B, 70B & 8B with multilinguality and long context

AI 导读

Meta 发布 Llama 3.1 系列开源模型,包含 8B、70B、405B 三种规模,各有基础版和指令微调版,上下文长度从 8K 提升到 128K token,支持英语、德语、法语、意大利语、葡萄牙语、印地语、西班牙语和泰语 8 种语言。

推荐理由

Meta 发布 Llama 3.1 三档开源模型,128K 上下文与工具调用能力配合更宽松的许可证,读者可据此判断开源模型在合成数据与蒸馏上的可用边界。

正文 · AI 翻译

Llama 3.1 发布了!今天,我们欢迎 Llama 家族的下一个迭代版本加入 Hugging Face。我们很高兴能与 Meta 合作,确保在 Hugging Face 生态系统中实现最佳集成。Hub 上提供了八个开放权重模型(3 个基础模型和 5 个微调模型)。

Llama 3.1 有三种规模:8B 适用于在消费级 GPU 上进行高效部署和开发,70B 适用于大规模 AI 原生应用,405B 适用于合成数据、LLM as a Judge 或蒸馏。这三种规模都提供基础版和指令微调版。

除了这六个生成模型外,Meta 还发布了两款新模型:Llama Guard 3 和 Prompt Guard。Prompt Guard 是一个小型分类器,用于检测提示注入和越狱。Llama Guard 3 是一个保障模型,可以对 LLM 的输入和生成内容进行分类。

在发布的功能和集成中,我们包括:

  • Hub 上的模型
  • Hugging Face Transformers 和 TGI 集成
  • 针对 Meta Llama 3.1 405B Instruct 的 Hugging Chat 集成
  • 与 Inference Endpoints、Google Cloud、Amazon SageMaker 和 DELL Enterprise Hub 的推理与部署集成
  • 针对 FP8、AWQ 和 GPTQ 的量化,以便更轻松地进行推理
  • 使用 🤗 TRL 在单 GPU 上微调 Llama 3.1 8B
  • 使用 Distilabel 和 Llama 3.1 70B 及 405B 生成合成数据

目录

Llama 3.1 有什么新特性?

为什么 Llama 3.1 如此令人兴奋?除了前代产品提供的功能外,Llama 3.1 还有一些关键的新特性:

  • 128K tokens 的大上下文长度(相比原来的 8K)
  • 多语言能力
  • 工具使用能力
  • 一个非常大的 4050 亿参数的密集模型
  • 更宽松的许可证

让我们深入了解一下!

Llama 3.1 的发布引入了六个基于 Llama 3 架构的新开放 LLM 模型。它们有三种规模:8B、70B 和 405B 参数,每种都有基础(预训练)版和指令微调版。所有变体都支持128K tokens 的上下文长度和 8 种语言,包括英语、德语、法语、意大利语、葡萄牙语、印地语、西班牙语和泰语。Llama 3.1 继续使用分组查询注意力(GQA),这是一种高效的表示方法,应有助于处理更长的上下文。

除了这 6 个语言模型外,还发布了 Llama Guard 3 和 Prompt Guard。

  • Llama Guard 3 是 Llama Guard 系列的最新版本,基于 Llama 3.1 8B 微调。它专为生产用例构建,具有 128k 上下文长度和多语言能力。Llama Guard 3 可以对 LLM 输入(提示)和响应进行分类,以检测在风险分类中被认为不安全的内容。
  • Prompt Guard 则是一个小型 279M 参数的基于 BERT 的分类器,可以检测提示注入和越狱。它是在大量攻击语料库上训练的,建议使用特定应用的数据进一步微调。

与 Llama 3 相比,Llama 3.1 的新功能是 instruct 模型针对代理用例的工具调用进行了微调。有两个内置工具(搜索、使用 Wolfram Alpha 的数学推理),可以通过自定义 JSON 函数进行扩展。

Llama 3.1 模型在定制构建的 GPU 集群上使用超过 15 万亿个 token 进行训练,总共使用了 3930 万 GPU 小时(8B 为 146 万,70B 为 700 万,405B 为 3084 万)。我们不知道训练数据集混合的确切细节,只能猜测它有多样化的多语言策展。Llama 3.1 Instruct 针对指令遵循进行了优化,并在公开可用的指令数据集以及超过 2500 万个合成生成的示例上进行了监督微调(SFT)和基于人类反馈的强化学习(RLHF)。Meta 开发了基于 LLM 的分类器,在创建数据混合期间过滤和策展高质量的提示和响应。

关于许可条款,Llama 3.1 的许可与之前非常相似,但有一个关键区别:它允许使用模型输出来改进其他 LLM。这意味着允许合成数据生成和蒸馏,甚至可以使用不同的模型!这对 405B 模型尤为重要,稍后将讨论。该许可允许再分发、微调和创建衍生作品,并且仍然要求衍生模型在其名称开头包含“Llama”,任何衍生作品或服务必须提及“Built with Llama”。有关完整详细信息,请务必阅读官方许可。

Llama 3.1 需要多少内存?

Llama 3.1 带来了令人兴奋的进步。然而,运行它需要仔细考虑您的硬件资源。我们分解了三种模型尺寸的训练和推理内存需求。

推理内存需求

对于推理,内存需求取决于模型大小和权重精度。以下是显示不同配置所需大致内存的表格:

模型大小 FP16 FP8 INT4
8B 16 GB 8 GB 4 GB
70B 140 GB 70 GB 35 GB
405B 810 GB 405 GB 203 GB

注意:上述数字表示仅加载模型检查点所需的 GPU VRAM。它们不包括内核或 CUDA 图的 torch 保留空间。

例如,一个 H100 节点(8x H100)有约 640GB 的 VRAM,因此 405B 模型需要在多节点设置中运行或以较低精度(例如 FP8)运行,这将是推荐的方法。

请记住,较低的精度(例如 INT4)可能会导致一些精度损失,但可以显著减少内存需求并提高推理速度。除了模型权重之外,你还需要将 KV Cache 保留在内存中。它包含模型上下文中所有 token 的键和值,这样在生成新 token 时就不需要重新计算它们。特别是在利用可用的长上下文长度时,它会成为一个重要因素。在 FP16 下,KV cache 的内存需求为:

模型大小 1k tokens 16k tokens 128k tokens
8B 0.125 GB 1.95 GB 15.62 GB
70B 0.313 GB 4.88 GB 39.06 GB
405B 0.984 GB 15.38 123.05 GB

特别是对于小模型,当接近上下文长度最大值时,缓存使用的内存与权重一样多。

训练内存需求

下表概述了使用不同技术训练 Llama 3.1 模型时的大致内存需求:

模型大小 全量微调 LoRA Q-LoRA
8B 60 GB 16 GB 6 GB
70B 500 GB 160 GB 48 GB
405B 3.25 TB 950 GB 250 GB

注意:这些是估算值,可能会因具体实现细节和优化而有所不同。

Llama 3.1 评估

注意:我们目前正在新的 Open LLM Leaderboard 2 上单独评估 Llama 3.1,并将在今天晚些时候更新本节内容。以下是 Meta 官方评估的摘录。

类别 基准 # Shots 指标 Llama 3 8B Llama 3.1 8B Llama 3 70B Llama 3.1 70B Llama 3.1 405B
通用 MMLU 5 macro_avg/acc_char 66.7 66.7 79.5 79.3 85.2
MMLU PRO (CoT) 5 macro_avg/acc_char 36.2 37.1 55.0 53.8 61.6
AGIEval English 3-5 average/acc_char 47.1 47.8 63.0 64.6 71.6
CommonSenseQA 7 acc_char 72.6 75.0 83.8 84.1 85.8
Winogrande 5 acc_char - 60.5 - 83.3 86.7
BIG-Bench Hard (CoT) 3 average/em 61.1 64.2 81.3 81.6 85.9
ARC-Challenge 25 acc_char 79.4 79.7 93.1 92.9 96.1
知识推理 TriviaQA-Wiki 5 em 78.5 77.6 89.7 89.8 91.8
SQuAD 1 em 76.4 77.0 85.6 81.8 89.3
阅读理解 QuAC (F1) 1 f1 44.4 44.9 51.1 51.1 53.6
BoolQ 0 acc_char 75.7 75.0 79.0 79.4 80.0
DROP (F1) 3 f1 58.4 59.5 79.7 79.6 84.8

使用 Hugging Face Transformers

Llama 3.1 需要进行小幅建模更新,以有效处理 RoPE 缩放。使用 Transformers 4.43.2 版本,你可以使用新的 Llama 3.1 模型,并利用 Hugging Face 生态系统中的所有工具。请确保使用最新的 transformers 版本:

pip install "transformers>=4.43.2" --upgrade

几个细节:

  • Transformers 默认以 bfloat16 加载模型。这是 Meta 发布的原始 checkpoint 所使用的类型,因此建议以此方式运行,以确保最佳精度或进行评估。
  • 助手回复可能会以特殊 token <|eot_id|> 结尾,但如果发现常规 EOS token,我们也必须停止生成。我们可以通过在 eos_token_id 参数中提供终止符列表来提前停止生成。
  • 我们使用了原始 meta 代码库中的默认采样参数(temperature 和 top_p)。我们还没有时间进行广泛的测试,欢迎自行探索!

以下代码片段展示了如何使用 meta-llama/Meta-Llama-3.1-8B-Instruct。它需要约 16 GB 的显存,适合许多消费级 GPU。同样的代码片段也适用于 meta-llama/Meta-Llama-3.1-70B-Instruct,后者需要 140GB 显存,以及 meta-llama/Meta-Llama-3.1-405B-Instruct(需要 810GB 显存),使其成为生产用例中非常有趣的模型。通过以 8 位或 4 位模式加载,可以进一步降低内存消耗。

from transformers import pipeline
import torch

model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
pipe = pipeline(
    "text-generation",
    model=model_id,
    model_kwargs={"torch_dtype": torch.bfloat16},
    device="cuda",
)

messages = [
    {"role": "user", "content": "Who are you? Please, answer in pirate-speak."},
]
outputs = pipe(
    messages,
    max_new_tokens=256,
    do_sample=False,
)
assistant_response = outputs[0]["generated_text"][-1]["content"]
print(assistant_response)
# Arrrr, me hearty! Yer lookin' fer a bit o' information about meself, eh? Alright then, matey! I be a language-generatin' swashbuckler, a digital buccaneer with a penchant fer spinnin' words into gold doubloons o' knowledge! Me name be... (dramatic pause)...Assistant! Aye, that be me name, and I be here to help ye navigate the seven seas o' questions and find the hidden treasure o' answers! So hoist the sails and set course fer adventure, me hearty! What be yer first question?

你还可以使用 bitsandbytes 自动量化模型,以 8 位甚至 4 位模式加载。大型 70B 版本的 4 位加载运行大约需要 34 GB 内存。以下是以 4 位加载生成管道的方法:

pipeline = pipeline(
    "text-generation",
    model=model_id,
    model_kwargs={
        "torch_dtype": torch.bfloat16,
        "quantization_config": {"load_in_4bit": True}
    },
)

有关使用 transformers 的模型的更多详细信息,请查看模型卡片。

注意:Transformers 会处理所有烦人的提示模板问题以及更多内容,如果你想了解更多关于提示的信息,请查看下一节。

如何提示 Llama 3.1

基础模型没有提示格式。与其他基础模型一样,它们可用于以合理的延续来续写输入序列,或用于零样本/少样本推理。它们也是为你自己的用例进行微调的绝佳基础。

Instruct 版本支持具有 4 种角色的对话格式:

  1. system:设置对话的上下文。它允许包含有助于有效响应的规则、指南或必要信息。它还在适当时用于启用工具使用。
  2. user:用户对模型的输入、命令和问题。
  3. assistant:助手基于“system”和“user”提示中提供的上下文做出的响应。
  4. ipython:Llama 3.1 中引入的新角色。当工具调用的输出被发送回 LLM 时,此角色用作该输出。

Instruct 版本对简单对话使用以下对话结构:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

{{ system_prompt }}<|eot_id|><|start_header_id|>user<|end_header_id|>

{{ user_msg_1 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{{ model_answer_1 }}<|eot_id|>

Llama 3.1 Instruct 模型现在支持工具调用,包括三个内置工具(brave_search、wolfram_alpha 和 code_interpreter)以及通过 JSON 函数调用进行的自定义工具调用。内置工具使用 Python 语法。输出用于函数调用的 Python 代码的能力是代码解释器工具的一部分,必须在系统提示中使用 Environment 关键字启用,如下所示。

内置工具调用

包含“Environment: ipython”会开启代码解释器模式,模型可以生成它期望被执行的 Python 代码。助手响应的消息正文以特殊标记 <|python_tag|> 开头,并以 <|eom_id|> 结束,而不是仅使用标准的 <|eot_id|>。后者表示该轮对话已结束,而前者表示继续进行多步推理。

内置工具调用示例

<|begin_of_text|><|start_header_id|>system<|end_header_id|>


Environment: ipython
Tools: brave_search, wolfram_alpha

Cutting Knowledge Date: 01 March 2023
Today's Date: 13 July 2024


You are a helpful Assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>

Weather in Menlo Park, California<|eot_id|><|start_header_id|>assistant<|end_header_id|>

此时模型的响应将包含用于调用某个受支持工具(本例中为 brave_search)的 Python 代码:

<|python_tag|>brave_search.call(query="current weather in Menlo Park, California")<|eom_id|>

然后,执行该调用后的响应会被发送回模型,以获取最终响应。为简洁起见,以下内容将追加到上一代码片段中显示的消息之后:

<|python_tag|>brave_search.call(query="Menlo Park California weather")<|eom_id|><|start_header_id|>ipython<|end_header_id|>

{"query": "Menlo Park California weather", "top_k": [{"title": "10-Day Weather Forecast for West Menlo Park, CA - The Weather Channel | weather.com", "url": "https://weather.com/weather/tenday/l/West+Menlo+Park+CA?canonicalCityId=b2375713aa1943aad7d1a13a85e1c0adad13c1b10563b2bbaad70734dc61cf11", "description": "Be prepared with the most accurate 10-day forecast for West <strong>Menlo</strong> <strong>Park</strong>, CA with highs, lows, chance of precipitation from The <strong>Weather</strong> Channel and <strong>Weather</strong>.com", "type": "search_result"},....}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

LLM 的最终响应将是:

The current weather in Menlo Park, California is mostly sunny with a high of 77°F and a low of 56°F.<|eot_id|>

自定义工具调用

Llama 3.1 Instruct 支持从单个用户消息中进行自定义函数调用。以下提示提供了如何从模型输出中调用自定义函数的示例。在自定义函数调用中,模型输出 <|eot_id|> 而不是 <|eom_id|>。需要调整系统提示以告知模型如何处理函数调用输出。

自定义工具调用 JSON 函数

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the orginal user question.<|eot_id|><|start_header_id|>user<|end_header_id|>

Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.

Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.

{
    "type": "function",
    "function": {
    "name": "get_current_conditions",
    "description": "Get the current weather conditions for a specific location",
    "parameters": {
        "type": "object",
        "properties": {
        "location": {
            "type": "string",
            "description": "The city and state, e.g., San Francisco, CA"
        },
        "unit": {
            "type": "string",
            "enum": ["Celsius", "Fahrenheit"],
            "description": "The temperature unit to use. Infer this from the user's location."
        }
        },
        "required": ["location", "unit"]
    }
    }
}

Question: what is the weather like in Menlo Park?<|eot_id|><|start_header_id|>assitant<|end_header_id|>

{"name": "get_current_conditions", "parameters": {"location": "Menlo Park, CA", "unit": "Fahrenheit"}}<|eot_id|><|start_header_id|>ipython<|end_header_id|>

当我们从所选工具检索输出时,我们使用相同的 <|python_tag|> 分隔符将其传递回模型。<|python_tag|> 并不意味着使用 Python。它仅用于表示任何工具输出的开始。

<|python_tag|>{
    "tool_call_id": "get_current_conditions"
    "output": "Clouds giving way to sun Hi: 76° Tonight: Mainly clear early, then areas of low clouds forming Lo: 56°"
}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

The weather in Menlo Park is currently cloudy with a high of 76° and a low of 56°, with clear skies expected tonight.<|eot_id|>

为了有效使用,必须精确重现此格式。transformers 中提供的聊天模板使得正确格式化提示变得简单。

演示

您可以在以下演示中试用三个 Instruct 模型:

整个技术栈都是开源的。Hugging Chat 由 chat-ui 和 text-generation-inference 提供支持。

Llama 3.1 405B 使用 FP8、AWQ 和 GPTQ 的量化

Meta 创建了 Llama 3.1 405B 的官方 FP8 量化版本,精度下降极小。为实现这一点,FP8 量化仅应用于模型的主要线性算子,例如 FFN 的 gate 和 up 以及 down 投影(覆盖了 75% 的推理 FLOPs)。我们共同努力确保此 FP8 量化检查点在社区(transformers、TGI、VLLM)中兼容。

此外,我们分别使用 AutoAWQ 和 AutoGPTQ 创建了 INT4 的 AWQ 和 GPTQ 量化变体。对于 AWQ,所有线性层都使用 GEMM 内核进行量化,执行零点量化降至 4 位,组大小为 128;对于 GPTQ,使用相同的设置,只是改用 GPTQ 内核。我们确保 INT4 检查点与 transformers 和 TGI 兼容,包括 Marlin 内核支持,以加速 TGI 中 GPTQ 量化的推理。

Llama 3.1 405B 可用的量化权重:

Hugging Quants 组织 还包含 70B 和 8B 版本的量化检查点。

推理集成

Hugging Face 推理 API

Hugging Face PRO 用户现在可以访问专属 API 端点,这些端点托管了由 text-generation-inference 驱动的 Llama 3.1 8B Instruct、Llama 3.1 70B Instruct 和 Llama 3.1 405B Instruct AWQ。所有版本均支持 Messages API,因此与 OpenAI 客户端库兼容,包括 LangChain 和 LlamaIndex。

注意:请使用 pip install "huggingface_hub>=0.24.1 更新到最新的 huggingface_hub 版本。


from huggingface_hub import InferenceClient

# Initialize the client, pointing it to one of the available models
client = InferenceClient()

chat_completion = client.chat.completions.create(
    model="meta-llama/Meta-Llama-3.1-405B-Instruct-FP8",
    messages=[
        {"role": "system", "content": "You are a helpful an honest programming assistant."},
        {"role": "user", "content": "Is Rust better than Python?"},
    ],
    stream=True,
    max_tokens=500
)

# iterate and print stream
for message in chat_completion:
    print(message.choices[0].delta.content, end="")

有关 Messages API 使用的更多详细信息,请查看此文章。

Hugging Face Inference Endpoints

你可以在 Hugging Face 的 Inference Endpoints 上部署 Llama 3.1,其后端使用 Text Generation Inference。Text Generation Inference 是 Hugging Face 开发的生产级推理容器,支持 FP8、连续批处理、令牌流式传输、张量并行,可在多个 GPU 上实现快速推理。要部署 Llama 3.1,请前往模型页面并点击 Deploy -> Inference Endpoints 组件:

from huggingface_hub import InferenceClient

# Initialize the client, pointing it to one of the available models
client = InferenceClient(
    base_url="<ENDPOINT_URL>",
)

# Create a chat completion
chat_completion = client.chat.completions.create(
    model="ENDPOINT",
    messages=[
        {"role": "system", "content": "You are a helpful an honest programming assistant."},
        {"role": "user", "content": "Is Rust better than Python?"},
    ],
    stream=True,
    max_tokens=500
)

# iterate and print stream
for message in chat_completion:
    print(message.choices[0].delta.content, end="")

Hugging Face 合作伙伴集成

注意:我们目前正在与 AWS、Google Cloud、Microsoft Azure 和 DELL 的合作伙伴合作,将 Llama 3.1 8B、70B 和 405B 添加到 Amazon SageMaker、Google Kubernetes Engine、Vertex AI Model Catalog、Azure AI Studio、DELL Enterprise Hub。一旦容器可用,我们将更新此部分——你可以订阅 Hugging Squad 以获取电子邮件更新。

使用 Hugging Face TRL 进行微调

在本节中,我们将介绍 Hugging Face 生态系统中可用的工具,以便在消费级 GPU 上高效训练 Llama 3.1。下面是一个在 OpenAssistant 的聊天数据集上微调 Llama 3.1 8B 的示例命令。我们使用 4 位量化和 QLoRA 来节省内存,以针对所有注意力块的线性层。

使用 Hugging Face TRL 的微调示例

首先,安装 🤗 TRL 的 nightly 版本并克隆仓库以获取训练脚本:

pip install "transformers>=4.43.2" --upgrade
pip install --upgrade bitsandbytes
pip install --ugprade peft
pip install git+https://github.com/huggingface/trl
git clone https://github.com/huggingface/trl
cd trl

然后你可以运行脚本:

python \
    trl/scripts/sft.py \
    --model_name meta-llama/Meta-Llama-3.1-8B \
    --dataset_name OpenAssistant/oasst_top1_2023-08-25 \
    --dataset_text_field="text" \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 1 \
    --gradient_accumulation_steps 4 \
    --learning_rate 2e-4 \
    --report_to "none" \
    --bf16 \
    --max_seq_length 1024 \
    --lora_r 16 --lora_alpha 32 \
    --lora_target_modules q_proj k_proj v_proj o_proj \
    --load_in_4bit \
    --use_peft \
    --attn_implementation "flash_attention_2" \
    --logging_steps=10 \
    --gradient_checkpointing \
    --output_dir llama31

如果你有更多 GPU 可用,可以使用 DeepSpeed 和 ZeRO Stage 3 运行训练:

accelerate launch --config_file=examples/accelerate_configs/deepspeed_zero3.yaml \
    trl/scripts/sft.py \
    --model_name meta-llama/Meta-Llama-3.1-8B \
    --dataset_name OpenAssistant/oasst_top1_2023-08-25 \
    --dataset_text_field="text" \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 1 \
    --gradient_accumulation_steps 4 \
    --learning_rate 2e-5 \
    --report_to wandb \
    --bf16 \
    --max_seq_length 1024 \
    --attn_implementation eager \
    --logging_steps=10 \
    --gradient_checkpointing \
    --output_dir models/llama

使用 distilabel 生成合成数据

Llama 3.1 许可证的一个重大变化是允许使用模型输出来改进其他 LLM,这意味着你可以使用 Llama 3.1 模型生成合成数据集,并用它们来微调更小、更专业的模型。

让我们看一个使用 distilabel 生成偏好数据集的示例,distilabel 是一个用于合成数据生成的开源框架。该数据集可用于使用 TRL 提供的偏好优化方法(如 DPO 或 KTO)微调模型。

首先安装最新的 distilabel 版本,包括 hf-inference-endpoints 额外组件,使用 pip 如下:

pip install “distilabel[hf-inference-endpoints]” --upgrade

然后定义一个流水线,它:

  • 从 Hugging Face Hub 加载包含指令的数据集。
  • 通过 Hugging Face Inference Endpoints 使用 Llama 3.1 70B Instruct 和 Llama 3.1 405B Instruct 生成响应。
  • 最后,使用 Llama 3.1 405B Instruct 作为评判者,利用 UltraFeedback 提示对回复进行评分。根据这些评分,可以选出被选中和被拒绝的回复,并使用偏好优化方法对模型进行微调。

请参阅下面的代码来定义流水线,或使用此 Colab notebook 自行运行,并在 Hub 中探索生成的数据集。

from distilabel.llms import InferenceEndpointsLLM
from distilabel.pipeline import Pipeline
from distilabel.steps import LoadDataFromHub, CombineColumns
from distilabel.steps.tasks import TextGeneration, UltraFeedback

llama70B = InferenceEndpointsLLM(
    model_id="meta-llama/Meta-Llama-3.1-70B-Instruct"
)
llama405B = InferenceEndpointsLLM(
    model_id="meta-llama/Meta-Llama-3.1-405B-Instruct-FP8"
)

with Pipeline(name="synthetic-data-with-llama3") as pipeline:
    # load dataset with prompts
    load_dataset = LoadDataFromHub(
        repo_id="argilla/10Kprompts-mini"
    )
    # generate two responses for each prompt
    generate = [
        TextGeneration(llm=llama70B),
        TextGeneration(llm=llama405B)
    ]
    # combine responses into one column
    combine = CombineColumns(
        columns=["generation", "model_name"],
        output_columns=["generations", "model_names"]
    )
    # rate responses with 405B LLM-as-a-judge
    rate = UltraFeedback(aspect="overall-rating", llm=llama405B)
    # define the pipeline
    load_dataset >> generate >> combine >> rate

if __name__ == "__main__":
    distiset = pipeline.run()

接下来是什么?除了上面的示例,distilabel 还提供了在各种场景和主题中使用 LLM 进行合成数据生成的令人兴奋的方法。它包括当前 SOTA 文献中针对诸如使用 LLM-as-a-judge 方法评估输出、演化指令、数据过滤以及定义自定义组件等任务的实现。

其他资源

致谢

在生态系统中发布此类模型并提供支持和评估,离不开数千名社区成员的贡献,他们为 transformers、tgi、vllm、pytorch、LM Eval Harness 以及许多其他项目做出了贡献。此次发布离不开以下人员的支持:Clémentine 和 Nathan 负责 LLM 评估;Nicolas、Olivier Dehaene 和 Daniël de Kok 提供文本生成推理支持;Arthur、Matthew Carrigan、Zachary Mueller、Joao、Joshua Lochner 和 Lysandre 将 Llama 3.1 集成到 transformers 中;Matthew Douglas 提供量化支持;Gabriel Martín Blázquez 提供 distilabel 支持;Merve Noyan 和 Aymeric Roucher 进行审阅;hysts 和 Yuvi 制作演示;Ellie 测试微调;Brigitte Tousignant 和 Florent Daudens 负责沟通;Nathan 和 Victor 在 Hugging Chat 中提供 Llama 3.1。

感谢 Meta 团队发布 Llama 3.1 并将其提供给开源 AI 社区!

来源:Hugging Face Blog · huggingface.co