🚀 Buddhi-128K-Chat
Buddhi-128K-Chat是一款通用型聊天模型,擁有128K的上下文長度窗口。它基於Mistral 7B Instruct進行精細微調,並採用創新的YaRN技術,能夠處理長達128,000個標記的上下文,在長文檔理解和對話處理方面表現出色。
🚀 快速開始
你可以點擊下面的鏈接在Colab中運行Buddhi-128K-Chat模型的推理代碼:

閱讀發佈文章:🔗 介紹Buddhi:具有128K上下文窗口的開源聊天模型 🔗

✨ 主要特性
- 長上下文處理能力:具備128K的上下文長度窗口,能夠深入理解長文檔或對話的上下文,適用於文檔總結、敘事生成和複雜問答等任務。
- 精細微調:在Mistral 7B Instruct基礎上進行精細微調,繼承了其優秀的推理能力。
- 創新技術應用:採用YaRN技術擴展上下文長度,有效提升模型性能。
📦 安裝指南
vLLM - 加速推理
!pip install vllm
!pip install flash_attn # 如果你的系統支持Flash Attention 2
請查看 Flash Attention 2 的GitHub倉庫獲取更多安裝說明。
硬件要求
⚠️ 重要提示
- 128k上下文長度:建議使用80GB VRAM的A100 GPU。
- 32k上下文長度:建議使用40GB VRAM的A100 GPU。
💻 使用示例
vLLM - 加速推理
from vllm import LLM, SamplingParams
llm = LLM(
model='aiplanet/buddhi-128k-chat-7b',
trust_remote_code=True,
dtype = 'bfloat16',
gpu_memory_utilization=1,
max_model_len= 75000
)
prompts = [
"""<s> [INST] Please tell me a joke. [/INST] """,
"""<s> [INST] What is Machine Learning? [/INST] """
]
sampling_params = SamplingParams(
temperature=0.8,
top_p=0.95,
max_tokens=1000
)
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(generated_text)
print("\n\n")
查看輸出結果,請點擊Colab筆記本鏈接: 
Transformers - 基礎實現
import torch
import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
model_name = "aiplanet/Buddhi-128K-Chat"
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
device_map="sequential",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
model,
trust_remote_code=True
)
prompt = "<s> [INST] Please tell me a small joke. [/INST] "
tokens = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
**tokens,
max_new_tokens=100,
do_sample=True,
top_p=0.95,
temperature=0.8,
)
decoded_output = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
print(f"Output:\n{decoded_output[len(prompt):]}")
輸出結果
Output:
Why don't scientists trust atoms?
Because they make up everything.
📚 詳細文檔
Buddhi-128K-Chat的提示模板
為了利用指令微調,你的提示應該用 [INST] 和 [/INST] 標記包圍。第一條指令應該以句子開始標記開頭,後續指令則不需要。助手的生成結果將以句子結束標記結束。
"<s>[INST] What is your favourite condiment? [/INST]"
"Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> "
"[INST] Do you have mayonnaise recipes? [/INST]"
基準測試
長上下文基準測試
LongICLBench Banking77
模型 |
1R/2k |
2R/4K |
3R/7K |
4R/9K |
5R/14K |
aiplanet/buddhi-128k-chat-7b |
47.8 |
60.8 |
57.8 |
62.4 |
57.2 |
NousResearch/Yarn-Mistral-7b-128k |
31.6 |
68.6 |
68 |
47 |
65.6 |
CallComply/zephyr-7b-beta-128k |
40.2 |
41.2 |
33.6 |
03 |
0 |
Eric111/Yarn-Mistral-7b-128k-DPO |
28.6 |
62.8 |
58 |
41.6 |
59.8 |
短上下文基準測試
模型 |
# 參數 |
平均 |
ARC (25-shot) |
HellaSwag (10-shot) |
Winogrande (5-shot) |
TruthfulOA (0-shot) |
MMLU (5-shot) |
aiplanet/buddhi-128k-chat-7b |
7B |
64.42 |
60.84 |
84 |
77.27 |
65.72 |
60.42 |
migtissera/Tess-XS-vl-3-yarn-128K |
7B |
62.66 |
61.09 |
82.95 |
74.43 |
50.13 |
62.15 |
migtissera/Tess-XS-v1-3-yarn-128K |
7B |
62.49 |
61.6 |
82.96 |
74.74 |
50.2 |
62.1 |
Eric111/Yarn-Mistral-7b-128k-DPO |
7B |
60.15 |
60.84 |
82.99 |
78.3 |
43.55 |
63.09 |
NousResearch/Yam-Mistral-7b-128k |
7B |
59.42 |
59.64 |
82.5 |
76.95 |
41.78 |
63.02 |
CallComply/openchat-3.5-0106-128k |
7B |
59.38 |
64.25 |
77.31 |
77.66 |
46.5 |
57.58 |
CallComply/zephyr-7b-beta-128k |
7B |
54.45 |
58.28 |
81 |
74.74 |
46.1 |
53.57 |
🔧 技術細節
架構
Buddhi-128K-Chat模型是在Mistral-7B Instruct基礎模型上進行微調的。我們選擇Mistral 7B Instruct v0.2作為父模型,是因為它具有出色的推理能力。Mistral-7B模型的架構包括分組查詢注意力(Grouped-Query Attention)和字節回退BPE分詞器(Byte-fallback BPE tokenizer)。該模型最初的最大位置嵌入為32,768。為了將上下文大小增加到128K,我們需要修改位置嵌入,這就是YaRN技術發揮作用的地方。
在我們的方法中,我們使用了NTK-aware技術,該技術推薦了用於位置插值的替代插值技術。其中一個實驗涉及動態YaRN(Dynamic-YARN),建議使用動態的 's' 縮放因子。這是因為在推理過程中,每個單詞預測後序列長度會增加1。通過將這些位置嵌入與Mistral-7B Instruct基礎模型集成,我們實現了128K的模型。
此外,我們在自己的數據集上對模型進行了微調,使其成為開源社區中少數幾個具有128K上下文長度的聊天模型之一,並且推理能力優於其他同類模型。
框架版本
- Transformers 4.39.2
- Pytorch 2.2.1+cu121
- Datasets 2.18.0
- Accelerate 0.27.2
- flash_attn 2.5.6
引用
@misc {Chaitanya890, lucifertrj ,
author = { Chaitanya Singhal, Tarun Jain },
title = { Buddhi-128k-Chat by AI Planet},
year = 2024,
url = { https://huggingface.co/aiplanet//Buddhi-128K-Chat },
publisher = { Hugging Face }
}
📄 許可證
本項目採用Apache-2.0許可證。
🤝 聯繫我們
你可以與我們的開發者關係和社區團隊安排一對一會議,以開始使用AI Planet的開源大語言模型和生成式AI棧。點擊以下鏈接安排會議:https://calendly.com/jaintarun
請持續關注我們的更新,加入我們的編碼進化之旅!在AI Planet,我們致力於讓每個人都能輕鬆使用AI技術。