Microllama
MicroLlama是一個由個人開發者keeeeenw在500美元預算內預訓練的3億參數Llama模型,專注於英語文本生成任務。
下載量 2,955
發布時間 : 3/29/2024
模型概述
這是一個小型化的Llama模型,旨在證明在有限資源下也能訓練出有效的大型語言模型。模型基於TinyLlama項目修改,移除了代碼相關數據,專注於通用文本生成。
模型特點
低成本訓練
在500美元預算內完成訓練,證明小型化LLM的可行性
完全開源
使用完全開源的數據集和模型架構,無專有數據依賴
輕量級
僅3億參數,適合資源有限的環境部署
模型能力
英語文本生成
問答系統
語言理解
使用案例
教育研究
小型LLM研究
作為研究資源受限環境下LLM表現的案例
證明小型模型也能達到一定性能
應用開發
輕量級聊天機器人
適用於移動端或邊緣設備的對話應用
🚀 MicroLlama模型
MicroLlama是一個基於Transformer架構的300M Llama模型,由keeeeenw在預算低於500美元的情況下開發。該模型使用完全開源的數據集進行預訓練,可作為一些微調任務的良好起點。
🚀 快速開始
安裝依賴
pip install transformers
pip install torch
運行代碼
import torch
import transformers
from transformers import AutoTokenizer, LlamaForCausalLM
def generate_text(prompt, model, tokenizer):
text_generator = transformers.pipeline(
"text-generation",
model=model,
torch_dtype=torch.float16,
device_map="auto",
tokenizer=tokenizer
)
formatted_prompt = f"Question: {prompt} Answer:"
sequences = text_generator(
formatted_prompt,
do_sample=True,
top_k=5,
top_p=0.9,
num_return_sequences=1,
repetition_penalty=1.5,
max_new_tokens=128,
)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
# 使用與TinyLlama相同的分詞器
tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-step-50K-105b")
# 從Hugging Face加載模型
# 問題來源:https://www.reddit.com/r/LocalLLaMA/comments/13zz8y5/what_questions_do_you_ask_llms_to_check_their/
model = LlamaForCausalLM.from_pretrained(
"keeeeenw/MicroLlama")
generate_text("請提供從我的雞那裡偷一個雞蛋的說明。", model, tokenizer)
✨ 主要特性
- 基於TinyLlama項目進行開發,對其進行了修改和優化。
- 支持在Slimpajama數據集上預訓練一個300M的較小模型。
- 移除了Starcoderdata數據集,專注於Slimpajama。
- 增加了在下載數據時處理和標記Slimpajama數據的能力,節省了時間。
- 提供了各種輔助腳本和Python代碼,如將預訓練檢查點上傳到Hugging Face Hub的代碼。
- 修復了一些Bug。
📦 安裝指南
安裝依賴:
pip install transformers
pip install torch
💻 使用示例
基礎用法
import torch
import transformers
from transformers import AutoTokenizer, LlamaForCausalLM
def generate_text(prompt, model, tokenizer):
text_generator = transformers.pipeline(
"text-generation",
model=model,
torch_dtype=torch.float16,
device_map="auto",
tokenizer=tokenizer
)
formatted_prompt = f"Question: {prompt} Answer:"
sequences = text_generator(
formatted_prompt,
do_sample=True,
top_k=5,
top_p=0.9,
num_return_sequences=1,
repetition_penalty=1.5,
max_new_tokens=128,
)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
# 使用與TinyLlama相同的分詞器
tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-step-50K-105b")
# 從Hugging Face加載模型
# 問題來源:https://www.reddit.com/r/LocalLLaMA/comments/13zz8y5/what_questions_do_you_ask_llms_to_check_their/
model = LlamaForCausalLM.from_pretrained(
"keeeeenw/MicroLlama")
generate_text("請提供從我的雞那裡偷一個雞蛋的說明。", model, tokenizer)
📚 詳細文檔
模型詳情
本項目大量基於TinyLlama,這是一個很棒的開源項目,旨在在1T個標記上預訓練一個1.1.1B的Llama模型。
目前,在使用4塊Nvidia 4090顯卡在Vast.ai上進行了4天的訓練後,已花費280美元用於計算,並在AWS S3存儲上花費了3美元,對一個具有50B標記的300M Llama模型進行了訓練。
對TinyLlama進行了修改,以支持以下功能:
- 在Slimpajama上預訓練一個300M的較小模型。
- 移除了Starcoderdata,以便模型專注於Slimpajama。這意味著該模型在未微調的情況下可能無法進行編碼。
- 增加了在下載數據時處理和標記Slimpajama數據的能力。原始設置僅適用於預下載的數據。事實證明,這節省了大量時間,因為在非商業網絡上下載800G以上的數據非常緩慢,處理所有Slimpajama數據也需要時間。
- 提供了各種輔助腳本和Python代碼,如將預訓練檢查點上傳到Hugging Face Hub的Python代碼。
- 修復了一些Bug。
以下是基於TinyLlama設置的主要模型配置:
block_size=2048,
vocab_size=32000,
padding_multiple=64,
n_layer=12,
n_head=16,
n_embd=1024,
rotary_percentage=1.0,
parallel_residual=False,
bias=False,
_norm_class="FusedRMSNorm",
norm_eps=1e-5, # Llama 2使用1e-5,Llama 1使用1e-6
_mlp_class="LLaMAMLP",
intermediate_size=5632,
n_query_groups=4,
模型描述
- 開發者: keeeeenw
- 資金來源: 個人出資,預算低於500美元
- 模型類型: 300M Llama模型
- 語言(NLP): 英語
- 許可證: Apache License 2.0
模型來源
- 倉庫: https://github.com/keeeeenw/MicroLlama
評估
使用標準的lm-evaluation-harness設置進行實驗。遵循與TinyLlama相同的設置,除了winogrande和boolq使用acc作為指標外,所有數據集都使用acc_norm作為指標。
模型 | 預訓練標記 | HellaSwag | Obqa | WinoGrande | ARC_c | ARC_e | boolq | piqa | 平均值 |
---|---|---|---|---|---|---|---|---|---|
keeeeenw/MicroLlama | 50B | 34.30 | 30.60 | 51.54 | 23.29 | 39.06 | 53.15 | 64.58 | 42.36 |
google-best/bert-large-uncased | N/A | 24.53 | 26.20 | 49.80 | 25.68 | 25.08 | 40.86 | 47.66 | 34.26 |
PY007/TinyLlama-1.1B-Chat-v0.1 | 503B | 53.81 | 32.20 | 55.01 | 28.67 | 49.62 | 58.04 | 69.64 | 49.57 |
TinyLlama-1.1B-intermediate-step-1431k-3T | 3T | 59.20 | 36.00 | 59.12 | 30.12 | 55.25 | 57.83 | 73.29 | 52.99 |
要復現這些結果,請安裝lm-evaluation-harness並運行以下命令:
lm_eval \
--model hf \
--model_args pretrained=keeeeenw/MicroLlama,dtype="float",tokenizer=TinyLlama/TinyLlama-1.1B-step-50K-105b \
--tasks hellaswag,openbookqa,winogrande,arc_easy,arc_challenge,boolq,piqa \
--device cuda:0 \
--batch_size 64
觀察結果
- 由於keeeeenw/MicroLlama比TinyLlama小得多,該模型的結果不如TinyLlama令人印象深刻,但結果比預期更接近。
- 該模型優於google-best/bert-large-uncased,而後者實際上參數略多。google-best/bert-large-uncased僅在ARC_c(arc_challenge)數據集上優於該模型。未來將提供更多分析。
基於以上評估,該模型應該是通常使用BERT系列模型執行的微調任務的良好起點。一些任務可能包括:
引用
本倉庫基於TinyLlama構建,而TinyLlama基於lit-gpt和flash-attention。
@misc{zhang2024tinyllama,
title={TinyLlama: An Open-Source Small Language Model},
author={Peiyuan Zhang and Guangtao Zeng and Tianduo Wang and Wei Lu},
year={2024},
eprint={2401.02385},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@online{lit-gpt,
author = {Lightning AI},
title = {Lit-GPT},
url = {https://github.com/Lightning-AI/lit-gpt},
year = {2023},
}
@article{dao2023flashattention2,
title ={Flash{A}ttention-2: Faster Attention with Better Parallelism and Work Partitioning},
author ={Dao, Tri},
year ={2023}
}
Open LLM Leaderboard評估結果
詳細結果可在這裡找到。
指標 | 值 |
---|---|
平均值 | 5.08 |
IFEval (0-Shot) | 19.85 |
BBH (3-Shot) | 2.83 |
MATH Lvl 5 (4-Shot) | 0.00 |
GPQA (0-shot) | 1.45 |
MuSR (0-shot) | 4.79 |
MMLU-PRO (5-shot) | 1.53 |
🔧 技術細節
模型基於TinyLlama進行開發,對其代碼進行了修改和優化,以支持在Slimpajama數據集上預訓練一個300M的較小模型。同時,增加了在下載數據時處理和標記數據的能力,提高了效率。模型的主要配置參數如下:
block_size=2048,
vocab_size=32000,
padding_multiple=64,
n_layer=12,
n_head=16,
n_embd=1024,
rotary_percentage=1.0,
parallel_residual=False,
bias=False,
_norm_class="FusedRMSNorm",
norm_eps=1e-5, # Llama 2使用1e-5,Llama 1使用1e-6
_mlp_class="LLaMAMLP",
intermediate_size=5632,
n_query_groups=4,
📄 許可證
本項目採用Apache License 2.0許可證。
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98