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

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

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

AI 导读

Hugging Face 上线 Meta Llama 3.1 系列,包含 8B、70B、405B 三个尺寸的基础与指令微调共六个模型,另发布 Llama Guard 3 和 Prompt Guard。

推荐理由

官方梳理了 Llama 3.1 三个尺寸的显存需求、量化方案和微调入口,便于据此评估部署成本。

正文 · AI 翻译

Llama 3.1 问世了!今天我们欢迎 Llama 系列的下一个迭代版本加入 HF Mirror。我们很高兴能与 Meta 合作,确保在 HF Mirror 生态系统中实现最佳集成。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 上的模型
  • HF Mirror 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 则是一个基于 BERT 的 279M 参数小型分类器,可以检测提示注入和越狱。它在一个大型攻击语料库上进行了训练,并建议使用特定于应用程序的数据进一步微调。

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

Llama 3.1 模型在超过 15 万亿个 token 上进行了训练,使用了一个定制构建的 GPU 集群,总计 39.3M GPU 小时(8B 为 1.46M,70B 为 7.0M,405B 为 30.84M)。我们不知道训练数据集混合的确切细节,只能猜测它为多语言性进行了更多样化的整理。Llama 3.1 Instruct 针对指令遵循进行了优化,并在公开可用的指令数据集以及超过 25M 个合成生成的示例上进行了训练,采用了监督微调(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 缓存。它包含模型上下文中所有 token 的键和值,这样在生成新 token 时就不需要重新计算它们。尤其是在利用较长的可用上下文长度时,它会成为一个重要因素。在 FP16 下,KV 缓存的内存需求为:

模型大小 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

使用 HF Mirror Transformers

Llama 3.1 需要进行少量建模更新,以有效处理 RoPE 缩放。使用 Transformers 4.43.2 版本,你可以使用新的 Llama 3.1 模型,并利用 HF Mirror 生态系统中的所有工具。请务必使用最新的 transformers 版本:

pip install "transformers>=4.43.2" --upgrade

几个细节:

  • Transformers 默认以 bfloat16 加载模型。这是 Meta 发布的原始检查点所使用的类型,因此建议以此方式运行,以确保最佳精度或进行评估。
  • 助手回复可能会以特殊 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 位模式加载它。以 4 位模式加载大型的 70B 版本大约需要 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 的门控、上投影和下投影(覆盖了 75% 的推理 FLOPs)。我们共同努力确保此 FP8 量化检查点在社区(transformers、TGI、VLLM)中兼容。

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

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

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

推理集成

HF Mirror 推理 API

HF Mirror 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 的更多详细信息,请查看此文章。

HF Mirror 推理端点

你可以在 HF Mirror 的 Inference Endpoints 上部署 Llama 3.1,该端点使用 Text Generation Inference 作为后端。Text Generation Inference 是 HF Mirror 开发的生产就绪推理容器,支持 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="")

HF Mirror 合作伙伴集成

注意:我们目前正在与 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 获取电子邮件更新。

使用 HF Mirror TRL 进行微调

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

使用 HF Mirror 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

然后定义一个管道,它:

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

请参阅下面的代码来定义管道,或者使用这个 Colab 笔记本 自行运行,并在 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 还提供了在广泛场景和主题中使用 LLMs 进行合成数据生成的令人兴奋的方法。它包括当前 SOTA 文献中的实现,用于执行诸如使用 LLM 作为评判者方法评估输出、演化指令、数据过滤以及定义自定义组件等任务。

其他资源

致谢

在生态系统中发布此类模型并提供支持和评估,离不开数千名社区成员的贡献,他们为 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 使 Llama 3.1 在 Hugging Chat 中可用。

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

来源:Hugging Face Blog · hf-mirror.com