您需要更新 transformers,以便 transformers 能够读取 gguf 文件。
transformers==4.45.1
numpy==1.24.4
gguf==0.10.0
accelerate
openmind-hub
einopsfrom openmind import AutoModelForCausalLM, AutoTokenizer
from openmind import is_torch_npu_available
import torch
import argparse
import torch.nn.functional as F
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="./h2o-danube3-500m-chat-GGUFF",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
#device = "cpu"
start_time = time.time()
filename = "h2o-danube3-500m-chat-Q4_K_M.gguf"
tokenizer = AutoTokenizer.from_pretrained(model_path, gguf_file=filename, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path, torch_dtype=torch.float16, gguf_file=filename, device_map=device
)
prompt = "Q: What is the largest animal?\nA:"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
input_ids = input_ids.to(model.device)
generation_output = model.generate(input_ids=input_ids, max_new_tokens=32)
print(tokenizer.decode(generation_output[0]))
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()本仓库包含 h2o-danube3-500m-chat 模型的 GGUF 格式文件,这些文件是使用 llama.cpp 框架进行量化处理的。
下表总结了 h2o-danube3-500m-chat 的不同量化版本,展示了模型在大小、速度和质量之间的权衡关系。
| 名称 | 量化方法 | 模型大小 | MT-Bench 平均值 | 困惑度 | 每秒令牌数 |
|---|---|---|---|---|---|
| h2o-danube3-500m-chat-F16.gguf | F16 | 1.03 GB | 3.34 | 9.46 | 1870 |
| h2o-danube3-500m-chat-Q8_0.gguf | Q8_0 | 0.55 GB | 3.76 | 9.46 | 2144 |
| h2o-danube3-500m-chat-Q6_K.gguf | Q6_K | 0.42 GB | 3.77 | 9.46 | 2418 |
| h2o-danube3-500m-chat-Q5_K_M.gguf | Q5_K_M | 0.37 GB | 3.20 | 9.55 | 2430 |
| h2o-danube3-500m-chat-Q4_K_M.gguf | Q4_K_M | 0.32 GB | 3.16 | 9.96 | 2427 |
表中的列说明如下:
<|prompt|>Why is drinking water so healthy?</s><|answer|>