语言:
- 英文
库名称: transformers
标签:
- GPT
- LLM
- 大语言模型
- H2O-LLMStudio
推理: 否
缩略图: https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
模型卡片
概述
该模型使用H2O LLM Studio训练而成。
使用方法
要在配备GPU的机器上使用transformers
库运行该模型,请首先确保已安装transformers
、accelerate
和torch
库。
pip install transformers==4.29.2
pip install einops==0.6.1
pip install accelerate==0.19.0
pip install torch==2.0.0
import torch
from transformers import pipeline
generate_text = pipeline(
model="Ketak-ZoomRx/Drug_Ollama_v3-2",
torch_dtype="auto",
trust_remote_code=True,
use_fast=True,
device_map={"": "cuda:0"},
)
res = generate_text(
"为什么喝水如此健康?",
min_new_tokens=2,
max_new_tokens=256,
do_sample=False,
num_beams=1,
temperature=float(0.0),
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(
"Ketak-ZoomRx/Drug_Ollama_v3-2",
use_fast=True,
padding_side="left",
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
"Ketak-ZoomRx/Drug_Ollama_v3-2",
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=256,
do_sample=False,
num_beams=1,
temperature=float(0.0),
repetition_penalty=float(1.2),
renormalize_logits=True
)
print(res[0]["generated_text"])
您也可以自行从加载的模型和分词器构建管道,并考虑预处理步骤:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Ketak-ZoomRx/Drug_Ollama_v3-2"
prompt = "<|prompt|>你好吗?</s><|answer|>"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
use_fast=True,
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(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
min_new_tokens=2,
max_new_tokens=256,
do_sample=False,
num_beams=1,
temperature=float(0.0),
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)
量化和分片
您可以通过指定load_in_8bit=True
或load_in_4bit=True
来加载量化模型。此外,通过设置device_map=auto
可以在多个GPU上进行分片。
模型架构
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的工具,而非人类。它可能会产生不正确、无意义或不相关的回答。用户有责任对生成的内容进行严格评估并自行决定使用方式。
- 风险自负:使用该大语言模型的用户必须对因使用该工具而可能产生的任何后果承担全部责任。本仓库的开发者和贡献者不对因使用或滥用该模型而导致的任何损害、损失或伤害承担责任。
- 伦理考虑:鼓励用户以负责任和符合伦理的方式使用大语言模型。使用该模型即表示您同意不将其用于宣扬仇恨言论、歧视、骚扰或任何形式的非法或有害活动。
- 问题报告:如果您遇到大语言模型生成的任何偏见、攻击性或其他不适当内容,请通过提供的渠道向仓库维护者报告。您的反馈将有助于改进模型并缓解潜在问题。
- 免责声明的变更:本仓库的开发者保留随时修改或更新本免责声明的权利,恕不另行通知。用户有责任定期查看免责声明以了解任何变更。
使用本仓库提供的大语言模型即表示您同意接受并遵守本免责声明中概述的条款和条件。如果您不同意本免责声明的任何部分,则应停止使用该模型及其生成的任何内容。