模型概述
模型特點
模型能力
使用案例
🚀 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的慷慨資助。



