语言:
- 英文
库名称: transformers
许可证: apache-2.0
标签:
- GPT
- 大语言模型
- H2O-LLMStudio
缩略图: https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
管道标签: 文本生成
概述
h2o-danube3.1-4b-chat 是由 H2O.ai 微调的聊天模型,拥有 40 亿参数。
该模型使用 H2O LLM Studio 训练。
可在手机上原生且完全离线运行 - 使用 H2O AI Personal GPT 亲自体验。
模型架构
我们调整了 Llama 2 架构,总计约 40 亿参数。详情请参阅我们的技术报告。我们使用词汇量为 32,000 的 Mistral 分词器,并将模型训练至上下文长度 8,192。
模型架构的详细参数如下:
超参数 |
值 |
层数 |
24 |
头数 |
32 |
查询组数 |
8 |
嵌入维度 |
3840 |
词汇量 |
32000 |
序列长度 |
8192 |
使用方式
要在配备 GPU 的机器上使用 transformers
库运行该模型,首先确保已安装 transformers
库。
pip install transformers==4.45.0
import torch
from transformers import pipeline
generate_text = pipeline(
model="h2oai/h2o-danube3.1-4b-chat",
torch_dtype=torch.bfloat16,
trust_remote_code=True,
device_map="auto",
)
messages = [
{
"role": "system",
"content": "你是一个友好礼貌的聊天机器人。",
},
{"role": "user", "content": "嗨,你好吗?"},
{"role": "assistant", "content": "我很好,你呢?"},
{"role": "user", "content": "为什么喝水这么健康?"},
]
res = generate_text(
messages,
renormalize_logits=True
)
print(res[0]["generated_text"][-1]['content'])
您可以打印应用聊天模板后的示例提示,查看其如何输入分词器:
print(generate_text.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
))
您也可以从加载的模型和分词器自行构建管道,并考虑预处理步骤:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "h2oai/h2o-danube3.1-4b-chat"
messages = [
{
"role": "system",
"content": "你是一个友好礼貌的聊天机器人。",
},
{"role": "user", "content": "嗨,你好吗?"},
{"role": "assistant", "content": "我很好,你呢?"},
{"role": "user", "content": "为什么喝水这么健康?"},
]
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
model.cuda().eval()
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
).to("cuda")
tokens = model.generate(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
renormalize_logits=True
)[0]
tokens = tokens[inputs["input_ids"].shape[1]:]
answer = tokenizer.decode(tokens, skip_special_tokens=True)
print(answer)
量化和分片
您可以通过指定 load_in_8bit=True
或 load_in_4bit=True
使用量化加载模型。此外,通过设置 device_map=auto
可在多个 GPU 上分片。
模型架构
LlamaForCausalLM(
(model): LlamaModel(
(embed_tokens): Embedding(32000, 3840, padding_idx=0)
(layers): ModuleList(
(0-23): 24 x LlamaDecoderLayer(
(self_attn): LlamaSdpaAttention(
(q_proj): Linear(in_features=3840, out_features=3840, bias=False)
(k_proj): Linear(in_features=3840, out_features=960, bias=False)
(v_proj): Linear(in_features=3840, out_features=960, bias=False)
(o_proj): Linear(in_features=3840, out_features=3840, bias=False)
(rotary_emb): LlamaRotaryEmbedding()
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=3840, out_features=10240, bias=False)
(up_proj): Linear(in_features=3840, out_features=10240, bias=False)
(down_proj): Linear(in_features=10240, out_features=3840, bias=False)
(act_fn): SiLU()
)
(input_layernorm): LlamaRMSNorm((3840,), eps=1e-05)
(post_attention_layernorm): LlamaRMSNorm((3840,), eps=1e-05)
)
)
(norm): LlamaRMSNorm((3840,), eps=1e-05)
(rotary_emb): LlamaRotaryEmbedding()
)
(lm_head): Linear(in_features=3840, out_features=32000, bias=False)
)
基准测试
🤗 Open LLM Leaderboard v2
基准测试 |
准确率 |
平均 |
16.21 |
IFEval |
50.21 |
BBH |
10.94 |
MATH Lvl 5 |
2.11 |
GPQA |
4.7 |
MUSR |
10.2 |
MML-PRO |
19.1 |
🤗 Open LLM Leaderboard v1
基准测试 |
准确率 |
平均 |
61.05 |
ARC-challenge |
57.68 |
Hellaswag |
79.05 |
MMLU |
55.61 |
TruthfulQA |
46.84 |
Winogrande |
75.93 |
GSM8K |
51.18 |
MT-Bench
第一轮: 7.394
第二轮: 5.563
平均: 6.478
免责声明
在使用本仓库提供的大语言模型前,请仔细阅读以下免责声明。使用该模型即表示您同意以下条款和条件。
- 偏见和冒犯性内容: 大语言模型基于多样化的互联网文本数据训练,可能包含偏见、种族主义、冒犯性或其他不当内容。使用该模型即表示您承认并接受生成内容有时可能表现出偏见或产生冒犯性、不当内容。本仓库开发者不认可、支持或推广任何此类内容或观点。
- 局限性: 大语言模型是基于 AI 的工具,并非人类。它可能产生不正确、无意义或不相关的回应。用户有责任批判性评估生成内容并自行决定使用方式。
- 风险自担: 使用该大语言模型的用户需自行承担由此产生的任何后果。本仓库开发者及贡献者对因使用或滥用该模型导致的任何损害、损失或伤害不承担法律责任。
- 道德考量: 鼓励用户以负责任和符合道德的方式使用大语言模型。使用该模型即表示您同意不将其用于宣扬仇恨言论、歧视、骚扰或任何非法或有害活动。
- 问题报告: 如遇到模型生成的任何偏见、冒犯性或不当内容,请通过指定渠道向仓库维护者报告。您的反馈将有助于改进模型并缓解潜在问题。
- 免责声明变更: 本仓库开发者保留随时修改或更新本免责声明的权利,恕不另行通知。用户有责任定期查阅免责声明以了解变更。
使用本仓库提供的大语言模型即表示您接受并同意遵守本免责声明中概述的条款和条件。如不同意本免责声明的任何部分,您应停止使用该模型及其生成内容。