模型概述
模型特點
模型能力
使用案例
🚀 MERAK-7B-V2 GGML
MERAK-7B-V2 GGML 是用於特定模型的文件格式,支持 CPU + GPU 推理。這些文件能與多種工具和庫兼容,為用戶提供了在不同環境下使用模型的便利。
🚀 快速開始
這些文件是 MERAK-7B-V2 的 GGML 格式模型文件。GGML 文件可使用 llama.cpp 以及支持此格式的庫和 UI 進行 CPU + GPU 推理,例如:
- KoboldCpp,一個強大的 GGML 網頁 UI,開箱即用支持全 GPU 加速,尤其適合講故事。
- LoLLMS Web UI,一個很棒的網頁 UI,通過 c_transformers 後端實現 GPU 加速。
- LM Studio,一個功能齊全的本地 GUI,在 macOS 上支持全 GPU 加速,也支持 Windows,但無 GPU 加速。
- text-generation-webui,最流行的網頁 UI,需要額外步驟通過 llama.cpp 後端啟用 GPU 加速。
- ctransformers,一個支持 LangChain 且兼容 OpenAI 的 Python 庫和 AI 服務器。
- llama-cpp-python,一個兼容 OpenAI API 的 Python 庫。
✨ 主要特性
- 多工具兼容:支持多種工具和庫進行 CPU + GPU 推理。
- 新量化方法:引入新的 k - quant 量化方法,提高兼容性和性能。
- 低顯存運行:藉助 QLoRA 技術,可在 16GB VRAM 下運行。
📦 安裝指南
環境準備
請確保系統已安裝 CUDA 驅動、Python 3.10 和 PyTorch 2。
安裝依賴庫
在終端中安裝以下庫:
pip install bitsandbytes==0.39.1
pip install transformers==4.31.0
pip install peft==0.4.0
pip install accelerate==0.20.3
pip install einops==0.6.1 scipy sentencepiece datasets
💻 使用示例
基礎用法
使用 BitsandBytes 並在 >= 10GB VRAM GPU 上運行:
import torch
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig, LlamaTokenizer
from peft import PeftModel, PeftConfig
model_id = "Ichsan2895/Merak-7B-v2"
config = AutoConfig.from_pretrained(model_id)
BNB_CONFIG = BitsAndBytesConfig(load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
)
model = AutoModelForCausalLM.from_pretrained(model_id,
quantization_config=BNB_CONFIG,
device_map="auto",
trust_remote_code=True)
tokenizer = LlamaTokenizer.from_pretrained(model_id)
def generate_response(question: str) -> str:
prompt = f"<|prompt|>{question}\n<|answer|>".strip()
encoding = tokenizer(prompt, return_tensors='pt').to("cuda")
with torch.inference_mode():
outputs = model.generate(input_ids=encoding.input_ids,
attention_mask=encoding.attention_mask,
eos_token_id=tokenizer.pad_token_id,
do_sample=False,
num_beams=2,
temperature=0.3,
repetition_penalty=1.2,
max_length=200)
response = tokenizer.decode(outputs[0], skip_special_tokes=True)
assistant_start = "<|answer|>"
response_start = response.find(assistant_start)
return response[response_start + len(assistant_start) :].strip()
prompt = "Siapa penulis naskah proklamasi kemerdekaan Indonesia?"
print(generate_response(prompt))
高級用法
不使用 BitsandBytes 4 位量化以獲得更好答案,但需要更高 VRAM:
import torch
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, BitsAndBytesConfig, LlamaTokenizer
from peft import PeftModel, PeftConfig
model_id = "Ichsan2895/Merak-7B-v2"
config = AutoConfig.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id,
device_map="auto",
trust_remote_code=True)
tokenizer = LlamaTokenizer.from_pretrained(model_id)
def generate_response(question: str) -> str:
prompt = f"<|prompt|>{question}\n<|answer|>".strip()
encoding = tokenizer(prompt, return_tensors='pt').to("cuda")
with torch.inference_mode():
outputs = model.generate(input_ids=encoding.input_ids,
attention_mask=encoding.attention_mask,
eos_token_id=tokenizer.pad_token_id,
do_sample=False,
num_beams=2,
temperature=0.3,
repetition_penalty=1.2,
max_length=200)
response = tokenizer.decode(outputs[0], skip_special_tokes=True)
assistant_start = "<|answer|>"
response_start = response.find(assistant_start)
return response[response_start + len(assistant_start) :].strip()
prompt = "Siapa penulis naskah proklamasi kemerdekaan Indonesia?"
print(generate_response(prompt))
📚 詳細文檔
兼容性
原始 llama.cpp 量化方法:q4_0, q4_1, q5_0, q5_1, q8_0
這些方法保證與 5 月下旬以來發布的任何 UI、工具和庫兼容。由於新的 k - quant 方法逐漸取代它們,這些方法可能很快會被淘汰。
新的 k - quant 方法:q2_K, q3_K_S, q3_K_M, q3_K_L, q4_K_S, q4_K_M, q5_K_S, q6_K
這些新的量化方法自 6 月 6 日提交 2d43387
起與 llama.cpp 兼容。
它們現在也與 text - generation - webui、KoboldCpp、llama - cpp - python、ctransformers、rustformers 等近期版本兼容。對於其他工具和庫的兼容性,請查看其文檔。
新 k - quant 方法說明
點擊查看詳情
可用的新方法如下:
- GGML_TYPE_Q2_K - “類型 1” 2 位量化,超級塊包含 16 個塊,每個塊有 16 個權重。塊的縮放和最小值用 4 位量化,最終每個權重有效使用 2.5625 位(bpw)。
- GGML_TYPE_Q3_K - “類型 0” 3 位量化,超級塊包含 16 個塊,每個塊有 16 個權重。縮放用 6 位量化,最終使用 3.4375 bpw。
- GGML_TYPE_Q4_K - “類型 1” 4 位量化,超級塊包含 8 個塊,每個塊有 32 個權重。縮放和最小值用 6 位量化,最終使用 4.5 bpw。
- GGML_TYPE_Q5_K - “類型 1” 5 位量化,與 GGML_TYPE_Q4_K 具有相同的超級塊結構,最終使用 5.5 bpw。
- GGML_TYPE_Q6_K - “類型 0” 6 位量化,超級塊有 16 個塊,每個塊有 16 個權重。縮放用 8 位量化,最終使用 6.5625 bpw。
- GGML_TYPE_Q8_K - “類型 0” 8 位量化,僅用於量化中間結果。與現有的 Q8_0 的區別在於塊大小為 256。所有 2 - 6 位點積都為此量化類型實現。
請參考下面的提供文件表,瞭解哪些文件使用了哪些方法以及如何使用。
提供的文件
名稱 | 量化方法 | 位數 | 使用場景 |
---|---|---|---|
Merak-7B-v2.ggmlv3.q2_K.bin | q2_K | 2 | 新的 k - quant 方法。對注意力層的 vw 和前饋層的 w2 張量使用 GGML_TYPE_Q4_K,對其他張量使用 GGML_TYPE_Q2_K。 |
Merak-7B-v2.ggmlv3.q3_K_L.bin | q3_K_L | 3 | 新的 k - quant 方法。對注意力層的 wv 、wo 和前饋層的 w2 張量使用 GGML_TYPE_Q5_K,其他使用 GGML_TYPE_Q3_K。 |
Merak-7B-v2.ggmlv3.q3_K_M.bin | q3_K_M | 3 | 新的 k - quant 方法。對注意力層的 wv 、wo 和前饋層的 w2 張量使用 GGML_TYPE_Q4_K,其他使用 GGML_TYPE_Q3_K。 |
Merak-7B-v2.ggmlv3.q3_K_S.bin | q3_K_S | 3 | 新的 k - quant 方法。所有張量使用 GGML_TYPE_Q3_K。 |
Merak-7B-v2.ggmlv3.q4_0.bin | q4_0 | 4 | 原始量化方法,4 位。 |
Merak-7B-v2.ggmlv3.q4_1.bin | q4_1 | 4 | 原始量化方法,4 位。比 q4_0 精度高,但不如 q5_0。推理速度比 q5 模型快。 |
Merak-7B-v2.ggmlv3.q4_K_M.bin | q4_K_M | 4 | 新的 k - quant 方法。對一半的注意力層的 wv 和前饋層的 w2 張量使用 GGML_TYPE_Q6_K,其他使用 GGML_TYPE_Q4_K。 |
Merak-7B-v2.ggmlv3.q4_K_S.bin | q4_K_S | 4 | 新的 k - quant 方法。所有張量使用 GGML_TYPE_Q4_K。 |
Merak-7B-v2.ggmlv3.q5_0.bin | q5_0 | 5 | 原始量化方法,5 位。精度更高,資源使用更多,推理速度更慢。 |
Merak-7B-v2.ggmlv3.q5_1.bin | q5_1 | 5 | 原始量化方法,5 位。精度更高,資源使用更多,推理速度更慢。 |
Merak-7B-v2.ggmlv3.q5_K_M.bin | q5_K_M | 5 | 新的 k - quant 方法。對一半的注意力層的 wv 和前饋層的 w2 張量使用 GGML_TYPE_Q6_K,其他使用 GGML_TYPE_Q5_K。 |
Merak-7B-v2.ggmlv3.q5_K_S.bin | q5_K_S | 5 | 新的 k - quant 方法。所有張量使用 GGML_TYPE_Q5_K。 |
Merak-7B-v2.ggmlv3.q6_K.bin | q6_K | 6 | 新的 k - quant 方法。所有張量使用 GGML_TYPE_Q8_K - 6 位量化。 |
lMerak-7B-v2.ggmlv3.q8_0.bin | q8_0 | 8 | 原始量化方法,8 位。幾乎與 float16 無區別,資源使用高,速度慢,不建議大多數用戶使用。 |
在 text-generation-webui
中運行的說明
更多說明請參考:text-generation-webui/docs/llama.cpp-models.md。
原始模型說明
Merak - 7B 是印度尼西亞語的大語言模型。 此模型基於 Meta Llama - 2 - 7B - Chat - HF,並使用我之前清理過的一些印度尼西亞維基百科文章進行微調。 藉助 QLoRA(QLora: Efficient Finetuning of Quantized LLMs),Merak - 7B 能夠在 16GB VRAM 下運行。 該模型遵循知識共享署名 - 相同方式共享 - 非商業性使用(CC - BY - SA - NC 4.0)許可,賦能 AI 愛好者和研究人員。
版本更新日誌
v1 = 第一個 Merak - 7B 模型。我們選擇並清理了約 200k 條印度尼西亞維基百科文章。 v2 = 第一個 Merak - 7B 模型的微調版本。我們再次使用相同的印度尼西亞維基百科文章進行微調,但問題中的提示風格有所改變。
引用信息
@Paper{arXiv,
author = {Touvron, et al},
title = {Llama 2: Open Foundation and Fine-Tuned Chat Models},
journal = {arXiv preprint arXiv:2307.09288},
year = {2023}
}
@ONLINE{wikidump,
author = "Wikimedia Foundation",
title = "Wikimedia Downloads",
url = "https://dumps.wikimedia.org"
}
@inproceedings{wolf-etal-2020-transformers,
title = "Transformers: State-of-the-Art Natural Language Processing",
author = "Thomas Wolf and Lysandre Debut and Victor Sanh and Julien Chaumond and Clement Delangue and Anthony Moi and Pierric Cistac and Tim Rault and Rémi Louf and Morgan Funtowicz and Joe Davison and Sam Shleifer and Patrick von Platen and Clara Ma and Yacine Jernite and Julien Plu and Canwen Xu and Teven Le Scao and Sylvain Gugger and Mariama Drame and Quentin Lhoest and Alexander M. Rush",
booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = oct,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2020.emnlp-demos.6",
pages = "38--45"
}
@article{dettmers2023qlora,
title = {QLoRA: Efficient Finetuning of Quantized LLMs},
author = {Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},
journal = {arXiv preprint arXiv:2305.14314},
year = {2023}
}
🔧 技術細節
- 模型架構:基於 Meta Llama - 2 - 7B - Chat - HF 架構。
- 微調數據:使用清理後的印度尼西亞維基百科文章進行微調。
- 量化技術:採用 QLoRA 技術實現低顯存運行。
📄 許可證
本模型遵循知識共享署名 - 相同方式共享 - 非商業性使用(CC - BY - SA - NC 4.0)許可。
信息表格
屬性 | 詳情 |
---|---|
模型類型 | Llama |
訓練數據 | 印度尼西亞維基百科文章 |
許可證 | Creative Commons - By Attribution - Share Alike - Non Commercial (CC - BY - SA - NC 4.0) |



