模型简介
模型特点
模型能力
使用案例
语言:
- 英文 库名称: transformers 标签:
- gpt
- llm
- 大语言模型
- h2o-llmstudio 推理: false 缩略图: https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
模型卡片
概述
该模型使用H2O LLM Studio进行训练。
-
在168个提示上进行训练,以生成多项选择题的回答(https://huggingface.co/datasets/fbellame/pdf_to_quizz_llama_13B)
你是一名正在准备测验问题的老师。根据以下文档,请生成1个包含4个选项的多项选择题(MCQ)以及对应的答案字母。 示例问题: 问题: 问题内容 选项A: 选项内容 选项B: 选项内容 选项C: 选项内容 选项D: 选项内容 答案: A或B或C或D 这些问题应详细且仅基于文档中提供的信息。 <文档开始> 1229年,国王不得不应对巴黎大学持续已久的罢工。拉丁区受到这些罢工的严重影响。 <文档结束>" 问题: 1229年巴黎大学罢工的原因是什么? A: 国王干预大学事务 B: 大学资源短缺 C: 教职员工之间的分歧 D: 拉丁区遭受自然灾害重创 答案: B
训练:
您可以在此处观看解释微调过程的YouTube视频: https://youtu.be/gXXkLVfiBVQ?si=b-RNVykuOLDPaTHb
源代码
您可以在此处找到使用此模型的GitHub项目 https://github.com/fbellame/pdf-to-quizz/tree/feature/local_model (分支local_model和https://github.com/fbellame/pdf-to-quizz/tree/feature/tgi)
使用方式
要在配备GPU的机器上使用transformers
库运行该模型,首先确保已安装transformers
库。
pip install transformers==4.31.0
如果模型位于私有仓库中,还需确保向pipeline提供您的huggingface令牌。
- 要么在pipeline
中保留token=True
并通过运行以下代码登录huggingface_hub
python import huggingface_hub huggingface_hub.login(<访问令牌>)
- 或者直接将您的<访问令牌>传递给pipeline
中的token
参数
from transformers import pipeline
generate_text = pipeline(
model="fbellame/llama2-pdf-to-quizz-13b",
torch_dtype="auto",
trust_remote_code=True,
use_fast=True,
device_map={"": "cuda:0"},
token=True,
)
res = generate_text(
"为什么喝水如此健康?",
min_new_tokens=2,
max_new_tokens=256,
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,将其与笔记本一起存储,然后从加载的模型和分词器自行构建pipeline。如果模型和分词器完全受transformers
包支持,这将允许您设置trust_remote_code=False
。
from h2oai_pipeline import H2OTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"fbellame/llama2-pdf-to-quizz-13b",
use_fast=True,
padding_side="left",
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
"fbellame/llama2-pdf-to-quizz-13b",
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.3),
repetition_penalty=float(1.2),
renormalize_logits=True
)
print(res[0]["generated_text"])
您也可以自行从加载的模型和分词器构建pipeline,并考虑预处理步骤:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "fbellame/llama2-pdf-to-quizz-13b" # 可以是本地文件夹或huggingface模型名称
# 重要: 提示需要采用与模型训练时相同的格式。
# 您可以在实验日志中找到示例提示。
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.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)
量化和分片
您可以通过指定load_in_8bit=True
或load_in_4bit=True
使用量化加载模型。此外,通过设置device_map=auto
可以在多个GPU上进行分片。
模型架构
LlamaForCausalLM(
(model): LlamaModel(
(embed_tokens): Embedding(32000, 5120, padding_idx=0)
(layers): ModuleList(
(0-39): 40 x LlamaDecoderLayer(
(self_attn): LlamaAttention(
(q_proj): Linear(in_features=5120, out_features=5120, bias=False)
(k_proj): Linear(in_features=5120, out_features=5120, bias=False)
(v_proj): Linear(in_features=5120, out_features=5120, bias=False)
(o_proj): Linear(in_features=5120, out_features=5120, bias=False)
(rotary_emb): LlamaRotaryEmbedding()
)
(mlp): LlamaMLP(
(gate_proj): Linear(in_features=5120, out_features=13824, bias=False)
(up_proj): Linear(in_features=5120, out_features=13824, bias=False)
(down_proj): Linear(in_features=13824, out_features=5120, bias=False)
(act_fn): SiLUActivation()
)
(input_layernorm): LlamaRMSNorm()
(post_attention_layernorm): LlamaRMSNorm()
)
)
(norm): LlamaRMSNorm()
)
(lm_head): Linear(in_features=5120, out_features=32000, bias=False)
)
模型配置
该模型使用H2O LLM Studio和cfg.yaml中的配置进行训练。访问H2O LLM Studio了解如何训练自己的大语言模型。
免责声明
在使用本仓库提供的大语言模型前,请仔细阅读以下免责声明。使用该模型即表示您同意以下条款和条件。
- 偏见和冒犯性内容: 大语言模型是在多样化的互联网文本数据上训练的,可能包含偏见、种族主义、冒犯性或其他不当内容。使用此模型即表示您承认并接受生成的内容有时可能表现出偏见或产生冒犯性或不适当的内容。本仓库开发者不认可、支持或推广任何此类内容或观点。
- 局限性: 大语言模型是基于AI的工具,而非人类。它可能产生不正确、无意义或不相关的回答。用户有责任批判性评估生成内容并自行决定使用方式。
- 风险自担: 使用此大语言模型的用户必须对因使用该工具而产生的任何后果承担全部责任。本仓库的开发者及贡献者不对因使用或滥用所提供模型而导致的任何损害、损失或伤害承担责任。
- 道德考量: 鼓励用户负责任且符合道德地使用大语言模型。使用此模型即表示您同意不将其用于宣扬仇恨言论、歧视、骚扰或任何形式的非法或有害活动。
- 问题报告: 如果您遇到大语言模型生成的任何偏见、冒犯性或其他不当内容,请通过提供的渠道向仓库维护者报告。您的反馈将有助于改进模型并缓解潜在问题。
- 免责声明变更: 本仓库开发者保留随时修改或更新此免责声明的权利,恕不另行通知。用户有责任定期查看免责声明以了解任何变更。
使用本仓库提供的大语言模型即表示您接受并同意遵守本免责声明中概述的条款和条件。如果您不同意本免责声明的任何部分,则应避免使用该模型及其生成的任何内容。


