language:
- en
library_name: transformers
license: apache-2.0
tags:
- gpt
- llm
- 大语言模型
- h2o-llmstudio
thumbnail: >-
https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
pipeline_tag: text-generation
概述
h2o-danube3-500m-chat是H2O.ai开发的500M参数对话微调模型。我们发布该模型的两种版本:
本模型使用H2O LLM Studio训练。
可在手机上原生全离线运行——立即通过H2O AI个人GPT体验。
模型架构
我们调整了Llama 2架构,总参数量约5亿。技术细节详见技术报告。采用词汇量32,000的Mistral分词器,最大上下文长度8,192。
模型架构参数如下:
超参数 |
值 |
网络层数 |
16 |
注意力头数 |
16 |
查询组数 |
8 |
嵌入维度 |
1536 |
词汇量 |
32000 |
序列长度 |
8192 |
使用指南
在GPU设备上使用transformers
库前,请确保已安装该库:
pip install transformers>=4.42.3
import torch
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="h2oai/h2o-danube3-500m-chat",
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{"role": "user", "content": "为什么喝水对健康如此重要?"},
]
prompt = pipe.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
res = pipe(
prompt,
return_full_text=False,
max_new_tokens=256,
)
print(res[0]["generated_text"])
该脚本会自动应用正确的提示格式:
<|prompt|>为什么喝水对健康如此重要?</s><|answer|>
也可通过以下方式运行:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "h2oai/h2o-danube3-500m-chat"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
messages = [
{"role": "user", "content": "为什么喝水对健康如此重要?"},
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(
prompt, return_tensors="pt", add_special_tokens=False
).to("cuda")
tokens = model.generate(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
min_new_tokens=2,
max_new_tokens=256,
)[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
加载量化模型。多GPU分片可通过device_map=auto
实现。
架构详情
LlamaForCausalLM(
(model): LlamaModel(
(embed_tokens): Embedding(32000, 1536, padding_idx=0)
(layers): ModuleList(
(0-15): 16 x LlamaDecoderLayer(
(self_attn): LlamaSdpaAttention(
(q_proj): Linear(in_features=1536, out_features=1536, bias=False)
(k_proj): Linear(in_features=1536, out_features=768, bias=False)
(v_proj): Linear(in_features=1536, out_features=768, bias=False)
(o_proj): Linear(in_features=1536, out_features=1536, bias=False)
(rotary_emb): LlamaRotaryEmbedding()
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=1536, out_features=4096, bias=False)
(up_proj): Linear(in_features=1536, out_features=4096, bias=False)
(down_proj): Linear(in_features=4096, out_features=1536, bias=False)
(act_fn): SiLU()
)
(input_layernorm): LlamaRMSNorm()
(post_attention_layernorm): LlamaRMSNorm()
)
)
(norm): LlamaRMSNorm()
)
(lm_head): Linear(in_features=1536, out_features=32000, bias=False)
)
基准测试
🏆 Open LLM排行榜v1
测试项目 |
准确率 |
综合平均 |
40.71 |
ARC挑战赛 |
39.25 |
Hellaswag |
61.02 |
MMLU |
26.33 |
TruthfulQA |
39.96 |
Winogrande |
61.72 |
GSM8K |
16.00 |
MT-Bench测试
首轮得分: 4.16
次轮得分: 2.40
平均得分: 3.28
免责声明
使用本仓库提供的大语言模型前,请仔细阅读以下免责声明。使用行为即表示您同意以下条款:
- 偏见与冒犯性:本模型基于多样化的互联网文本训练,可能生成包含偏见、种族歧视、冒犯性或其他不当内容。使用者需知悉并接受生成内容可能存在的偏见或不当性。开发者不支持、不认可任何此类内容或观点。
- 局限性:本模型是AI工具而非人类,可能产生错误、无意义或不相关回复。使用者需自主评估生成内容并审慎使用。
- 自担风险:使用者需对模型使用后果承担全部责任。开发者及贡献者不对因使用或误用导致的任何损害承担责任。
- 伦理要求:使用者应遵循负责任和符合伦理的使用准则。禁止将模型用于宣扬仇恨言论、歧视、骚扰等非法或有害行为。
- 问题反馈:如发现生成内容存在偏见、冒犯性等问题,请通过指定渠道向维护者报告。您的反馈将助力模型优化。
- 免责声明变更:开发者保留随时修改免责声明的权利,恕不另行通知。使用者应定期查阅以获取最新版本。
使用本模型即表示您接受本免责声明全部条款。如不同意任何条款,请立即停止使用本模型及其生成内容。