跳到正文
Hugging Face Blog·· 2024-07-23精選AI 評分87

Meta 發佈 Llama 3.1,推出 8B、70B、405B 模型並支援多語言與 128K tokens 上下文

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

AI 導讀

Meta 發佈 Llama 3.1,提供 8B、70B、405B 三種規模的 base 與 instruct 模型,均支援 128K tokens 上下文和 8 種語言。Instruct 版本加入工具調用能力,並支援自訂 JSON 函數;授權亦允許以模型輸出改進其他 LLM。Hugging Face 同時列出 Transformers、TGI 等整合,以及各型號在推理和微調時的記憶體需求。

推薦理由

文章將 8B、70B、405B 的部署定位、128K tokens 上下文及記憶體需求一併列出,可比較不同規模模型的使用取捨。

正文 · 繁體中文

Llama 3.1 推出!今天,我們在 Hugging Face 迎來 Llama 系列的新一代產品。我們很高興與 Meta 合作,確保它能與 Hugging Face 生態系統完善整合。Hub 上現有八款開放權重模型(3 款基礎模型及 5 款微調模型)。

Llama 3.1 有三種規模:8B 適合在消費級 GPU 上高效部署和開發;70B 適合大型 AI 原生應用;405B 則適合生成合成資料、以 LLM 作評審或進行蒸餾。三種規模均提供基礎版及指令微調版。

除了六款生成式模型,Meta 亦推出兩款新模型:Llama Guard 3 和 Prompt Guard。Prompt Guard 是小型分類器,可偵測提示注入和越獄攻擊;Llama Guard 3 則是安全防護模型,可分類 LLM 的輸入和生成內容。

本次發布的功能和整合包括:

  • Hub 上的模型
  • Hugging Face Transformers 和 TGI 整合
  • Hugging Chat 整合 Meta Llama 3.1 405B Instruct
  • 與 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)
  • 多語言能力
  • 工具使用能力
  • 參數量高達 405 billion 的大型稠密模型
  • 限制較少的授權條款

以下逐一介紹!

Llama 3.1 發布六款以 Llama 3 架構為基礎的全新開源 LLM,分為 8B、70B 和 405B 三種規模,每款均有基礎版(預訓練)及指令微調版。所有版本均支援128K tokens上下文長度及 8 種語言,包括英文、德文、法文、意大利文、葡萄牙文、印地文、西班牙文和泰文。Llama 3.1 繼續採用 Grouped-Query Attention(GQA),這種高效表示方式應有助處理較長上下文。

除了這 6 款語言模型,Meta 亦發布 Llama Guard 3 和 Prompt Guard。

  • Llama Guard 3 是 Llama Guard 系列的最新版本,以 Llama 3.1 8B 微調而成。它針對生產用途設計,支援 128k 上下文長度和多語言能力,可按風險分類法分類 LLM 輸入(提示)和回應,以偵測不安全內容。
  • 另一方面,Prompt Guard 是一款小型、含 279M 參數的 BERT 分類器,可偵測提示注入和越獄攻擊。它以大量攻擊案例語料訓練,建議再使用應用程式專用資料微調。

與 Llama 3 相比,Llama 3.1 的新特點是指令模型已針對代理式用途的工具呼叫進行微調。它內置兩款工具(搜尋,以及透過 Wolfram Alpha 進行數學推理),亦可用自訂 JSON 函數擴充。

Llama 3.1 模型使用自建 GPU 叢集訓練超過 15 trillion tokens,總計消耗 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,並未計入 torch 為核心或 CUDA graphs 預留的空間。

例如,一個由 8 部 H100 組成的 H100 節點約有 640GB VRAM,因此 405B 模型需要多節點設定,或降低精度(例如 FP8);後者是建議做法。

請留意,較低精度(例如 INT4)可能稍微降低準確度,但可大幅減少記憶體需求並加快推論。除了模型權重,亦須在記憶體中保存 KV Cache,其中儲存模型上下文內所有 tokens 的鍵和值,生成新 token 時便無需重新計算。若使用可用的長上下文,KV Cache 尤其會佔用大量資源。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

上下文長度接近上限時,尤其是小型模型,cache 佔用的記憶體可與權重相若。

訓練所需記憶體

下表概述使用不同技術訓練 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 的官方評估。

