英文

模型卡片

概述

该模型是使用 H2O LLM Studio 进行训练的。

用法

要在启用GPU的计算机上使用 transformers 库和模型,请确保已安装 transformers、accelerate、torch 和 einops 库。

pip install transformers==4.29.2
pip install accelerate==0.19.0
pip install torch==2.0.0
pip install einops==0.6.1
import torch
from transformers import AutoTokenizer, pipeline


tokenizer = AutoTokenizer.from_pretrained(
    "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v3",
    use_fast=False,
    padding_side="left",
    trust_remote_code=True,
)

generate_text = pipeline(
    model="h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v3",
    tokenizer=tokenizer,
    torch_dtype=torch.float16,
    trust_remote_code=True,
    use_fast=False,
    device_map={"": "cuda:0"},
)

res = generate_text(
    "Why is drinking water so healthy?",
    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("Why is drinking water so healthy?")["prompt_text"])
<|prompt|>Why is drinking water so healthy?<|endoftext|><|answer|>

或者,您可以下载 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-falcon-7b-v3",
    use_fast=False,
    padding_side="left",
    trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
    "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v3",
    torch_dtype=torch.float16,
    device_map={"": "cuda:0"},
    trust_remote_code=True,
)
generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)

res = generate_text(
    "Why is drinking water so healthy?",
    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-falcon-7b-v3"  # either local folder or huggingface model name
# Important: The prompt needs to be in the same format the model was trained with.
# You can find an example prompt in the experiment logs.
prompt = "<|prompt|>How are you?<|endoftext|><|answer|>"

tokenizer = AutoTokenizer.from_pretrained(
    model_name,
    use_fast=False,
    trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map={"": "cuda:0"},
    trust_remote_code=True,
)
model.cuda().eval()
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")

# generate configuration can be modified to your needs
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)

模型架构

RWForCausalLM(
  (transformer): RWModel(
    (word_embeddings): Embedding(65024, 4544)
    (h): ModuleList(
      (0-31): 32 x DecoderLayer(
        (input_layernorm): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)
        (self_attention): Attention(
          (maybe_rotary): RotaryEmbedding()
          (query_key_value): Linear(in_features=4544, out_features=4672, bias=False)
          (dense): Linear(in_features=4544, out_features=4544, bias=False)
          (attention_dropout): Dropout(p=0.0, inplace=False)
        )
        (mlp): MLP(
          (dense_h_to_4h): Linear(in_features=4544, out_features=18176, bias=False)
          (act): GELU(approximate='none')
          (dense_4h_to_h): Linear(in_features=18176, out_features=4544, bias=False)
        )
      )
    )
    (ln_f): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)
  )
  (lm_head): Linear(in_features=4544, out_features=65024, bias=False)
)

模型配置

该模型是使用H2O LLM Studio训练的,并使用 cfg.yaml 中的配置。访问 H2O LLM Studio 了解如何训练自己的大语言模型。

免责声明

在使用本仓库提供的大语言模型之前,请仔细阅读本免责声明。您使用该模型即表示您同意以下条款和条件。

  • 偏见和冒犯性:该大语言模型是基于各种互联网文本数据进行训练的,其中可能包含有偏见、种族主义、冒犯性或其他不适当的内容。通过使用该模型,您承认并接受生成的内容有时可能会展示出偏见,或者生成冒犯性或不适当的内容。本仓库的开发人员不赞同、支持或推广任何此类内容或观点。
  • 限制:该大语言模型是一种基于人工智能的工具,而不是人类。它可能会生成错误的、荒谬的或不相关的回答。用户有责任对生成的内容进行批判性评估,并自行决定是否使用它。
  • 自担风险:使用该大语言模型的用户必须对其使用可能产生的任何后果承担全责。本仓库的开发人员和贡献者对使用或滥用所提供模型所造成的任何损害、损失或伤害概不负责。
  • 道德考虑:鼓励用户负责和合乎道德地使用该大语言模型。通过使用该模型,您同意不将其用于促进仇恨言论、歧视、骚扰或任何形式的非法或有害活动。
  • 报告问题:如果您遇到由大语言模型生成的有偏见、冒犯性或其他不适当的内容,请通过提供的渠道向仓库维护者报告。您的反馈将有助于改进模型并减轻潜在问题。
  • 免责声明的更改:本仓库的开发人员保留随时修改或更新本免责声明的权利,无需事先通知。用户有责任定期查阅免责声明,以了解任何更改。

通过使用本仓库提供的大语言模型,您表示同意接受并遵守本免责声明中概述的条款和条件。如果您不同意本免责声明的任何部分,您应避免使用该模型和由其生成的任何内容。