license: apache-2.0
pipeline_tag: text-generation
datasets:
- aiplanet/buddhi-dataset
language:
- en
Buddhi-128K-Chat
Buddhi-128K-Chat (7B) vLLM 推理: 

模型描述
Buddhi-128k-Chat 是一款具有 128K 上下文窗口的通用首款聊天模型。它基于 Mistral 7B Instruct 进行了精细微调,并通过创新的 YaRN(Yet another Rope Extension)技术优化,可处理长达 128,000 个标记的扩展上下文长度。这一增强功能使 Buddhi 能够在长文档或对话中保持对上下文的深入理解,尤其擅长需要广泛上下文保留的任务,如全面的文档摘要、详细的叙事生成和复杂的问答。
架构
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 技术,该技术推荐了位置插值的替代插值技术。其中一项实验涉及 Dynamic-YARN,建议动态调整 's' 比例因子的值。这是因为在推理过程中,序列长度在每次单词预测后会变化 1。通过将这些位置嵌入与 Mistral-7B Instruct 基础模型集成,我们实现了 128K 模型。
此外,我们在自己的数据集上对模型进行了微调,为开源社区贡献了为数不多的 128K 聊天模型之一,其推理能力优于所有同类模型。
硬件要求:
对于 128k 上下文长度
对于 32k 上下文长度
vLLM - 更快的推理
安装
!pip install vllm
!pip install flash_attn # 如果您的系统支持 Flash Attention 2
请查看 Flash Attention 2 GitHub 仓库以获取更多安装说明。
实现:
注意:运行模型的实际硬件需求大约为 70GB VRAM。出于实验目的,我们将上下文长度限制为 75K 而非 128K。这使得模型适合在 30-35 GB VRAM 中进行测试。
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] 请给我讲个笑话。 [/INST] """,
"""<s> [INST] 什么是机器学习? [/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] 请给我讲个小笑话。 [/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"输出:\n{decoded_output[len(prompt):]}")
输出
输出:
为什么科学家不相信原子?
因为它们构成了一切。
Buddi-128-Chat 的提示模板
为了充分利用指令微调,您的提示应被 [INST] 和 [/INST] 标记包围。第一个指令应以句子开始 ID 开头。后续指令则不需要。助手的生成将以句子结束标记 ID 结束。
"<s>[INST] 你最喜欢的调味品是什么? [/INST]"
"嗯,我特别喜欢新鲜的柠檬汁。它为我厨房里做的任何食物都增添了恰到好处的清爽风味!</s> "
"[INST] 你有蛋黄酱的食谱吗? [/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 |
联系我们
您可以与我们的开发者关系与社区团队安排 1:1 会议,了解如何开始使用 AI Planet 开源 LLM 和 GenAI 技术栈。在此预约会议:https://calendly.com/jaintarun
敬请关注更多更新,并参与编码革命。加入我们这段激动人心的旅程,共同推动 AI 的普及!
框架版本
- 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 }
}