llama-cpp模型轻量化部署与量化

一、定义

  1. 定义
  2. 配置环境
  3. 遇到的问题,交互模式下模型一直输出,不会停止
  4. 模型量化
  5. Qwen1.5-7B 案例demo

二、实现

  1. 定义
    主要应用与cpu 上的部署框架。由c++完成。

  2. 配置环境
    https://github.com/ggerganov/llama.cpp
    https://github.com/echonoshy/cgft-llm/blob/master/llama-cpp/README.md
    安装:

    git clone https://github.com/ggerganov/llama.cpp
    cd llama.cpp

编译环境

复制代码
sudo apt update
sudo apt install cmake

cpu:
cmake -B build_cpu
cmake --build build_cpu --config Release

部署:

复制代码
cd /root/code/llama.cpp/build_cpu/bin/
#交互模式
./llama-cli -m /home/Llama3-8B-Chinese-Chat-GGUF/Llama3-8B-Chinese-Chat-q8_0-v2_1.gguf \
    -n -1 \
    -t 12 \                    #多线程
    --color \                 #输入有颜色
    -r "User:" \              #-r: 遇到User: 停止,等待输入
    --in-prefix " " \         #输入前缀
    -i \                      #交互模式
    -p \                      #输入prompt
'User: 你好
AI: 你好啊,我是光屿,要聊聊吗?
User: 好啊!
AI: 你想聊聊什么话题呢?
User:'

#接口模式
./llama-server \
    -m /home/Llama3-8B-Chinese-Chat-GGUF/Llama3-8B-Chinese-Chat-q8_0-v2_1.gguf \
    --host "0.0.0.0" \
    --port 8080 \
    -c 2048 \
    -ngl 128 \            
    --api-key "echo in the moon"


  1. 遇到的问题,交互模式下模型一直输出,不会停止,参数-r 不起作用

原因: 容器内不支持中文,添加上中文输入法,问题解决。

复制代码
安装语言包
apt update
apt install -y language-pack-zh-hans
设置环境变量
export LANG=zh_CN.UTF-8
启动终端
exec bash
  1. Qwen1.5-7B 案例demo

    1. 将qwen1.5 转为gguf

    python convert-hf-to-gguf.py /home/Qwen1.5_7b --outfile /home/Qwen1.5_7b-GGUF/Qwen1.5_7b_v1.gguf

量化

复制代码
cd llama.cpp/build_cuda/bin
./llama-quantize --allow-requantize /home/Qwen1.5_7b-GGUF/Qwen1.5_7b_v1.gguf /home/Qwen1.5_7b-GGUF/Qwen1.5_7b-q4_1-v1.gguf Q4_1
  1. 测试

    ./llama-cli -m /home/Qwen1.5_7b-GGUF/Qwen1.5_7b-q4_1-v1.gguf
    -n -1
    -ngl 256
    -t 12
    --color
    -r "user:"
    --in-prefix " "
    -i
    -p
    "user:: 你好
    AI: 你好啊,我是光屿,要聊聊吗?
    user: 好啊!
    AI: 你想聊聊什么话题呢?
    user:"

相关推荐
闲看云起2 小时前
从 GPT 到 LLaMA:解密 LLM 的核心架构——Decoder-Only 模型
gpt·架构·llama
小草cys2 天前
在树莓派集群上部署 Distributed Llama (Qwen 3 14B) 详细指南
python·llama·树莓派·qwen
咕咚-萌西2 天前
联邦学习论文分享:Towards Building the Federated GPT:Federated Instruction Tuning
llama·联邦学习·指令微调
relis3 天前
解密llama.cpp中的batch与ubatch:深度学习推理优化的内存艺术
深度学习·batch·llama
relis3 天前
解密llama.cpp:Prompt Processing如何实现高效推理?
prompt·llama
GEO_JYB4 天前
BERT家族进化史:从BERT到LLaMA,每一次飞跃都源于对“学习”的更深理解
学习·bert·llama
AI大模型5 天前
大模型开发实战:使用 LLaMA Factory 微调与量化模型并部署至 Ollama
程序员·llm·llama
relis5 天前
解密llama.cpp:从Prompt到Response的完整技术流程剖析
prompt·llama
我不是小upper5 天前
Llama v3 中的低秩自适应 (LoRA)
llama
df007df11 天前
【RAGFlow代码详解-10】文本处理和查询处理
人工智能·ocr·embedding·llama