语言:
- 英语
库名称: transformers
标签:
- GPT
- 大语言模型
- H2O-LLMStudio
推理: 否
缩略图: >-
https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
许可证: Apache-2.0
数据集:
- OpenAssistant/oasst1
模型卡片
概述
该模型使用H2O LLM Studio训练而成。
使用说明
在配备GPU的设备上使用transformers
库调用模型前,请确保已安装transformers
、accelerate
和torch
库。
pip install transformers==4.30.2
pip install accelerate==0.20.3
pip install torch==2.0.0
import torch
from transformers import pipeline
generate_text = pipeline(
model="h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-3b",
torch_dtype="auto",
trust_remote_code=True,
use_fast=False,
device_map={"": "cuda:0"},
)
res = generate_text(
"为什么喝水如此健康?",
min_new_tokens=2,
max_new_tokens=1024,
do_sample=False,
num_beams=1,
temperature=float(0.3),
repetition_penalty=float(1.2),
renormalize_logits=True
)
print(res[0]["generated_text"])
可通过以下代码查看预处理后的提示模板:
print(generate_text.preprocess("为什么喝水如此健康?")["prompt_text"])
<|prompt|>为什么喝水如此健康?</s><|answer|>
您也可以下载h2oai_pipeline.py脚本,通过加载的模型和分词器自行构建流水线。若模型和分词器完全受transformers
包支持,可设置trust_remote_code=False
。
import torch
from h2oai_pipeline import H2OTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-3b",
use_fast=False,
padding_side="left",
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
"h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-3b",
torch_dtype="auto",
device_map={"": "cuda:0"},
trust_remote_code=True,
)
generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
res = generate_text(
"为什么喝水如此健康?",
min_new_tokens=2,
max_new_tokens=1024,
do_sample=False,
num_beams=1,
temperature=float(0.3),
repetition_penalty=float(1.2),
renormalize_logits=True
)
print(res[0]["generated_text"])
也可自行构建流水线并考虑预处理步骤:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-3b"
prompt = "<|prompt|>你好吗?</s><|answer|>"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
use_fast=False,
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map={"": "cuda:0"},
trust_remote_code=True,
)
model.cuda().eval()
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
tokens = model.generate(
**inputs,
min_new_tokens=2,
max_new_tokens=1024,
do_sample=False,
num_beams=1,
temperature=float(0.3),
repetition_penalty=float(1.2),
renormalize_logits=True
)[0]
tokens = tokens[inputs["input_ids"].shape[1]:]
answer = tokenizer.decode(tokens, skip_special_tokens=True)
print(answer)
模型架构
LlamaForCausalLM(
(model): LlamaModel(
(embed_tokens): Embedding(32000, 3200, padding_idx=0)
(layers): ModuleList(
(0-25): 26 x LlamaDecoderLayer(
(self_attn): LlamaAttention(
(q_proj): Linear(in_features=3200, out_features=3200, bias=False)
(k_proj): Linear(in_features=3200, out_features=3200, bias=False)
(v_proj): Linear(in_features=3200, out_features=3200, bias=False)
(o_proj): Linear(in_features=3200, out_features=3200, bias=False)
(rotary_emb): LlamaRotaryEmbedding()
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=3200, out_features=8640, bias=False)
(down_proj): Linear(in_features=8640, out_features=3200, bias=False)
(up_proj): Linear(in_features=3200, out_features=8640, bias=False)
(act_fn): SiLUActivation()
)
(input_layernorm): LlamaRMSNorm()
(post_attention_layernorm): LlamaRMSNorm()
)
)
(norm): LlamaRMSNorm()
)
(lm_head): Linear(in_features=3200, out_features=32000, bias=False)
)
模型配置
本模型使用H2O LLM Studio训练,配置详见cfg.yaml。访问H2O LLM Studio了解如何训练自定义大语言模型。
免责声明
使用本仓库提供的大语言模型前,请仔细阅读以下免责声明。使用该模型即表示您同意以下条款:
- 偏见与冒犯性内容:该大语言模型基于多样化的互联网文本数据训练,可能包含偏见、种族歧视、冒犯性或其他不当内容。您承认并同意生成内容可能偶尔会呈现偏见或产生冒犯性内容。本仓库开发者不认可、不支持或推广任何此类内容或观点。
- 局限性:大语言模型是基于AI的工具而非人类,可能产生错误、无意义或不相关的回应。用户需对生成内容进行批判性评估并自行判断使用。
- 自担风险:用户必须对使用该工具产生的任何后果承担全部责任。本仓库开发者及贡献者不对因使用或误用该模型导致的任何损害、损失或伤害承担责任。
- 道德考量:鼓励用户以负责任和符合道德的方式使用大语言模型。使用本模型即承诺不将其用于宣扬仇恨言论、歧视、骚扰或任何非法及有害活动。
- 问题反馈:如发现模型生成任何具有偏见、冒犯性或不当内容,请通过指定渠道向仓库维护者报告。您的反馈将有助于改进模型并缓解潜在问题。
- 免责声明变更:开发者保留随时修改或更新本免责声明的权利,恕不另行通知。用户有责任定期查阅以了解变更内容。
使用本仓库提供的大语言模型即表示您接受并同意遵守本免责声明所述条款。如不同意任何条款,请停止使用该模型及其生成内容。