模型简介
模型特点
模型能力
使用案例
🚀 OpenLLaMA:LLaMA的开源复刻版本
OpenLLaMA是对Meta AI的LLaMA大语言模型进行的开源复刻,采用宽松许可协议。本项目发布了一系列3B、7B和13B模型,这些模型在不同的数据混合集上进行训练。模型权重可直接替代现有实现中的LLaMA。
🚀 快速开始
在本仓库中,我们提供了Meta AI的LLaMA大语言模型的开源复刻版本。我们发布了一系列在1万亿个token上训练的3B、7B和13B模型。同时,我们提供了预训练的OpenLLaMA模型的PyTorch和JAX权重,以及评估结果,并与原始的LLaMA模型进行了对比。v2模型比在不同数据混合集上训练的旧v1模型表现更好。更多详细信息,请参阅OpenLLaMA项目主页。
✨ 主要特性
- 开源许可:训练框架EasyLM和检查点权重均在Apache 2.0许可下发布。
- 多格式支持:提供EasyLM和PyTorch两种格式的权重。
- 性能相当:在大多数任务上,OpenLLaMA与原始LLaMA和GPT - J表现相当,在某些任务上更优。
📦 安装指南
本项目未提及具体安装命令,因此跳过安装指南章节。
💻 使用示例
基础用法
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM
## v2 models
model_path = 'openlm-research/open_llama_7b_v2'
## v1 models
# 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文档。
高级用法
使用lm - eval - harness进行评估
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
)
模型可以使用[lm - eval - harness](https://github.com/EleutherAI/lm - evaluation - harness)进行评估。由于前面提到的分词器问题,我们需要避免使用快速分词器以获得正确的结果。可以通过在[lm - eval - harness的这部分](https://github.com/EleutherAI/lm - evaluation - harness/blob/4b701e228768052cfae9043dca13e82052ca5eea/lm_eval/models/huggingface.py#LL313C9 - L316C10)中传入use_fast = False
来实现,如上述示例所示。
使用EasyLM加载权重
若要在我们的EasyLM框架中使用这些权重,请参阅[EasyLM的LLaMA文档](https://github.com/young - geng/EasyLM/blob/main/docs/llama.md)。请注意,与原始的LLaMA模型不同,我们的OpenLLaMA分词器和权重是完全从头开始训练的,因此不再需要获取原始的LLaMA分词器和权重。
📚 详细文档
数据集和训练
- 数据集:v1模型在[RedPajama数据集](https://huggingface.co/datasets/togethercomputer/RedPajama - Data - 1T)上训练。v2模型在[Falcon refined - web数据集](https://huggingface.co/datasets/tiiuae/falcon - refinedweb)、StarCoder数据集以及[RedPajama数据集](https://huggingface.co/datasets/togethercomputer/RedPajama - Data - 1T)中的维基百科、arxiv、书籍和stackexchange部分的混合数据集上训练。
- 训练设置:我们遵循与原始LLaMA论文完全相同的预处理步骤和训练超参数,包括模型架构、上下文长度、训练步骤、学习率调度和优化器。唯一的区别在于使用的数据集:OpenLLaMA使用开放数据集,而不是原始LLaMA使用的数据集。
- 训练平台:我们使用基于JAX的训练管道[EasyLM](https://github.com/young - geng/EasyLM)在云TPU - v4上训练模型。我们结合了普通数据并行和[完全分片数据并行(也称为ZeRO stage 3)](https://engineering.fb.com/2021/07/15/open - source/fsdp/)来平衡训练吞吐量和内存使用。总体而言,我们的7B模型在每个TPU - v4芯片上达到了超过2200个token/秒的吞吐量。
评估
我们使用[lm - eval - harness](https://github.com/EleutherAI/lm - evaluation - harness)在广泛的任务上对OpenLLaMA进行了评估。LLaMA的结果是通过在相同的评估指标上运行原始LLaMA模型生成的。我们注意到,我们的LLaMA模型结果与原始LLaMA论文略有不同,我们认为这是由于不同的评估协议造成的。在[lm - eval - harness的这个问题](https://github.com/EleutherAI/lm - evaluation - harness/issues/443)中也报告了类似的差异。此外,我们还展示了GPT - J的结果,它是由EleutherAI在Pile数据集上训练的一个60亿参数的模型。
原始的LLaMA模型在1万亿个token上训练,GPT - J在5000亿个token上训练。我们在下表中展示了结果。在大多数任务中,OpenLLaMA的性能与原始的LLaMA和GPT - J相当,并且在某些任务中表现更优。
任务/指标 | GPT - J 6B | LLaMA 7B | LLaMA 13B | OpenLLaMA 7Bv2 | OpenLLaMA 3B | OpenLLaMA 7B | OpenLLaMA 13B |
---|---|---|---|---|---|---|---|
anli_r1/acc | 0.32 | 0.35 | 0.35 | 0.34 | 0.33 | 0.33 | 0.33 |
anli_r2/acc | 0.34 | 0.34 | 0.36 | 0.35 | 0.32 | 0.36 | 0.33 |
anli_r3/acc | 0.35 | 0.37 | 0.39 | 0.39 | 0.35 | 0.38 | 0.40 |
arc_challenge/acc | 0.34 | 0.39 | 0.44 | 0.39 | 0.34 | 0.37 | 0.41 |
arc_challenge/acc_norm | 0.37 | 0.41 | 0.44 | 0.41 | 0.37 | 0.38 | 0.44 |
arc_easy/acc | 0.67 | 0.68 | 0.75 | 0.73 | 0.69 | 0.72 | 0.75 |
arc_easy/acc_norm | 0.62 | 0.52 | 0.59 | 0.70 | 0.65 | 0.68 | 0.70 |
boolq/acc | 0.66 | 0.75 | 0.71 | 0.72 | 0.68 | 0.71 | 0.75 |
hellaswag/acc | 0.50 | 0.56 | 0.59 | 0.56 | 0.49 | 0.53 | 0.56 |
hellaswag/acc_norm | 0.66 | 0.73 | 0.76 | 0.75 | 0.67 | 0.72 | 0.76 |
openbookqa/acc | 0.29 | 0.29 | 0.31 | 0.30 | 0.27 | 0.30 | 0.31 |
openbookqa/acc_norm | 0.38 | 0.41 | 0.42 | 0.41 | 0.40 | 0.40 | 0.43 |
piqa/acc | 0.75 | 0.78 | 0.79 | 0.79 | 0.75 | 0.76 | 0.77 |
piqa/acc_norm | 0.76 | 0.78 | 0.79 | 0.80 | 0.76 | 0.77 | 0.79 |
record/em | 0.88 | 0.91 | 0.92 | 0.89 | 0.88 | 0.89 | 0.91 |
record/f1 | 0.89 | 0.91 | 0.92 | 0.89 | 0.89 | 0.90 | 0.91 |
rte/acc | 0.54 | 0.56 | 0.69 | 0.57 | 0.58 | 0.60 | 0.64 |
truthfulqa_mc/mc1 | 0.20 | 0.21 | 0.25 | 0.23 | 0.22 | 0.23 | 0.25 |
truthfulqa_mc/mc2 | 0.36 | 0.34 | 0.40 | 0.35 | 0.35 | 0.35 | 0.38 |
wic/acc | 0.50 | 0.50 | 0.50 | 0.50 | 0.48 | 0.51 | 0.47 |
winogrande/acc | 0.64 | 0.68 | 0.70 | 0.66 | 0.62 | 0.67 | 0.70 |
平均 | 0.52 | 0.55 | 0.57 | 0.56 | 0.53 | 0.55 | 0.57 |
我们从基准测试中移除了任务CB和WSC,因为我们的模型在这两个任务上的表现异常高。我们推测训练集中可能存在基准数据污染。
联系我们
我们非常希望得到社区的反馈。如果您有任何问题,请创建一个issue或联系我们。
OpenLLaMA由伯克利人工智能研究中心的[Xinyang Geng](https://young - geng.xyz/)*和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 v1模型是与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}
}
📄 许可证
本项目采用Apache 2.0许可证。



