OLMo 7B 2024年4月版是原始OLMo 7B模型的更新版本。通过使用改进版的Dolma数据集和分阶段训练,该版本在MMLU评估中得分提升了24分,其他评估指标也有所改善。 此版本可直接与v4.40及更高版本的HuggingFace Transformers配合使用。
OLMo(Open Language Models,开放语言模型)系列旨在推动语言模型科学的发展。 OLMo模型均在Dolma数据集上训练。 我们公开发布训练这些模型所涉及的所有代码、检查点、日志和详细信息。
本批次发布的核心模型如下:
| 规模 | 训练 tokens | 层数 | 隐藏层大小 | 注意力头数 | 上下文长度 |
|---|---|---|---|---|---|
| OLMo 1B | 3万亿 | 16 | 2048 | 16 | 2048 |
| OLMo 7B | 2.5万亿 | 32 | 4096 | 32 | 2048 |
| OLMo 7B Twin 2T | 2万亿 | 32 | 4096 | 32 | 2048 |
| OLMo 7B April 2024 | 2.05万亿 | 32 | 4096 | 32 | 4096 |
注:OLMo 7B 2024年4月版还包含QKV裁剪功能。
要使用HuggingFace加载特定的模型修订版本,只需添加参数revision:
olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B-0424-hf", revision="step1000-tokens4B")所有修订版本/分支均列于文件 revisions.txt 中。
或者,您可以通过以下代码片段访问模型的所有修订版本:
from huggingface_hub import list_repo_refs
out = list_repo_refs("allenai/OLMo-7B-0424-hf")
branches = [b.name for b in out.branches]from openmind import pipeline, is_torch_npu_available
from openmind import AutoTokenizer, AutoModelForCausalLM
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="jeffding/OLMo-1.7-7B-hf-openmind",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(device)
start_time = time.time()
text = "Generative AI is "
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer,device=device)
generated_text = pipe(text, max_length=50, do_sample=False, no_repeat_ngram_size=2)[0]
print(generated_text['generated_text'])
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()olmo at allenai dot org。媒体联络:press at allenai dot org按照 HuggingFace 的常规方式操作:
from transformers import AutoModelForCausalLM, AutoTokenizer
olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B-0424-hf")
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-7B-0424-hf")
message = ["Language modeling is"]
inputs = tokenizer(message, return_tensors='pt', return_token_type_ids=False)
# optional verifying cuda
# inputs = {k: v.to('cuda') for k,v in inputs.items()}
# olmo = olmo.to('cuda')
response = olmo.generate(**inputs, max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
>> 'Language modeling is the first step to build natural language generation...'或者,使用 pipeline 抽象:
from transformers import pipeline
olmo_pipe = pipeline("text-generation", model="allenai/OLMo-7B-0424-hf")
print(olmo_pipe("Language modeling is "))
>> 'Language modeling is a branch of natural language processing that aims to...'或者,你可以通过对模型进行量化来略微提高速度,例如 AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B-0424-hf", torch_dtype=torch.float16, load_in_8bit=True)(需要 bitsandbytes)。
量化后的模型对类型/ CUDA 更为敏感,因此建议将输入以 inputs.input_ids.to('cuda') 的形式传入,以避免潜在问题。
模型微调可以从最终检查点(此模型的 main 修订版)或许多中间检查点进行。有两种调优方案可供使用。
torchrun --nproc_per_node=8 scripts/train.py {path_to_train_config} \
--data.paths=[{path_to_data}/input_ids.npy] \
--data.label_mask_paths=[{path_to_data}/label_mask.npy] \
--load_path={path_to_checkpoint} \
--reset_trainer_state更多文档,请参见 GitHub 自述文件。
新模型和原始 7B 模型的核心模型结果如下。
| 任务 | Llama-7b | Llama2-7b | Falcon-7b | Mpt-7b | OLMo-7B | Llama2-13b | OLMo 1.7-7B |
|---|---|---|---|---|---|---|---|
| arc_c | 44.5 | 48.5 | 47.5 | 46.5 | 48.5 | 52.8 | 42.5 |
| arc_e | 67.9 | 69.5 | 70.4 | 70.5 | 65.4 | 73.7 | 67.2 |
| boolq | 75.4 | 80.2 | 74.6 | 74.2 | 73.4 | 82.2 | 83.7 |
| copa | 91.0 | 86.0 | 86.0 | 85.0 | 90.0 | 90.0 | 86.0 |
| hellaswag | 76.2 | 76.8 | 75.9 | 77.6 | 76.4 | 78.6 | 75.5 |
| openbookqa | 51.2 | 48.4 | 53.0 | 48.6 | 50.4 | 51.8 | 50.0 |
| piqa | 77.2 | 76.7 | 78.5 | 77.3 | 78.4 | 79.0 | 77.5 |
| sciq | 93.9 | 94.5 | 93.9 | 93.7 | 93.8 | 95.5 | 96.7 |
| winogrande | 70.5 | 69.4 | 68.9 | 69.9 | 67.9 | 73.5 | 69.8 |
| truthfulQA (MC2) | 33.9 | 38.5 | 34.0 | 33.0 | 36.0 | 36.8 | 35.8 |
| MMLU (5 shot MC) | 31.5 | 45.0 | 24.0 | 30.8 | 28.3 | 55.5 | 52.0 |
| GSM8k | 10.0 | 12.0 | 4.0 | 4.5 | 8.5 | 25.0 | 29.0 |
| 总体平均值 | 60.3 | 62.1 | 59.2 | 59.3 | 59.8 | 66.2 | 63.8 |
1B 模型的结果如下:
| 任务 | 随机值 | StableLM 2 1.6b* | Pythia 1B | TinyLlama 1.1B | OLMo 1B(我们的模型) |
|---|---|---|---|---|---|
| arc_challenge | 25 | 43.81 | 33.11 | 34.78 | 34.45 |
| arc_easy | 25 | 63.68 | 50.18 | 53.16 | 58.07 |
| boolq | 50 | 76.6 | 61.8 | 64.6 | 60.7 |
| copa | 50 | 84 | 72 | 78 | 79 |
| hellaswag | 25 | 68.2 | 44.7 | 58.7 | 62.5 |
| openbookqa | 25 | 45.8 | 37.8 | 43.6 | 46.4 |
| piqa | 50 | 74 | 69.1 | 71.1 | 73.7 |
| sciq | 25 | 94.7 | 86 | 90.5 | 88.1 |
| winogrande | 50 | 64.9 | 53.3 | 58.9 | 58.9 |
| 平均值 | 36.11 | 68.41 | 56.44 | 61.48 | 62.42 |
*与 OLMo、Pythia 和 TinyLlama 不同,StabilityAI 尚未披露 StableLM 的训练数据,这使得与其他模型的比较存在一定难度。
关于训练数据的详细信息,请参阅 Dolma 文档。 本模型采用全新的 1.7 版本,该版本包含更多数据源、更优的去重处理和质量过滤。 在退火阶段,我们使用 Dolma 的一个更高质量子集,并采用线性衰减学习率直至为 0。
与 OLMo 1.0 不同,我们采用两阶段课程学习方式训练 OLMo 1.7:
OLMo 7B 架构以及用于比较的同类模型。
| OLMo 7B | Llama 2 7B | OpenLM 7B | Falcon 7B | PaLM 8B | |
|---|---|---|---|---|---|
| d_model | 4096 | 4096 | 4096 | 4544 | 4096 |
| 注意力头数 | 32 | 32 | 32 | 71 | 16 |
| 层数 | 32 | 32 | 32 | 32 | 32 |
| MLP 比例 | ~8/3 | ~8/3 | ~8/3 | 4 | 4 |
| 层归一化类型 | 非参数化 LN | RMSNorm | 参数化 LN | 参数化 LN | 参数化 LN |
| 位置嵌入 | RoPE | RoPE | RoPE | RoPE | RoPE |
| 注意力变体 | 全注意力 | GQA | 全注意力 | MQA | MQA |
| 偏置项 | 无 | 无 | 仅在 LN 中 | 仅在 LN 中 | 无 |
| 模块类型 | 顺序式 | 顺序式 | 顺序式 | 并行式 | 并行式 |
| 激活函数 | SwiGLU | SwiGLU | SwiGLU | GeLU | SwiGLU |
| 序列长度 | 2048 | 4096 | 2048 | 2048 | 2048 |
| 批大小(样本数) | 2160 | 1024 | 2048 | 2304 | 512 |
| 批大小(tokens) | ~4M | ~4M | ~4M | ~4M | ~1M |
| 权重共享 | 否 | 否 | 否 | 否 | 是 |
以下为AdamW优化器参数。
| 规模 | 峰值学习率 | 贝塔系数 | epsilon | 权重衰减 |
|---|---|---|---|---|
| 1B | 4.0E-4 | (0.9, 0.95) | 1.0E-5 | 0.1 |
| 7B | 3.0E-4 | (0.9, 0.99) | 1.0E-5 | 0.1 |
与同类模型的优化器设置对比。
| OLMo 7B | Llama 2 7B | OpenLM 7B | Falcon 7B | |
|---|---|---|---|---|
| 预热步数 | 5000 | 2000 | 2000 | 1000 |
| 峰值学习率 | 3.0E-04 | 3.0E-04 | 3.0E-04 | 6.0E-04 |
| 最小学习率 | 3.0E-05 | 3.0E-05 | 3.0E-05 | 1.2E-05 |
| 权重衰减 | 0.1 | 0.1 | 0.1 | 0.1 |
| beta1 | 0.9 | 0.9 | 0.9 | 0.99 |
| beta2 | 0.95 | 0.95 | 0.95 | 0.999 |
| epsilon | 1.0E-05 | 1.0E-05 | 1.0E-05 | 1.0E-05 |
| 学习率调度 | 线性 | 余弦 | 余弦 | 余弦 |
| 梯度裁剪 | 全局 1.0 | 全局 1.0 | 全局 1.0 | 全局 1.0 |
| 梯度归约数据类型 | FP32 | FP32 | FP32 | BF16 |
| 优化器状态数据类型 | FP32 | 很可能为 FP32 | FP32 | FP32 |
与任何基础语言模型或未经安全过滤的微调模型一样,用户相对容易通过提示词让这些模型生成有害及通常具有敏感性的内容。
此类内容也可能非故意产生,尤其是在存在偏见的情况下,因此我们建议用户考虑应用此技术所带来的风险。
此外,OLMo或任何LLM输出的许多事实往往并非真实,因此需要进行核实。
BibTeX:
@article{Groeneveld2023OLMo,
title={OLMo: Accelerating the Science of Language Models},
author={Groeneveld, Dirk and Beltagy, Iz and Walsh, Pete and Bhagia, Akshita and Kinney, Rodney and Tafjord, Oyvind and Jha, Ananya Harsh and Ivison, Hamish and Magnusson, Ian and Wang, Yizhong and Arora, Shane and Atkinson, David and Authur, Russell and Chandu, Khyathi and Cohan, Arman and Dumas, Jennifer and Elazar, Yanai and Gu, Yuling and Hessel, Jack and Khot, Tushar and Merrill, William and Morrison, Jacob and Muennighoff, Niklas and Naik, Aakanksha and Nam, Crystal and Peters, Matthew E. and Pyatkin, Valentina and Ravichander, Abhilasha and Schwenk, Dustin and Shah, Saurabh and Smith, Will and Subramani, Nishant and Wortsman, Mitchell and Dasigi, Pradeep and Lambert, Nathan and Richardson, Kyle and Dodge, Jesse and Lo, Kyle and Soldaini, Luca and Smith, Noah A. and Hajishirzi, Hannaneh},
journal={Preprint},
year={2024}
}APA格式:
Groeneveld, D., Beltagy, I., Walsh, P., Bhagia, A., Kinney, R., Tafjord, O., Jha, A., Ivison, H., Magnusson, I., Wang, Y., Arora, S., Atkinson, D., Authur, R., Chandu, K., Cohan, A., Dumas, J., Elazar, Y., Gu, Y., Hessel, J., Khot, T., Merrill, W., Morrison, J., Muennighoff, N., Naik, A., Nam, C., Peters, M., Pyatkin, V., Ravichander, A., Schwenk, D., Shah, S., Smith, W., Subramani, N., Wortsman, M., Dasigi, P., Lambert, N., Richardson, K., Dodge, J., Lo, K., Soldaini, L., Smith, N., & Hajishirzi, H. (2024). OLMo:加速语言模型科学研究。预印本。
如本模型卡片存在错误,请联系Nathan,邮箱地址:{nathanl} at allenai dot org。