模型概述
模型特點
模型能力
使用案例
🚀 Colossal-LLaMA-2-7B
Colossal-LLaMA-2-7B是基於LLaMA-2開發的開源模型,經過持續預訓練,在中英文評估指標上表現出色,且成本較低,可用於構建特定領域知識或任務的模型。
🚀 快速開始
加載模型
使用以下代碼加載Colossal-LLaMA-2-7B-base模型:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("hpcai-tech/Colossal-LLaMA-2-7b-base", device_map="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("hpcai-tech/Colossal-LLaMA-2-7b-base", trust_remote_code=True)
input = "明月松間照,\n\n->\n\n"
inputs = tokenizer(input, return_tensors='pt')
inputs = inputs.to('cuda:0')
pred = model.generate(**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.3,
top_k=50,
top_p=0.95,
num_return_sequences=1)
print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True)[len(input):])
✨ 主要特性
- 開源模型:基於LLaMA-2開發的開源模型Colossal-LLaMA-2-7B-base。
- 成本效益高:經過約85億個token的持續預訓練,僅需64塊A800 GPU訓練15小時,成本不到1000美元,卻能達到數百萬美元從頭預訓練的效果。
- 多語言支持:支持中文和英文,上下文窗口達4096個token。
- 性能出色:在標準中英文評估指標(如C-Eval和MMLU)上表現優異。
📚 詳細文檔
模型介紹
Colossal-AI團隊推出了開源模型Colossal-LLaMA-2-7B-base。該模型基於LLaMA-2,經過約85億個token的持續預訓練,使用64塊A800 GPU訓練了15小時。成本不到1000美元,卻能達到數百萬美元從頭預訓練的效果。它遵循LLaMA-2許可證和Apache 2.0許可證,無額外商業使用限制,可用於構建特定領域知識或任務的模型。
Colossal-LLaMA-2-7B-base支持中文和英文,上下文窗口達4096個token,在標準中英文評估指標(如C-Eval和MMLU)上表現出色。
性能評估
我們在4個數據集上進行了全面評估,並將Colossal-Llama-2-7b-base模型與多種模型進行了比較。
- MMLU和CMMLU使用5-shot,根據第一個預測token的logits計算分數。
- AGIEval使用5-shot,僅計算4選1問題的分數,採用精確匹配和第一個預測token的logits組合指標。
- GAOKAO-Bench使用0-shot,僅根據第一個預測token的logits計算4選1問題的分數。
- 所有數據集的生成配置均為貪心搜索。
- 我們還提供了CEval分數,來自其最新排行榜或模型的官方倉庫。
更多指標詳情可參考Metrics。
屬性 | 詳情 |
---|---|
模型類型 | Colossal-LLaMA-2-7B-base |
訓練數據 | 約85億個token |
| 模型 | 骨幹網絡 | 消耗的token數 | MMLU (5-shot) | CMMLU (5-shot) | AGIEval (5-shot) | GAOKAO (0-shot) | CEval (5-shot) | | :----------------------------: | :--------: | :-------------: | :------------------: | :-----------: | :-----: | :----: | :----: | :----------------------------: | | | - | - | | | | | | | Baichuan-7B | - | 1.2T | 42.32 (42.30) | 44.53 (44.02) | 38.72 | 36.74 | 42.80 | | Baichuan2-7B-Base | - | 2.6T | 46.97 (54.16) | 57.67 (57.07) | 45.76 | 52.60 | 54.00 | | ChatGLM-6B | - | 1.0T | 39.67 (40.63) | 41.17 (-) | 40.10 | 36.53 | 38.90 | | ChatGLM2-6B | - | 1.4T | 44.74 (45.46) | 49.40 (-) | 46.36 | 45.49 | 51.70 | | InternLM-7B | - | - | 46.70 (51.00) | 52.00 (-) | 44.77 | 61.64 | 52.80 | | Qwen-7B (original) | - | 2.2T | 54.29 (56.70) | 56.03 (58.80) | 52.47 | 56.42 | 59.60 | | Qwen-7B | - | 2.4T | 58.33 (58.20) | 62.54 (62.20) | 64.34 | 74.05 | 63.50 | | Llama-2-7B | - | 2.0T | 44.47 (45.30) | 32.97 (-) | 32.60 | 25.46 | - | | Linly-AI/Chinese-LLaMA-2-7B-hf | Llama-2-7B | 1.0T | 37.43 | 29.92 | 32.00 | 27.57 | - | | wenge-research/yayi-7b-llama2 | Llama-2-7B | - | 38.56 | 31.52 | 30.99 | 25.95 | - | | ziqingyang/chinese-llama-2-7b | Llama-2-7B | - | 33.86 | 34.69 | 34.52 | 25.18 | 34.2 | | TigerResearch/tigerbot-7b-base | Llama-2-7B | 0.3T | 43.73 | 42.04 | 37.64 | 30.61 | - | | LinkSoul/Chinese-Llama-2-7b | Llama-2-7B | - | 48.41 | 38.31 | 38.45 | 27.72 | - | | FlagAlpha/Atom-7B | Llama-2-7B | 0.1T | 49.96 | 41.10 | 39.83 | 33.00 | - | | Colossal-LLaMA-2-7b-base | Llama-2-7B | 0.0085T | 53.06 | 49.89 | 51.48 | 58.82 | 50.20 |
括號內的分數對應模型官方倉庫中的分數。
ChatGLM模型使用零樣本。
評估Qwen-7B在MMLU數據集上的表現時,提示語為"xxx Answer:"(去掉":"後的空格),我們計算Qwen-7B在" A"、" B"、" C"和" D"上的logits。Qwen-7B的原始版本和更新版本都比其他模型更具確定性。例如," A"的logits可能為
-inf
,softmax值為0
。對於其他模型和其他數據集,我們計算" A"、" B"、" C"和" D"上的logits。
❗️ 更多評估方法和結果復現的詳細信息,請參考ColossalEval。
技術細節
數據
為了提高LLaMA-2理解和生成中文內容的能力,Colossal-AI團隊提出使用中英文語料對LLaMA-2模型進行持續預訓練。
大型語言模型(如LLaMA-2)使用多種高質量數據集進行訓練,取得了不錯的效果。提高LLaMA-2在中文語料上的性能,同時保持其英語能力,關鍵在於數據集的組成(包括中英文內容)和每個子數據集的質量。
下圖展示了Colossal-LLaMA-2的數據處理流程:
❗️ 重要提示:我們即將開源數據處理工具包,請持續關注!
分詞器
原始的LLaMA-2詞表包含的中文字符少於1000個,無法有效編碼完整的中文文本。其次,字節token的使用使Transformer編碼器難以捕捉中文字符的語義細微差別。
為解決上述問題,我們將LLaMA-2的詞表從32000擴展到69104。為使LLaMA-2模型適應Colossal-LLaMA-2分詞器,我們通過計算原始LLaMA-2嵌入的均值來初始化新的詞嵌入,並將這些新行添加到原始嵌入矩陣的末尾。
擴展詞表大小的優點:
- 提高字符串序列編碼的壓縮率。
- 增強信息的完整性。
- 使編碼序列包含更多有價值的信息,從而理論上提高章節級編碼能力。
在低資源設置下大詞表的優點:
- 大量未使用的token可能是由於訓練數據集有限,過多的token可能未被有效學習。
- 過度擴展詞表會增加嵌入相關參數,導致更高的內存使用,進而影響訓練效率。
為平衡兩者,我們最終構建了大小為69104的詞表。下表展示了7B級別的各種模型的比較:
模型 | 詞表大小 | 壓縮率 | 樣本平均長度(token級) |
---|---|---|---|
Colossal-LLaMA-2 | 69104 | 0.659 | 73.682 |
LLaMA-2-7B | 32000 | 1.205 | 134.689 |
Atom-7B | 65000 | 0.634 | 70.915 |
Baichuan-7B | 64000 | 0.678 | 75.857 |
Baichuan2-7B-base | 125696 | 0.570 | 63.761 |
Chatglm2-6B | 64789 | 0.645 | 72.178 |
InternLM-7B | 103168 | 0.566 | 63.349 |
Qwen-7B | 151643 | 0.578 | 64.703 |
Tigerbot-7B-base | 60515 | 0.630 | 70.515 |
Yayi-7B-llama2 | 32005 | 1.214 | 135.689 |
Chinese-llama-2-7b | 55296 | 0.668 | 74.690 |
Chinese-Falcon-7B | 90046 | 0.669 | 74.858 |
LinkSoul-Chinese-Llama-2-7b | 40076 | 0.958 | 107.089 |
Ziya-LLaMA-13B-v1.1 | 39410 | 0.958 | 107.074 |
訓練日誌
以下是我們實驗的訓練日誌:
訓練策略
多階段訓練
為提高模型性能並充分發揮原始LLaMA-2的潛力,我們開發了多階段訓練策略,旨在分階段系統地解鎖模型能力。
因此,我們將訓練過程分為三個階段:
- 大規模預訓練階段(由LLaMA-2完成):此初始階段旨在從頭建立模型的基礎能力,需要使用不少於1萬億個token的大量數據集。
- 中文知識注入階段:在此階段,我們向模型中引入中文知識,需要訪問富含中文綜合知識的高質量數據集。
- 知識回放階段:通過問答(QA)機制回放知識,涵蓋中英文領域。
完成多階段訓練後,模型在中英文基準測試中的性能均有顯著提升。
下圖展示了Colossal-LLaMA-2的三個訓練階段:
基於桶的訓練
我們的實驗表明,訓練數據集中的分佈以及各種主題相關數據點的排列,對模型的整體性能有顯著影響,特別是在LLaMA-2的持續預訓練中。
為實現更平衡的分佈並控制數據集的順序,我們採用了將每個子數據集劃分為離散箱的方法。這些箱然後組合成單個數據桶,每個子數據集貢獻一個箱。
更多細節請參考我們的Github。
侷限性
Colossal-LLaMA-2-7B是LLaMA-2的衍生模型,使用時存在風險。到目前為止,測試僅在中英文語言中進行,需要承認它無法涵蓋所有可能的場景。與其他大語言模型一樣,無法提前預測Colossal-LLaMA-2-7B-base的潛在結果。在某些情況下,Colossal-LLaMA-2-7B-base可能會生成不準確、有偏見或有害的響應。因此,在部署任何由Colossal-LLaMA-2-7B-base驅動的應用程序之前,開發人員必須進行安全測試和調優,使模型滿足其應用程序的特定要求。
引用
@article{bian2021colossal,
title={Colossal-AI: A Unified Deep Learning System For Large-Scale Parallel Training},
author={Bian, Zhengda and Liu, Hongxin and Wang, Boxiang and Huang, Haichen and Li, Yongbin and Wang, Chuanrui and Cui, Fan and You, Yang},
journal={arXiv preprint arXiv:2110.14883},
year={2021}
}
@misc{touvron2023llama,
title={Llama 2: Open Foundation and Fine-Tuned Chat Models},
author={Hugo Touvron and Louis Martin and Kevin Stone and Peter Albert and Amjad Almahairi and Yasmine Babaei and Nikolay Bashlykov and Soumya Batra and Prajjwal Bhargava and Shruti Bhosale and Dan Bikel and Lukas Blecher and Cristian Canton Ferrer and Moya Chen and Guillem Cucurull and David Esiobu and Jude Fernandes and Jeremy Fu and Wenyin Fu and Brian Fuller and Cynthia Gao and Vedanuj Goswami and Naman Goyal and Anthony Hartshorn and Saghar Hosseini and Rui Hou and Hakan Inan and Marcin Kardas and Viktor Kerkez and Madian Khabsa and Isabel Kloumann and Artem Korenev and Punit Singh Koura and Marie-Anne Lachaux and Thibaut Lavril and Jenya Lee and Diana Liskovich and Yinghai Lu and Yuning Mao and Xavier Martinet and Todor Mihaylov and Pushkar Mishra and Igor Molybog and Yixin Nie and Andrew Poulton and Jeremy Reizenstein and Rashi Rungta and Kalyan Saladi and Alan Schelten and Ruan Silva and Eric Michael Smith and Ranjan Subramanian and Xiaoqing Ellen Tan and Binh Tang and Ross Taylor and Adina Williams and Jian Xiang Kuan and Puxin Xu and Zheng Yan and Iliyan Zarov and Yuchen Zhang and Angela Fan and Melanie Kambadur and Sharan Narang and Aurelien Rodriguez and Robert Stojnic and Sergey Edunov and Thomas Scialom},
year={2023},
eprint={2307.09288},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@article{dao2023flashattention2,
title={Flash{A}ttention-2: Faster Attention with Better Parallelism and Work Partitioning},
author={Dao, Tri},
year={2023}
}
資源鏈接
|🔥 GitHub | 👾 Modelscope| 😊 Slack| 💬 WeChat|



