语言:
- 英文
库名称: transformers
标签:
- GPT
- 大语言模型
- H2O-LLMStudio
推理: false
缩略图: >-
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.28.1
pip install accelerate==0.18.0
pip install torch==2.0.0
import torch
from transformers import pipeline
generate_text = pipeline(
model="h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b-preview-700bt",
torch_dtype=torch.float16,
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|>
如果不希望使用trust_remote_code=True
,可以下载h2oai_pipeline.py,将其与笔记本文件存放在同一目录下,然后自行从加载的模型和分词器构建管道:
import torch
from h2oai_pipeline import H2OTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b-preview-700bt",
use_fast=False,
padding_side="left"
)
model = AutoModelForCausalLM.from_pretrained(
"h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b-preview-700bt",
torch_dtype=torch.float16,
device_map={"": "cuda:0"}
)
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-7b-preview-700bt"
prompt = "<|prompt|>你好吗?</s><|answer|>"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_name)
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, 4096, padding_idx=0)
(layers): ModuleList(
(0-31): 32 x LlamaDecoderLayer(
(self_attn): LlamaAttention(
(q_proj): Linear(in_features=4096, out_features=4096, bias=False)
(k_proj): Linear(in_features=4096, out_features=4096, bias=False)
(v_proj): Linear(in_features=4096, out_features=4096, bias=False)
(o_proj): Linear(in_features=4096, out_features=4096, bias=False)
(rotary_emb): LlamaRotaryEmbedding()
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
(down_proj): Linear(in_features=11008, out_features=4096, bias=False)
(up_proj): Linear(in_features=4096, out_features=11008, bias=False)
(act_fn): SiLUActivation()
)
(input_layernorm): LlamaRMSNorm()
(post_attention_layernorm): LlamaRMSNorm()
)
)
(norm): LlamaRMSNorm()
)
(lm_head): Linear(in_features=4096, out_features=32000, bias=False)
)
模型配置
该模型使用H2O LLM Studio训练,配置见cfg.yaml。访问H2O LLM Studio了解如何训练自己的大语言模型。
模型验证
使用EleutherAI lm-evaluation-harness进行的模型验证结果。
CUDA_VISIBLE_DEVICES=0 python main.py --model hf-causal-experimental --model_args pretrained=h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b-preview-700bt --tasks openbookqa,arc_easy,winogrande,hellaswag,arc_challenge,piqa,boolq --device cuda &> eval.log
免责声明
在使用本仓库提供的大语言模型前,请仔细阅读以下免责声明。使用该模型即表示您同意以下条款和条件。
- 偏见与冒犯性内容:大语言模型基于多样化的互联网文本数据训练,可能包含偏见、种族歧视、冒犯性或其他不当内容。使用该模型即表示您承认并接受生成内容可能偶尔会表现出偏见或产生冒犯性、不当内容。本仓库开发者不认可、不支持或推广任何此类内容或观点。
- 局限性:大语言模型是基于AI的工具而非人类,可能产生错误、无意义或不相关的回应。用户需对生成内容进行批判性评估并自行决定使用方式。
- 风险自担:用户必须对使用该大语言模型可能产生的任何后果承担全部责任。本仓库开发者及贡献者不对因使用或滥用该模型导致的任何损害、损失或伤害承担责任。
- 道德考量:鼓励用户以负责任和符合道德的方式使用大语言模型。使用该模型即表示您同意不将其用于宣扬仇恨言论、歧视、骚扰或任何非法及有害活动。
- 问题报告:如发现大语言模型生成任何具有偏见、冒犯性或不当内容,请通过指定渠道向仓库维护者报告。您的反馈将帮助改进模型并缓解潜在问题。
- 免责声明变更:本仓库开发者保留随时修改或更新本免责声明的权利,恕不另行通知。用户有责任定期查阅免责声明以了解变更内容。
使用本仓库提供的大语言模型即表示您接受并同意遵守本免责声明中概述的条款和条件。如不同意本免责声明的任何部分,您应停止使用该模型及其生成内容。