🚀 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技术。