模型简介
模型特点
模型能力
使用案例
🚀 Merlyn Education Corpus QA v2 - GPTQ
本项目提供了Merlyn Education Corpus QA v2的GPTQ模型文件,支持多种量化参数选项,可根据自身硬件和需求进行选择。
🚀 快速开始
本仓库包含了Merlyn Mind的Merlyn Education Corpus QA v2的GPTQ模型文件。提供了多种GPTQ参数排列组合,详情请见下方的“提供的文件和GPTQ参数”部分,其中包含了各选项的参数以及创建这些文件所使用的软件信息。
这些文件是使用Massed Compute慷慨提供的硬件进行量化的。
✨ 主要特性
- 多版本支持:提供AWQ模型、多种量化参数的GPTQ模型、GGUF模型以及原始未量化的fp16模型,满足不同硬件和使用场景的需求。
- 参数可选:提供多种量化参数,用户可根据自身硬件和需求选择最合适的参数。
- 广泛兼容:已知可在多个推理服务器和Web UI中使用,如text-generation-webui、KoboldAI United等。
📦 安装指南
在text-generation-webui中下载
- 若要从
main
分支下载,在“下载模型”框中输入TheBloke/merlyn-education-corpus-qa-v2-GPTQ
。 - 若要从其他分支下载,在下载名称末尾添加
:branchname
,例如TheBloke/merlyn-education-corpus-qa-v2-GPTQ:gptq-4bit-32g-actorder_True
。
从命令行下载
推荐使用huggingface-hub
Python库:
pip3 install huggingface-hub
若要将main
分支下载到名为merlyn-education-corpus-qa-v2-GPTQ
的文件夹中:
mkdir merlyn-education-corpus-qa-v2-GPTQ
huggingface-cli download TheBloke/merlyn-education-corpus-qa-v2-GPTQ --local-dir merlyn-education-corpus-qa-v2-GPTQ --local-dir-use-symlinks False
若要从不同分支下载,添加--revision
参数:
mkdir merlyn-education-corpus-qa-v2-GPTQ
huggingface-cli download TheBloke/merlyn-education-corpus-qa-v2-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir merlyn-education-corpus-qa-v2-GPTQ --local-dir-use-symlinks False
使用git
下载(不推荐)
若要使用git
克隆特定分支,可使用如下命令:
git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/merlyn-education-corpus-qa-v2-GPTQ
请注意,强烈不建议使用Git与HF仓库配合使用,因为这比使用huggingface-hub
慢得多,并且会占用两倍的磁盘空间,因为它必须将模型文件存储两次(一次存储在目标文件夹中,另一次作为blob存储在.git
文件夹中)。
💻 使用示例
在text-generation-webui中使用
- 确保使用的是text-generation-webui的最新版本。强烈建议使用text-generation-webui的一键安装程序,除非你确定自己知道如何手动安装。
- 点击“模型”选项卡。
- 在“下载自定义模型或LoRA”中输入
TheBloke/merlyn-education-corpus-qa-v2-GPTQ
。- 若要从特定分支下载,可输入例如
TheBloke/merlyn-education-corpus-qa-v2-GPTQ:gptq-4bit-32g-actorder_True
。 - 具体分支列表可参考上方的“提供的文件和GPTQ参数”部分。
- 若要从特定分支下载,可输入例如
- 点击“下载”,模型将开始下载。下载完成后会显示“完成”。
- 在左上角,点击“模型”旁边的刷新图标。
- 在“模型”下拉菜单中,选择刚刚下载的模型:
merlyn-education-corpus-qa-v2-GPTQ
。 - 模型将自动加载,现在即可使用!
- 若需要自定义设置,设置完成后点击右上角的“保存此模型的设置”,然后点击“重新加载模型”。
- 请注意,不再需要也不应该手动设置GPTQ参数,这些参数会从
quantize_config.json
文件中自动设置。
- 请注意,不再需要也不应该手动设置GPTQ参数,这些参数会从
- 准备好后,点击“文本生成”选项卡,输入提示词即可开始!
从Text Generation Inference (TGI) 提供服务
建议使用TGI 1.1.0或更高版本,官方Docker容器为:ghcr.io/huggingface/text-generation-inference:1.1.0
。
示例Docker参数:
--model-id TheBloke/merlyn-education-corpus-qa-v2-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
示例Python代码,用于与TGI交互(需要huggingface-hub 0.17.0或更高版本):
pip3 install huggingface-hub
from huggingface_hub import InferenceClient
endpoint_url = "https://your-endpoint-url-here"
prompt = "Tell me about AI"
prompt_template=f'''Instruction:\t{system_message}
Conversation:
'user1':\tuser message to analyse
'user2':\tuser message to analyse
Response:
'''
client = InferenceClient(endpoint_url)
response = client.text_generation(prompt,
max_new_tokens=128,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=40,
repetition_penalty=1.1)
print(f"Model output: {response}")
Python代码示例:从该GPTQ模型进行推理
安装必要的包
需要:Transformers 4.33.0或更高版本、Optimum 1.12.0或更高版本以及AutoGPTQ 0.4.2或更高版本。
pip3 install --upgrade transformers optimum
# 若使用PyTorch 2.1 + CUDA 12.x:
pip3 install --upgrade auto-gptq
# 或者,若使用PyTorch 2.1 + CUDA 11.x:
pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
若使用PyTorch 2.0,则需要从源代码安装AutoGPTQ。同样,若预构建的轮子有问题,也应尝试从源代码构建:
pip3 uninstall -y auto-gptq
git clone https://github.com/PanQiWei/AutoGPTQ
cd AutoGPTQ
git checkout v0.5.1
pip3 install .
示例Python代码
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_name_or_path = "TheBloke/merlyn-education-corpus-qa-v2-GPTQ"
# 若要使用不同分支,更改revision
# 例如:revision="gptq-4bit-32g-actorder_True"
model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
device_map="auto",
trust_remote_code=False,
revision="main")
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
prompt = "Tell me about AI"
prompt_template=f'''Instruction:\t{system_message}
Conversation:
'user1':\tuser message to analyse
'user2':\tuser message to analyse
Response:
'''
print("\n\n*** Generate:")
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
print(tokenizer.decode(output[0]))
# 也可以使用transformers的pipeline进行推理
print("*** Pipeline:")
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=512,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=40,
repetition_penalty=1.1
)
print(pipe(prompt_template)[0]['generated_text'])
📚 详细文档
可用的仓库
- 用于GPU推理的AWQ模型。
- 用于GPU推理的GPTQ模型,具有多种量化参数选项。
- 适用于CPU + GPU推理的2、3、4、5、6和8位GGUF模型。
- Merlyn Mind的原始未量化的pytorch格式的fp16模型,用于GPU推理和进一步转换。
提示模板:Merlyn-Education
Instruction:\t{system_message}
Conversation:
'user1':\tuser message to analyse
'user2':\tuser message to analyse
Response:
许可证
源模型的创建者将其许可证列为apache-2.0
,因此本次量化也使用了相同的许可证。
由于该模型基于Llama 2,因此它也受Meta Llama 2许可证条款的约束,并且还包含了该许可证文件。因此,应将其视为同时受这两种许可证的约束。我已联系Hugging Face以澄清双重许可问题,但他们目前尚未有官方立场。如果情况发生变化,或者Meta对此情况提供任何反馈,我将相应更新此部分内容。
在此期间,任何关于许可证的问题,特别是这两种许可证可能如何相互作用的问题,应直接咨询原始模型仓库:Merlyn Mind的Merlyn Education Corpus QA v2。
已知兼容的客户端/服务器
这些GPTQ模型已知可在以下推理服务器/Web UI中使用:
这可能不是完整的列表,如果您知道其他兼容的客户端/服务器,请告知我!
提供的文件和GPTQ参数
提供了多种量化参数,以便您根据自己的硬件和需求选择最佳参数。
每个单独的量化版本位于不同的分支中。有关从不同分支获取文件的说明,请见下文。
大多数GPTQ文件使用AutoGPTQ制作。Mistral模型目前使用Transformers制作。
GPTQ参数说明
- 位数(Bits):量化模型的位大小。
- GS(GPTQ组大小):较高的数值使用较少的VRAM,但量化精度较低。“None”是可能的最低值。
- Act Order:真或假。也称为
desc_act
。设置为真可获得更好的量化精度。一些GPTQ客户端在处理同时使用Act Order和Group Size的模型时曾遇到问题,但目前这个问题通常已得到解决。 - Damp %:一个影响量化样本处理方式的GPTQ参数。默认值为0.01,但设置为0.1可获得稍高的精度。
- GPTQ数据集:量化期间使用的校准数据集。使用与模型训练更匹配的数据集可以提高量化精度。请注意,GPTQ校准数据集与训练模型使用的数据集不同 - 有关训练数据集的详细信息,请参考原始模型仓库。
- 序列长度(Sequence Length):量化时使用的数据集序列长度。理想情况下,该值应与模型序列长度相同。对于一些非常长序列的模型(16K以上),可能需要使用较低的序列长度。请注意,较低的序列长度不会限制量化模型的序列长度,它仅影响较长推理序列的量化精度。
- ExLlama兼容性:该文件是否可以使用ExLlama加载,目前ExLlama仅支持4位的Llama和Mistral模型。
分支 | 位数 | GS | Act Order | Damp % | GPTQ数据集 | 序列长度 | 大小 | ExLlama | 描述 |
---|---|---|---|---|---|---|---|---|---|
main | 4 | 128 | 是 | 0.1 | wikitext | 4096 | 7.26 GB | 是 | 4位,带有Act Order和组大小128g。比64g使用更少的VRAM,但精度稍低。 |
gptq-4bit-32g-actorder_True | 4 | 32 | 是 | 0.1 | wikitext | 4096 | 8.00 GB | 是 | 4位,带有Act Order和组大小32g。可提供最高的推理质量,但使用最大的VRAM。 |
gptq-8bit--1g-actorder_True | 8 | 无 | 是 | 0.1 | wikitext | 4096 | 13.36 GB | 否 | 8位,带有Act Order。无组大小,以降低VRAM需求。 |
gptq-8bit-128g-actorder_True | 8 | 128 | 是 | 0.1 | wikitext | 4096 | 13.65 GB | 否 | 8位,组大小128g以提高推理质量,带有Act Order以获得更高的精度。 |
gptq-8bit-32g-actorder_True | 8 | 32 | 是 | 0.1 | wikitext | 4096 | 14.54 GB | 否 | 8位,组大小32g和Act Order以获得最大的推理质量。 |
gptq-4bit-64g-actorder_True | 4 | 64 | 是 | 0.1 | wikitext | 4096 | 7.51 GB | 是 | 4位,带有Act Order和组大小64g。比32g使用更少的VRAM,但精度稍低。 |
兼容性
提供的文件已测试可与Transformers配合使用。对于非Mistral模型,也可以直接使用AutoGPTQ。
ExLlama与4位的Llama和Mistral模型兼容。每个文件的兼容性请参考上方的“提供的文件和GPTQ参数”表格。
有关客户端/服务器的列表,请见上方的“已知兼容的客户端/服务器”部分。
🔧 技术细节
Merlyn Education Corpus QA v2是一个用于教育领域的具有130亿参数的解码器式Transformer模型。它是在llama2-13b基础模型上进行微调得到的。
该模型经过训练,能够根据给定的上下文回答问题。与基于pythia的v1模型相比,它在更大的数据集上进行了训练,在更大、更多样化的基准测试数据集上表现出更好的正确性和更少的幻觉现象。
模型使用示例
加载模型和分词器
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "MerlynMind/merlyn-education-corpus-qa-v2"
device = torch.device("cuda:0") # 按需更改设备ID
model = AutoModelForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path, fast_tokenizer=True)
model.to(device) # 移动到设备
提示示例
info = '''Information:\tThe Solar System is about 4.6 billion years old. The Sun formed by gravity in a large molecular cloud. It is mainly hydrogen, which it converts into helium.
Information:\tThe formation and evolution of the Solar System began 4.6 billion years ago with the gravitational collapse of a small part of a giant molecular cloud.
Information:\tAstronomers are now more or less certain that the order of the planets was not always as it is today. Knowing what we know today, we can see the Solar System is strange. All other planetary system we are able to study have their largest planet close to their star. Also we have noticed other oddities in the Solar System. Mars is smaller than it ought to be, and the asteroid belt has been disturbed.
Information:\tFor thousands of years, people had no need for a name for the "Solar System". They thought the Earth stayed still at the center of everything (geocentrism). The Greek philosopher Aristarchus of Samos suggested that there was a special order in the sky. Nicolaus Copernicus was the first to develop a mathematical system that described what we now call the "Solar System". This was called a "new system of the world". In the 17th century, Galileo Galilei, Johannes Kepler and Isaac Newton began to understand physics more clearly. People began to accept the idea that the Earth is a planet that moves around the Sun, and that the planets are worlds, and that all worlds are governed by the same same physical laws. More recently, telescopes and space probes sometimes let us see details directly. All inner planets have surface features. The gas giants (as the name suggests) have surfaces whose make-up is gradually being discovered.
Information:\tThere are eight planets in the Solar System. From closest to farthest from the Sun, they are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. The first four planets are called terrestrial planets. They are mostly made of rock and metal, and they are mostly solid. The last four planets are called gas giants. This is because they are much larger than other planets and are mostly made of gas.
'''
qs = "Question:\tHow old is the Solar System?"
prompt = tokenizer.bos_token
prompt += '''Instruction:\tYou are to try to answer the following question using only the pieces of information given.
Instruction:\tYour response should be a well formed JSON object with an 'answerable' property followed by an 'answer' property.
Instruction:\tIf you cannot answer the question given the information, the value of the 'answerable' should be 'false' and the 'answer' should be an empty string.
Instruction:\tIf you can answer the question given the information, the value of the 'answerable' should be 'true' and your answer should be the string value of the 'answer' property.
''' + info + qs + " Response:"
停止条件设置
from transformers import StoppingCriteria, StoppingCriteriaList
eos_tokens = [tokenizer.eos_token,'\n']
eos_token_ids = [tokenizer.encode(token)[0] for token in eos_tokens]
class MultipleEOSTokensStoppingCriteria(StoppingCriteria):
def __init__(self, eos_token_ids):
self.eos_token_ids = set(eos_token_ids)
def __call__(self, input_ids, scores) -> bool:
if input_ids.shape[-1] <= 1:
return False
for eos_token_id in self.eos_token_ids:
if eos_token_id == input_ids[0, -1].item():
return True
return False
# 定义停止条件
multiple_eos_tokens_processor = MultipleEOSTokensStoppingCriteria(eos_token_ids)
stopping_criteria = StoppingCriteriaList([multiple_eos_tokens_processor])
推理
inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False).to(device)
generate_ids = model.generate(
**inputs,
max_new_tokens=1024,
temperature=0.0,
num_beams=2,
top_p=1,
stopping_criteria=stopping_criteria
)
response = tokenizer.decode(generate_ids[0],
skip_special_tokens=True,
clean_up_tokenization_spaces=True)
示例输出(响应处理后)
[{"answerable": "true", "answer": "4.6 billion years"}]
📄 许可证
本项目使用apache-2.0
许可证,同时由于基于Llama 2,也受Meta Llama 2许可证条款的约束。
🔗 其他链接
Discord
如需进一步支持,或参与有关这些模型和人工智能的讨论,请加入: TheBloke AI的Discord服务器
感谢与贡献方式
感谢chirper.ai团队!
感谢来自gpus.llm-utils.org的Clay!
很多人询问是否可以进行贡献。我很享受提供模型并帮助他人的过程,也希望能够有更多时间投入其中,同时开展新的项目,如微调/训练。
如果您有能力且愿意贡献,我将不胜感激,这将帮助我继续提供更多模型,并开始新的人工智能项目。
捐赠者将在任何与AI/LLM/模型相关的问题和请求上获得优先支持,访问私人Discord房间,以及其他福利。
- Patreon: https://patreon.com/TheBlokeAI
- Ko-Fi: https://ko-fi.com/TheBlokeAI
特别感谢:Aemon Algiz。
Patreon特别提及:Brandon Frisco, LangChain4j, Spiking Neurons AB, transmissions 11, Joseph William Delisle, Nitin Borwankar, Willem Michiel, Michael Dempsey, vamX, Jeffrey Morgan, zynix, jjj, Omer Bin Jawed, Sean Connelly, jinyuan sun, Jeromy Smith, Shadi, Pawan Osman, Chadd, Elijah Stavena, Illia Dulskyi, Sebastain Graf, Stephen Murray, terasurfer, Edmond Seymore, Celu Ramasamy, Mandus, Alex, biorpg, Ajan Kanaga, Clay Pascal, Raven Klaugh, 阿明, K, ya boyyy, usrbinkat, Alicia Loh, John Villwock, ReadyPlayerEmma, Chris Smitley, Cap'n Zoog, fincy, GodLy, S_X, sidney chen, Cory Kujawski, OG, Mano Prime, AzureBlack, Pieter, Kalila, Spencer Kim, Tom X Nguyen, Stanislav Ovsiannikov, Michael Levine, Andrey, Trailburnt, Vadim, Enrico Ros, Talal Aujan, Brandon Phillips, Jack West, Eugene Pentland, Michael Davis, Will Dee, webtim, Jonathan Leane, Alps Aficionado, Rooh Singh, Tiffany J. Kim, theTransient, Luke @flexchar, Elle, Caitlyn Gatomon, Ari Malik, subjectnull, Johann-Peter Hartmann, Trenton Dambrowitz, Imad Khwaja, Asp the Wyvern, Emad Mostaque, Rainer Wilmers, Alexandros Triantafyllidis, Nicholas, Pedro Madruga, SuperWojo, Harry Royden McLaughlin, James Bentley, Olakabola, David Ziegler, Ai Maven, Jeff Scroggin, Nikolai Manek, Deo Leter, Matthew Berman, Fen Risland, Ken Nordquist, Manuel Alberto Morcote, Luke Pendergrass, TL, Fred von Graf, Randy H, Dan Guido, NimbleBox.ai, Vitor Caleffi, Gabriel Tamborski, knownsqashed, Lone Striker, Erik Bjäreholt, John Detwiler, Leonard Tan, Iucharbius
感谢所有慷慨的赞助者和捐赠者!
再次感谢a16z的慷慨资助。