類別 基準測試 提示次數 指標 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 發布的原始檢查點所用格式,為確保最佳精度或進行評估,建議採用此方式執行。
  • Assistant 回應可能以特殊 token <|eot_id|> 結尾,但若偵測到一般 EOS token,我們亦必須停止生成。可在 eos_token_id 參數提供終止符清單,提早停止生成。
  • 我們使用 Meta 原始程式碼庫中的預設取樣參數(temperature 和 top_p)。我們尚未有時間進行廣泛測試,歡迎大家自行探索!

以下範例示範如何使用 meta-llama/Meta-Llama-3.1-8B-Instruct,約需 16 GB VRAM,適用於不少消費級 GPU。同一範例亦適用於 meta-llama/Meta-Llama-3.1-70B-Instruct(需 140GB VRAM)及 meta-llama/Meta-Llama-3.1-405B-Instruct(需 810GB VRAM),令後者成為很適合生產環境的模型。改用 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 = 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 程式碼以呼叫函數屬於 code interpreter 工具功能;如以下所示,必須在 system prompt 中使用 Environment 關鍵字啟用。

內置工具呼叫

加入「Environment: ipython」即可啟用 code interpreter 模式,模型會生成預期由程式執行的 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|>

此時模型的回應會包含呼叫其中一款支援工具的 Python 程式碼(本例為 brave_search):

<|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|>。必須調整 system prompt,告知模型如何處理函數呼叫的輸出。

自訂工具呼叫 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 提供的 chat template 讓正確格式化提示變得簡單。

示範

你可在以下示範中試用三款 Instruct 模型:

整個技術堆疊都是開源的。Hugging Chat 由 chat-ui 和 text-generation-inference 驅動。

以 FP8、AWQ 和 GPTQ 量化 Llama 3.1 405B

Meta 建立了官方 FP8 量化版 Llama 3.1 405B,準確度損失極小。為此,只對模型的主要線性運算子進行 FP8 量化,例如 FFN 的 gate、up 和 down projection(涵蓋 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 Inference 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 client libraries 相容,包括 LangChain 和 LlamaIndex。

注意:請將 huggingface_hub 更新至最新版本,使用 pip install "huggingface_hub>=0.24.1。


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、連續批次處理、token 串流,以及在多部 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-bit 量化和 QLoRA 節省記憶體,並以注意力區塊的所有線性層為微調目標。

使用 Hugging Face TRL 微調範例

首先安裝 🤗 TRL 每夜版,並複製儲存庫以取得訓練指令碼:

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 建立偏好資料集。此資料集可用 TRL 提供的偏好最佳化方法(例如 DPO 或 KTO)微調模型。

首先按以下方式安裝最新 distilabel 版本(連同 hf-inference-endpoints 附加套件),使用 pip:

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

然後定義一條 pipeline:

  • 從 Hugging Face Hub 載入含指令的資料集。
  • 透過 Hugging Face Inference Endpoints,使用 Llama 3.1 70B Instruct 和 Llama 3.1 405B Instruct 生成回應。
  • 最後使用 Llama 3.1 405B Instruct 作評審,以 UltraFeedback 提示為回應評分。根據評分選取較佳及較差的回應,便可使用偏好最佳化方法微調模型。

請參閲下方程式碼以定義 pipeline,或使用這個 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 作評審來評估輸出、擴展指令、篩選資料,以及定義自訂元件。

其他資源

鳴謝

這些模型得以發布,並在生態系統中獲得支援和評估,仰賴數以千計的社羣成員為 transformers、tgi、vllm、pytorch、LM Eval Harness 及許多其他專案作出貢獻。本次發布亦有賴以下人士支持:協助 LLM 評估的 Clémentine 和 Nathan;支援 Text Generation Inference 的 Nicolas、Olivier Dehaene 和 Daniël de Kok;協助將 Llama 3.1 整合至 Arthur、Matthew Carrigan、Zachary Mueller、Joao、Joshua Lochner 和 Lysandre 的 transformers;協助量化的 Matthew Douglas;支援 Gabriel Martín Blázquez 的 distilabel;協助審閲的 Merve Noyan 和 Aymeric Roucher;製作示範的 hysts 和 Yuvi;測試微調的 Ellie;負責溝通的 Brigitte Tousignant 和 Florent Daudens;以及令 Llama 3.1 能在 Hugging Chat 使用的 Nathan 和 Victor。

亦感謝 Meta 團隊發布 Llama 3.1,並讓開源 AI 社羣能夠使用!

來源:Hugging Face Blog · huggingface.co