模型概述
模型特點
模型能力
使用案例
🚀 OLMo 7B Instruct模型介紹
OLMo 7B Instruct是一款專為語言模型研究而設計的模型,它基於OLMo基礎模型進行改進,在問答任務上表現出色。該模型通過在特定數據集上的訓練和微調,展示了現有微調技術對基礎模型性能的提升效果。
🚀 快速開始
對於transformers版本v4.40.0或更高版本,建議使用 OLMo 7B Instruct HF。
此模型需要使用pip安裝 ai2-olmo
,並使用 ai2-olmo
>= 0.3.0 或 HuggingFace Transformers <= 4.39。新的模型版本將很快發佈,以改進兼容性。
安裝
快速開始推理需要進行以下安裝:
pip install ai2-olmo
推理示例
按照以下步驟使用HuggingFace進行推理:
from hf_olmo import OLMoForCausalLM, OLMoTokenizerFast
olmo = OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct")
tokenizer = OLMoTokenizerFast.from_pretrained("allenai/OLMo-7B-Instruct")
chat = [
{ "role": "user", "content": "What is language modeling?" },
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
# 可選:驗證cuda
# inputs = {k: v.to('cuda') for k,v in inputs.items()}
# olmo = olmo.to('cuda')
response = olmo.generate(input_ids=inputs.to(olmo.device), max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
>> '<|user|>\nWhat is language modeling?\n<|assistant|>\nLanguage modeling is a type of natural language processing (NLP) task or machine learning task that...'
可以通過量化模型來提高推理速度,例如:
OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct", torch_dtype=torch.float16, load_in_8bit=True)
(需要安裝 bitsandbytes
)。量化模型對輸入類型和cuda更敏感,建議將輸入作為 inputs.input_ids.to('cuda')
傳遞,以避免潛在問題。
⚠️ 重要提示
如果
ai2-olmo
安裝不正確,可能會看到以下錯誤,這是由內部Python檢查命名引起的。我們將盡快更新代碼,使錯誤信息更清晰。
raise ImportError(
ImportError: This modeling file requires the following packages that were not found in your environment: hf_olmo. Run `pip install hf_olmo`
✨ 主要特性
- OLMo是一系列開放語言模型,旨在推動語言模型科學的發展。
- 基礎模型在 Dolma 數據集上訓練,適應版本在 Tulu SFT mixture 和 UltraFeedback數據集 上訓練。
- 發佈了所有代碼、檢查點、日誌(即將發佈)以及訓練這些模型的詳細信息。
- OLMo 7B Instruct和OLMo SFT是為更好的問答性能而訓練的適應版本,展示了基礎模型通過現有微調技術可實現的性能提升。
📦 安裝指南
使用pip安裝 ai2-olmo
:
pip install ai2-olmo
💻 使用示例
基礎用法
from hf_olmo import OLMoForCausalLM, OLMoTokenizerFast
olmo = OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct")
tokenizer = OLMoTokenizerFast.from_pretrained("allenai/OLMo-7B-Instruct")
chat = [
{ "role": "user", "content": "What is language modeling?" },
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
# 可選:驗證cuda
# inputs = {k: v.to('cuda') for k,v in inputs.items()}
# olmo = olmo.to('cuda')
response = olmo.generate(input_ids=inputs.to(olmo.device), max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
高級用法
量化模型以提高推理速度:
OLMoForCausalLM.from_pretrained("allenai/OLMo-7B-Instruct", torch_dtype=torch.float16, load_in_8bit=True)
📚 詳細文檔
模型詳情
模型版本
發佈了兩個適應模型版本:
模型 | 訓練方法 | 數據集 | 上下文長度 |
---|---|---|---|
OLMo 7B SFT | SFT | Tulu 2 SFT Mix | 2048 |
OLMo 7B Instruct | SFT + DPO | Tulu 2 SFT Mix + Ultrafeedback Cleaned | 2048 |
相關基礎模型信息如下:
大小 | 訓練令牌數 | 層數 | 隱藏層大小 | 注意力頭數 | 上下文長度 |
---|---|---|---|---|---|
OLMo 1B | 3萬億 | 16 | 2048 | 16 | 2048 |
OLMo 7B | 2.5萬億 | 32 | 4096 | 32 | 2048 |
OLMo 7B Twin 2T | 2萬億 | 32 | 4096 | 32 | 2048 |
模型描述
- 開發者:Allen Institute for AI (AI2)
- 支持方:Databricks、哈佛大學Kempner Institute for the Study of Natural and Artificial Intelligence、AMD、CSC (Lumi Supercomputer)、UW
- 模型類型:Transformer風格的自迴歸語言模型
- 語言:英語
- 許可證:代碼和模型根據Apache 2.0許可證發佈
- 聯繫方式:技術諮詢:
olmo at allenai dot org
;媒體諮詢:press at allenai dot org
- 數據截止日期:基於Dolma數據集版本,截止到2023年2月/3月
模型資源
- 項目頁面:https://allenai.org/olmo
- 倉庫:
- 核心倉庫(訓練、推理、微調等):https://github.com/allenai/OLMo
- 評估代碼:https://github.com/allenai/OLMo-Eval
- 進一步微調代碼:https://github.com/allenai/open-instruct
- 論文:鏈接
- 技術博客文章:https://blog.allenai.org/olmo-open-language-model-87ccfc95f580
- W&B日誌:https://wandb.ai/ai2-llm/OLMo-7B/reports/OLMo-7B--Vmlldzo2NzQyMzk5
評估
7B適應模型的核心評估結果如下:
模型 | MMLU 0-shot ↑ | AlpacaEval %win ↑ | ToxiGen % Toxic ↓ | TruthfulQA %Info+True ↑ |
---|---|---|---|---|
OLMo (基礎模型) | 28.3 | - | 81.4 | 31.6 |
MPT Chat | 33.8 | 46.8 | 0.1 | 42.7 |
Falcon Instruct | 25.2 | 14.0 | 70.7 | 27.2 |
RPJ-INCITE Chat | 27.0 | 38.0 | 46.4 | 53.0 |
Llama-2-Chat 7B | 46.8 | 87.3 | 0.0 | 26.3 |
AI2 Tulu 2 7B | 50.4 | 73.9 | 7.0 | 51.7 |
AI2 Tulu 2 7B DPO | 50.7 | 85.1 | 0.5 | - * |
OLMo 7B SFT | 47.3 | 57.0 | 14.4 | 41.2 |
OLMo 7B Instruct | 46.2 | 69.3 | 1.7 | 52.0 |
*根據Ivison等人2023年的研究,由於測試集汙染,未報告Tulu 2的TruthfulQA分數。
數據
有關訓練數據的詳細信息,請參閱 Dolma、Tulu 2 和 UltraFeedback 的文檔。
超參數
兩個訓練階段的超參數如下:
階段 | 學習率 | Beta | 輪數 | 預熱 | 權重衰減 | 梯度裁剪 | 最大序列長度 |
---|---|---|---|---|---|---|---|
SFT | 2 × 10^-6 | N/A | 3 | 在前3%的總訓練時間內進行線性預熱,然後冷卻到0 | 0 | 0 | 2048 |
DPO | 5 × 10^-7 | 0.1 | 3 | 在前10%的總訓練時間內進行線性預熱,然後冷卻到0 | 0 | 0 | 2048 |
與Tulu 2相比,DPO超參數相同。SFT的學習率更低,輪數為3而不是2(序列長度為2k而不是8k)。
🔧 技術細節
架構
文檔未提供詳細架構信息。
訓練
模型在特定數據集上進行訓練,使用了SFT和DPO等訓練方法。
📄 許可證
代碼和模型根據Apache 2.0許可證發佈。
偏差、風險和限制
此適應的OLMo模型是研究成果,旨在造福對理解大語言模型安全特性感興趣的研究社區和為大語言模型構建安全工具的開發者。因此,該模型不包含特定的安全過濾器或安全訓練數據。儘管我們的模型在ToxiGen上的得分相對於同行較好,但模型仍有可能根據某些用戶提示生成有害和敏感內容。我們建議開發者謹慎行事,考慮該技術應用的風險。此外,開發者應在適當的時候考慮實施針對偏差、隱私和其他潛在危害的保護措施。最後,與所有大語言模型一樣,OLMo可能會產生看似事實但可能不正確的輸出,因此鼓勵開發者和用戶在依賴這些輸出之前進行確認。該模型的所有用戶都應對其使用方式負責。
引用
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: Accelerating the Science of Language Models. Preprint.
模型卡片聯繫方式
如果模型卡片存在錯誤,請聯繫Nathan或Jacob,郵箱:{nathanl, jacobm} at allenai dot org
。



