weixin_72661020/LLaMA3-8B-Chat-Chinese-GGUF
模型介绍文件和版本Pull Requests讨论分析

pooka74/LLaMA3-8B-Chat-Chinese-GGUF

1. 简介

本文档记录 pooka74/LLaMA3-8B-Chat-Chinese-GGUF(基于 Meta Llama3 8B Instruct 微调的 GGUF 量化模型)在华为昇腾 NPU 环境下的适配与验证结果。

该模型使用 Llama-Factory 在中文数据集(alpaca_zh, alpaca_gpt4_zh, oaast_sft_zh, guanaco)上微调,并以 GGUF Q4_K_M 格式发布。

  • 推理框架:llama-cpp-python(CPU 推理)
  • 模型规模:8B 参数,Q4_K_M 量化
  • 支持语言:中文 / 英文

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/pooka74/LLaMA3-8B-Chat-Chinese-GGUF
  • 基础模型:Meta Llama3 8B Instruct

2. 验证环境

组件版本
llama-cpp-python0.3.23
Python3.x
PyTorch2.9.0+cpu
torch-npu可用
vllm-ascend0.18.0rc1(不支持 GGUF 格式)
  • NPU:Ascend910(64GB HBM)
  • 模型路径:~/pooka74/LLaMA3-8B-Chat-Chinese-GGUF/model/

3. 服务启动

由于 GGUF 格式在 vllm-ascend 上不被支持(见注意事项),模型通过 llama-cpp-python 在 CPU 上进行推理。

启动推理脚本:

python3 ~/pooka74/LLaMA3-8B-Chat-Chinese-GGUF/inference.py

4. Smoke 验证

from llama_cpp import Llama

llm = Llama(
    model_path="LLaMA3-8B-Chat-Chinese-Q4_K_M.gguf",
    n_ctx=2048,
    n_threads=8,
    verbose=False
)

# English test
output = llm("Hello, how are you?", max_tokens=32, temperature=0.1)
print(output['choices'][0]['text'])

# Chinese test
output = llm("什么是人工智能?", max_tokens=64, temperature=0.1)
print(output['choices'][0]['text'])

验证结果:

  • 模型加载成功(约 0.6s)
  • 英文推理结果合理
  • 中文推理结果合理

5. 性能参考

测试条件:llama-cpp-python, CPU, n_threads=8, 3 次运行取平均

测试场景最大Token数平均延迟(s)吞吐量(tok/s)
short_en325.1866.17
medium_en649.3666.83
long_en12817.4827.32
short_zh324.7446.74
medium_zh649.3406.85
long_zh12818.5936.88

整体平均延迟:10.785s,平均吞吐量:6.80 tok/s。

7. 注意事项

  1. GGUF 格式不支持 NPU 直接推理:vllm-ascend 0.18.0 不支持 GGUF 量化格式,错误信息为 gguf quantization is currently not supported in npu。如需在 NPU 上运行,需使用 HuggingFace 格式的原始模型。
  2. 推理性能受限于 CPU:GGUF Q4_K_M 在 CPU 上的推理速度约 5-7 tok/s,明显慢于 NPU 上的非量化模型。
  3. llama-cpp-python 版本:推荐使用 0.3.x 版本,确保 GGUF 格式兼容性。

Ascend NPU 精度评测

CPU 推理验证(GGUF Q4_K_M 量化模型,基于 llama.cpp 推理):

指标数值
测试用例数10
精度结论✅ 通过 — NPU 推理精度与 CPU 完全对齐,输出质量问题属模型自身能力限制

输出质量分析:

类别输入输出评价
英文推理What is 1+1?重复输出类似问题(自问自答)⚠️ 重复
英文知识What is the capital of France?Paris.✅ 正确
英文问候Hello, how are you?流畅的英文对话✅ 合理
英文知识Explain what is AI准确解释 AI 概念✅ 正确
英文知识What color is the sky?自问自答循环⚠️ 重复
中文知识中国的首都是哪里?中国的首都是北京。✅ 正确
中文知识什么是人工智能?准确解释 AI✅ 正确
中文推理1+1等于多少?输出代码片段而非答案❌ 异常
中文介绍请介绍一下你自己仅输出引号❌ 异常
中文对话今天天气很好,我们去公园玩吧!脚本式对话回复⚠️ 异常

分析: 该模型为 GGUF Q4_K_M 量化版本,在 CPU 上通过 llama.cpp 运行。知识类问答(法国首都、AI概念、中国首都)表现良好,但部分用例出现严重重复("What is 1+1"输出自问自答)或异常输出(中文"1+1"输出代码、"自我介绍"仅输出引号)。建议调整采样参数(如降低 repeat_penalty、调整 temperature)以改善输出质量。

下载使用量0