模型:
在这个存储库中,我们展示了 Meta AI 公司的 LLaMA 大型语言模型的一个开放源代码复刻版。我们发布了经过1万亿标记训练的3B、7B和13B模型。我们提供了预训练的 OpenLLaMA 模型的 PyTorch 和 JAX 权重,以及与原始 LLaMA 模型的评估结果和比较。更多详情请参阅 project homepage of OpenLLaMA 。
我们以两种格式发布权重:一种是用于我们的 EasyLM 框架的 EasyLM 格式,另一种是用于 Hugging Face transformers 库的 PyTorch 格式。我们的训练框架 EasyLM 和检查点权重都采用 Apache 2.0 许可证进行许可。
预览检查点可以直接从 Hugging Face Hub 加载。目前建议避免使用 Hugging Face 快速分词器,因为我们观察到自动转换的快速分词器有时会给出不正确的标记。可以通过直接使用 LlamaTokenizer 类,或将 AutoTokenizer 类的 use_fast=False 选项传递给它来实现这一点。以下示例演示了使用方法。
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM
# model_path = 'openlm-research/open_llama_3b'
# model_path = 'openlm-research/open_llama_7b'
model_path = 'openlm-research/open_llama_13b'
tokenizer = LlamaTokenizer.from_pretrained(model_path)
model = LlamaForCausalLM.from_pretrained(
model_path, torch_dtype=torch.float16, device_map='auto',
)
prompt = 'Q: What is the largest animal?\nA:'
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
generation_output = model.generate(
input_ids=input_ids, max_new_tokens=32
)
print(tokenizer.decode(generation_output[0]))
有关更高级的用法,请参阅 transformers LLaMA documentation 。
模型可以使用 lm-eval-harness 进行评估。然而,由于之前提到的分词器问题,我们需要避免使用快速分词器以获得正确的结果。可以通过向 this part of lm-eval-harness 传递 use_fast=False 来实现,如下例所示:
tokenizer = self.AUTO_TOKENIZER_CLASS.from_pretrained(
pretrained if tokenizer is None else tokenizer,
revision=revision + ("/" + subfolder if subfolder is not None else ""),
use_fast=False
)
要在我们的 EasyLM 框架中使用权重,请参阅 LLaMA documentation of EasyLM 。请注意,与原始 LLaMA 模型不同,我们的 OpenLLaMA 分词器和权重是完全从头开始训练的,因此不再需要获取原始 LLaMA 分词器和权重。请注意,在训练过程中,我们使用了 BOS(句子开头)标记(id=1)。因此,在进行少样本评估时,最好在句子前面添加此标记以获得最佳性能。
我们使用 RedPajama 数据集对模型进行训练,该数据集由 Together 发布,是 LLaMA 训练数据集的复制版本,包含超过1.2万亿个标记。我们遵循与原始 LLaMA 论文相同的预处理步骤和训练超参数,包括模型架构、上下文长度、训练步骤、学习率调度和优化器。我们设置与原始设置的唯一区别是使用的数据集:OpenLLaMA 使用了 RedPajama 数据集,而不是原始 LLaMA 使用的数据集。
我们使用云 TPU-v4 在我们开发的 JAX 训练管道 EasyLM 上训练模型。我们采用正常数据并行化和 fully sharded data parallelism (also know as ZeRO stage 3) 来平衡训练吞吐量和内存使用情况。总体而言,我们的7B模型的吞吐量超过每秒2200个标记/TPU-v4芯片。
我们使用 lm-evaluation-harness 对 OpenLLaMA 在各种任务上进行了评估。使用相同的评估指标在原始 LLaMA 模型上运行,得到 LLaMA 的结果。我们注意到我们对 LLaMA 模型的结果与原始 LLaMA 论文略有不同,我们认为这是由于不同的评估协议导致的。 this issue of lm-evaluation-harness 中也报告了类似的差异。此外,我们还提供了基于 Pile 数据集和 EleutherAI 训练的 6B 参数的 GPT-J 的结果。
原始 LLaMA 模型训练了1万亿个标记,GPT-J 训练了5000亿个标记。我们在下表中呈现了结果。OpenLLaMA 在大多数任务上表现出与原始 LLaMA 和 GPT-J 相当的性能,并在某些任务上超越它们。
| Task/Metric | GPT-J 6B | LLaMA 7B | LLaMA 13B | OpenLLaMA 7B | OpenLLaMA 3B | OpenLLaMA 13B |
|---|---|---|---|---|---|---|
| anli_r1/acc | 0.32 | 0.35 | 0.35 | 0.33 | 0.33 | 0.33 |
| anli_r2/acc | 0.34 | 0.34 | 0.36 | 0.36 | 0.32 | 0.33 |
| anli_r3/acc | 0.35 | 0.37 | 0.39 | 0.38 | 0.35 | 0.40 |
| arc_challenge/acc | 0.34 | 0.39 | 0.44 | 0.37 | 0.34 | 0.41 |
| arc_challenge/acc_norm | 0.37 | 0.41 | 0.44 | 0.38 | 0.37 | 0.44 |
| arc_easy/acc | 0.67 | 0.68 | 0.75 | 0.72 | 0.69 | 0.75 |
| arc_easy/acc_norm | 0.62 | 0.52 | 0.59 | 0.68 | 0.65 | 0.70 |
| boolq/acc | 0.66 | 0.75 | 0.71 | 0.71 | 0.68 | 0.75 |
| hellaswag/acc | 0.50 | 0.56 | 0.59 | 0.53 | 0.49 | 0.56 |
| hellaswag/acc_norm | 0.66 | 0.73 | 0.76 | 0.72 | 0.67 | 0.76 |
| openbookqa/acc | 0.29 | 0.29 | 0.31 | 0.30 | 0.27 | 0.31 |
| openbookqa/acc_norm | 0.38 | 0.41 | 0.42 | 0.40 | 0.40 | 0.43 |
| piqa/acc | 0.75 | 0.78 | 0.79 | 0.76 | 0.75 | 0.77 |
| piqa/acc_norm | 0.76 | 0.78 | 0.79 | 0.77 | 0.76 | 0.79 |
| record/em | 0.88 | 0.91 | 0.92 | 0.89 | 0.88 | 0.91 |
| record/f1 | 0.89 | 0.91 | 0.92 | 0.90 | 0.89 | 0.91 |
| rte/acc | 0.54 | 0.56 | 0.69 | 0.60 | 0.58 | 0.64 |
| truthfulqa_mc/mc1 | 0.20 | 0.21 | 0.25 | 0.23 | 0.22 | 0.25 |
| truthfulqa_mc/mc2 | 0.36 | 0.34 | 0.40 | 0.35 | 0.35 | 0.38 |
| wic/acc | 0.50 | 0.50 | 0.50 | 0.51 | 0.48 | 0.47 |
| winogrande/acc | 0.64 | 0.68 | 0.70 | 0.67 | 0.62 | 0.70 |
| Average | 0.52 | 0.55 | 0.57 | 0.55 | 0.53 | 0.57 |
我们从基准测试中删除了 CB 和 WSC 任务,因为我们的模型在这两个任务上的表现异常好。我们推测在训练集中可能存在基准数据污染。
我们非常希望得到社区的反馈。如果您有任何问题,请提出问题或与我们联系。
OpenLLaMA 的开发人员: Xinyang Geng 和 Hao Liu 来自伯克利人工智能研究。*同等贡献
我们感谢 Google TPU Research Cloud 计划提供部分计算资源。我们特别感谢来自 TPU Research Cloud 的 Jonathan Caton 帮助我们组织计算资源,来自 Google Cloud 团队的 Rafi Witten 和 Google JAX 团队的 James Bradbury 帮助我们优化训练吞吐量。我们还要感谢 Charlie Snell、Gautier Izacard、Eric Wallace、Lianmin Zheng 和我们的用户社区的讨论和反馈。
OpenLLaMA 13B 模型是与 Stability AI 共同训练的,我们感谢 Stability AI 提供计算资源。我们特别感谢 David Ha 和 Shivanshu Purohit 协调物流并提供工程支持。
如果您在研究或应用中使用了 OpenLLaMA,请使用以下 BibTeX 引用:
@software{openlm2023openllama,
author = {Geng, Xinyang and Liu, Hao},
title = {OpenLLaMA: An Open Reproduction of LLaMA},
month = May,
year = 2023,
url = {https://github.com/openlm-research/open_llama}
}
@software{together2023redpajama,
author = {Together Computer},
title = {RedPajama-Data: An Open Source Recipe to Reproduce LLaMA training dataset},
month = April,
year = 2023,
url = {https://github.com/togethercomputer/RedPajama-Data}
}
@article{touvron2023llama,
title={Llama: Open and efficient foundation language models},
author={Touvron, Hugo and Lavril, Thibaut and Izacard, Gautier and Martinet, Xavier and Lachaux, Marie-Anne and Lacroix, Timoth{\'e}e and Rozi{\`e}re, Baptiste and Goyal, Naman and Hambro, Eric and Azhar, Faisal and others},
journal={arXiv preprint arXiv:2302.13971},
year={2023}
}