模型简介
模型特点
模型能力
使用案例
🚀 mamba - gpt - 3b模型
本项目对open - lama模型进行了微调,在多个评估子任务中超越了原始模型,使其成为目前性能最佳的3B模型,性能可与llama - 7b相媲美。
🚀 快速开始
要在配备GPU的机器上使用transformers
库调用此模型,首先要确保已安装transformers
、accelerate
和torch
库。
pip install transformers==4.29.2
pip install accelerate==0.19.0
pip install torch==2.0.0
import torch
from transformers import pipeline
generate_text = pipeline(
model="CobraMamba/mamba-gpt-3b",
torch_dtype="auto",
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?</s><|answer|>
或者,你可以下载mamba_gpt_pipeline.py
,将其与你的笔记本放在一起,并根据加载的模型和分词器自己构建管道。如果模型和分词器在transformers
包中得到完全支持,这将允许你设置trust_remote_code = False
。
import torch
from mamba_gpt_pipeline import MambaGPTTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"CobraMamba/mamba-gpt-3b",
use_fast=False,
padding_side="left",
trust_remote_code=False,
)
model = AutoModelForCausalLM.from_pretrained(
"CobraMamba/mamba-gpt-3b",
torch_dtype="auto",
device_map={"": "cuda:0"},
trust_remote_code=False,
)
generate_text = MambaGPTTextGenerationPipeline(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 = "CobraMamba/mamba-gpt-3b" # 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?</s><|answer|>"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
use_fast=False,
trust_remote_code=False,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map={"": "cuda:0"},
trust_remote_code=False,
)
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)
✨ 主要特性
- 对open - lama模型进行微调,在多个评估子任务中超越原始模型。
- 目前性能最佳的3B模型,性能可与llama - 7b相媲美。
📦 安装指南
要使用该模型,需安装以下依赖库:
pip install transformers==4.29.2
pip install accelerate==0.19.0
pip install torch==2.0.0
📚 详细文档
模型指标
指标 | 值 |
---|---|
MMLU (5 - shot) | 25.3 |
ARC (25 - shot) | 40.5 |
HellaSwag (10 - shot) | 64.9 |
TruthfulQA (0 - shot) | 37.1 |
平均值 | 42.0 |
我们使用最先进的Language Model Evaluation Harness来运行上述基准测试。
模型架构
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)
)
评估结果
我们使用lm - evaluation - harness在广泛的任务上对OpenLLaMA进行了评估。LLaMA的结果是通过在相同的评估指标上运行原始LLaMA模型生成的。我们注意到,我们的LLaMA模型结果与原始LLaMA论文略有不同,我们认为这是由于不同的评估协议造成的。类似的差异已在lm - evaluation - harness的这个问题中报告。此外,我们还展示了GPT - J的结果,它是由EleutherAI在Pile数据集上训练的一个6B参数模型。
原始LLaMA模型训练了1万亿个标记,GPT - J训练了5000亿个标记。我们在下表中展示结果。OpenLLaMA在大多数任务上表现出与原始LLaMA和GPT - J相当的性能,并且在某些任务上表现更优。
任务/指标 | 微调后的GPT 3B | OpenLLaMA 3B |
---|---|---|
anli_r1/acc | 0.35 | 0.33 |
anli_r2/acc | 0.33 | 0.32 |
anli_r3/acc | 0.35 | 0.35 |
arc_challenge/acc | 0.35 | 0.34 |
arc_challenge/acc_norm | 0.37 | 0.37 |
arc_easy/acc | 0.71 | 0.69 |
arc_easy/acc_norm | 0.65 | 0.65 |
boolq/acc | 0.72 | 0.66 |
hellaswag/acc | 0.49 | 0.43 |
hellaswag/acc_norm | 0.66 | 0.67 |
openbookqa/acc | 0.26 | 0.27 |
openbookqa/acc_norm | 0.40 | 0.40 |
piqa/acc | 0.76 | 0.75 |
piqa/acc_norm | 0.76 | 0.76 |
record/em | 0.88 | 0.88 |
record/f1 | 0.88 | 0.89 |
rte/acc | 0.55 | 0.58 |
truthfulqa_mc/mc1 | 0.27 | 0.22 |
truthfulqa_mc/mc2 | 0.37 | 0.35 |
wic/acc | 0.49 | 0.48 |
winogrande/acc | 0.63 | 0.62 |
平均值 | 0.53 | 0.52 |
我们从基准测试中移除了任务CB和WSC,因为我们的模型在这两个任务上的表现异常出色。我们推测训练集中可能存在基准数据污染。
免责声明
在使用本仓库提供的大语言模型之前,请仔细阅读本免责声明。使用该模型即表示您同意以下条款和条件。
- 偏差与冒犯性:大语言模型是在各种互联网文本数据上训练的,这些数据可能包含有偏差、种族主义、冒犯性或其他不适当的内容。使用此模型即表示您承认并接受生成的内容有时可能会表现出偏差或产生冒犯性或不适当的内容。本仓库的开发者不认可、支持或推广任何此类内容或观点。
- 局限性:大语言模型是基于人工智能的工具,而非人类。它可能会产生不正确、无意义或不相关的回复。用户有责任批判性地评估生成的内容,并自行决定是否使用。
- 风险自担:使用此大语言模型的用户必须对使用该工具可能产生的任何后果承担全部责任。本仓库的开发者和贡献者不对因使用或滥用所提供的模型而导致的任何损害、损失或伤害承担责任。
- 伦理考量:鼓励用户负责任且合乎道德地使用大语言模型。使用此模型即表示您同意不将其用于宣扬仇恨言论、歧视、骚扰或任何形式的非法或有害活动的目的。
- 问题反馈:如果您遇到大语言模型生成的有偏差、冒犯性或其他不适当的内容,请通过提供的渠道向仓库维护者报告。您的反馈将有助于改进模型并减轻潜在问题。
- 免责声明变更:本仓库的开发者保留在任何时候修改或更新本免责声明的权利,且无需事先通知。用户有责任定期查看免责声明,以了解任何变更。
使用本仓库提供的大语言模型即表示您同意接受并遵守本免责声明中规定的条款和条件。如果您不同意本免责声明的任何部分,您应避免使用该模型及其生成的任何内容。
📄 许可证
本项目采用Apache - 2.0许可证。
🔗 相关链接



