模型简介
模型特点
模型能力
使用案例
🚀 Llama3-German-8B-32k (版本 0.1)
Llama3-German-8B-32k 是基于 Meta 的 Llama3-8B 开发的大语言模型,专门针对德语进行了优化。通过在 650 亿高质量德语标记上进行持续预训练,该模型在德语任务上表现出色,同时在英语任务上的性能也保持稳定。
🚀 快速开始
这是一个基础模型,在使用前可能需要进行微调。你可以在我们的 集合 中找到各种微调版本和长上下文版本。
以下是使用 transformers
库调用该模型的示例代码:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
device="cuda"
model = AutoModelForCausalLM.from_pretrained(
"DiscoResearch/Llama3-DiscoLeo-Instruct-8B-v0.1",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("DiscoResearch/Llama3-DiscoLeo-Instruct-8B-v0.1")
prompt = "Schreibe ein Essay über die Bedeutung der Energiewende für Deutschlands Wirtschaft"
messages = [
{"role": "system", "content": "Du bist ein hilfreicher Assistent."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
✨ 主要特性
- 德语优化:通过在 650 亿高质量德语标记上进行持续预训练,模型在德语任务上表现出色,显著减少了语法错误,提升了语言理解和推理能力。
- 长上下文处理:提供长上下文版本(32k 上下文长度),能够处理长达 65k 标记的上下文,适用于需要处理长文本的任务。
- 多版本选择:包括基础模型、长上下文版本、指令微调版本等多种配置,满足不同应用场景的需求。
📦 安装指南
文档未提及安装步骤,故跳过该章节。
💻 使用示例
基础用法
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
device="cuda"
model = AutoModelForCausalLM.from_pretrained(
"DiscoResearch/Llama3-DiscoLeo-Instruct-8B-v0.1",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("DiscoResearch/Llama3-DiscoLeo-Instruct-8B-v0.1")
prompt = "Schreibe ein Essay über die Bedeutung der Energiewende für Deutschlands Wirtschaft"
messages = [
{"role": "system", "content": "Du bist ein hilfreicher Assistent."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
📚 详细文档
模型训练与超参数
模型在 hessian.Ai 42 的 128 个 GPU 上训练了约 60 小时。详细的超参数如下:
参数 | 详情 |
---|---|
序列长度 | 8192 标记 |
学习率 | 1.5e-5 到 1.5e-6(余弦调度) |
批量大小 | 4194304(512*8192)标记 |
微批量大小 | 4*8192 标记 |
训练步数 | 15500 |
热身步数 | 155(1%) |
权重衰减 | 0.05 |
优化器 | AdamW |
数据收集与预处理
预训练阶段,我们使用了来自 occiglot-fineweb-0.5 数据集的 650 亿德语标记。数据包含来自 LLM-Datasets 的多个精选数据集,以及经过 OSCAR's Ungoliant 管道 处理的 12 个 Common-Crawl 版本。
所有数据都使用了基于 Huggingface's fine-web 的特定语言过滤器进行进一步过滤,并进行了全局去重。
评估与结果
我们使用 GermanBench 中的一系列常见英语基准测试及其德语版本对模型进行了评估。
下图展示了与基础模型 meta-llama/Meta-Llama3-8B 以及两种不同超参数配置的基准测试结果对比。我们对不同的学习率进行了扫描,以确定一个效果良好的设置。最终发布的模型是学习率为 1.5e-5 的版本。
基础模型和长上下文模型的详细基准测试分数如下表所示:
模型 | truthful_qa_de | truthfulqa_mc | arc_challenge | arc_challenge_de | hellaswag | hellaswag_de | MMLU | MMLU-DE | 平均值 |
---|---|---|---|---|---|---|---|---|---|
DiscoResearch/Llama3-German-8B | 0.49499 | 0.44838 | 0.55802 | 0.49829 | 0.79924 | 0.65395 | 0.62240 | 0.54413 | 0.57743 |
DiscoResearch/Llama3-German-8B-32k | 0.48920 | 0.45138 | 0.54437 | 0.49232 | 0.79078 | 0.64310 | 0.58774 | 0.47971 | 0.55982 |
meta-llama/Meta-Llama-3-8B-Instruct | 0.47498 | 0.43923 | 0.59642 | 0.47952 | 0.82025 | 0.60008 | 0.66658 | 0.53541 | 0.57656 |
长上下文扩展
除了基础模型,我们还发布了 Llama3-German-8B 的长上下文版本 (DiscoResearch/Llama3-German-8B-32k),能够处理长达 65k 标记的上下文。该变体在 32k 上下文长度下额外训练了 1 亿标记,使用的 rope_theta
值为 1.5e6
,学习率为 1.5e-5
,批量大小为 256*8192
标记,其他超参数与基础模型相同。
指令微调
我们还提供了一个指令微调版本:DiscoResearch/Llama3-DiscoLeo-Instruct-8B-v0.1,使用 DiscoLM 德语数据集进行微调(也有长上下文版本,DiscoResearch/Llama3-DiscoLeo-Instruct-8B-32k-v0.1)。
更多详细信息请参考相应的模型卡片。此外,还可以查看我们的实验性合并模型 (DiscoResearch/Llama3-DiscoLeo-8B-DARE-Experimental),该模型尝试结合 meta-llama/Meta-Llama3-8B-Instruct 的出色能力和我们微调模型的卓越德语技能。
文档打包
我们采用了基于 "Fewer Truncations Improve Language Modeling" 论文(Ding 等人,2024) 的更智能的文档打包策略,使用首次适应递减算法将文档打包成批次,而不进行截断。
我们将数据按 10000 个文档为一组进行打包,以提高处理效率,同时保持 >99% 的打包效率。长度超过序列长度的文档会被分割成序列长度的块。
在相同数据和超参数的训练条件下,这种方法在整体基准测试中取得了更高的分数。以下是使用 3e-5
学习率和 12k 步的初始实验结果,显示了与原论文相似的改进:
任务 | 简单打包 | 减少截断打包 | 百分比提升 |
---|---|---|---|
truthfulqa_mc | 0.452648 | 0.467687 | 3.32% |
arc_challenge | 0.517918 | 0.528157 | 1.98% |
truthful_qa_de | 0.485529 | 0.492979 | 1.53% |
arc_challenge_de | 0.480375 | 0.493174 | 2.66% |
hellaswag | 0.776041 | 0.773352 | -0.35% |
hellaswag_de | 0.655248 | 0.653356 | -0.29% |
MMLU | 0.573719 | 0.579802 | 1.06% |
MMLU-DE | 0.504509 | 0.503863 | -0.13% |
以下是论文中描述的首次适应递减算法的简单实现:
def pack_documents(tokenized_documents):
# Sort documents by their length in descending order
sorted_docs = sorted(tokenized_documents, key=len, reverse=True)
# Initialize bins
bins = []
# Function to find the first bin that can accommodate the document
def find_bin(doc):
for b in bins:
if sum(len(d) for d in b) + len(doc) <= 8192:
return b
return None
# Place each document in the first available bin or create a new bin
for doc in sorted_docs:
target_bin = find_bin(doc)
if target_bin is not None:
target_bin.append(doc)
else:
# Create a new bin with this document if no suitable bin is found
bins.append([doc])
# Return results
return bins
模型配置
我们发布了 DiscoLeo-8B 的以下配置:
🔧 技术细节
文档未提供具体的技术实现细节,故跳过该章节。
📄 许可证
本模型使用 Llama3 许可证。



