5.llama.cpp编译及使用

5.llama.cpp编译及使用

    正在检查是否收录...

llama.cpp的编译及使用

下载源码

llama.cpp
https://github.com/ggerganov/llama.cpp 
ggml 向量库
https://github.com/ggerganov/ggml 

安装依赖库

cmake 编译:版本稍高一些,我的是3.22

编译

支持cuda

cd llama.cpp mkdir build cd build cmake .. -DLLAMA_CUBLAS=ON make -j8 

最后在build/bin目录下生成

下载模型

meta官网下载,贼麻烦
https://ai.meta.com/llama/ 
https://huggingface.co/meta-llama 
huggingface下载
https://huggingface.co/ 
Linly: 国内Linly开源
https://github.com/CVI-SZU/Linly 

模型量化

模型量化的python代码在llama.cpp下面找到。在硬件资源有限的情况下才对模型进行量化。
在build/bin找到quantize

模型下载
https://huggingface.co/meta-llama/Llama-2-7b-hf 
模型转换
convert the 7B model to ggml FP16 format 默认做当前目录下生成ggml模型ggml-model-f16.bin
python convert.py models/llama-2-7b-hf/ 

在较新版本默认生成的是ggml-model-f16.gguf

模型量化
quantize the model to 4-bits (using q4_0 method) 进一步对FP16模型进行4-bit量化
./quantize ./models/llama-2-7b-hf/ggml-model-f16.bin ./models/llama-2-7b-hf/ggml-model-q4_0.bin q4_0 

模型推理

在build/bin找到main

./main -ngl 30 -m ./models/llama-2-7b-hf/ggml-model-q4_0.bin --color -f ./prompts/chat-with-vicuna-v0.txt -ins -c 2048 --temp 0.2 -n 4096 --repeat_penalty 1.0 

Linly模型

自己动手处理

运行测试

测试用脚本
#!/bin/bash # llama 推理 #./main -ngl 30 -m ./models/7B/ggml-model-alpaca-7b-q4_0.gguf --color -f ./prompts/chat-with-vicuna-v0.txt -ins -c 2048 --temp 0.2 -n 4096 --repeat_penalty 1.3 # linly 基础模型 #./main -ngl 30 -m ./models/7B/linly-ggml-model-q4_0.bin --color -f ./prompts/chat-with-vicuna-v0.txt -ins -c 2048 --temp 0.2 -n 4096 --repeat_penalty 1.0 # linly chatflow模型 ./main -ngl 30 -m ./models/chatflow_7b/linly-chatflow-7b-q4_0.bin --color -f ./prompts/chat-with-vicuna-v0.txt -ins -c 2048 --temp 0.2 -n 4096 --repeat_penalty 1.0 # whisper llama #./whisper/talk-llama -l zh -mw ./models/ggml-small_q4_0.bin -ml ./models/7B/ggml-model-alpaca-7b-q4_0.gguf -p "lfrobot" -t 8 -c 0 -vth 0.6 -fth 100 -pe 
参数说明
比较重要的参数:
-ins 启动类ChatGPT的对话交流模式 -f 指定prompt模板,alpaca模型请加载prompts/alpaca.txt 指令模板 -c 控制上下文的长度,值越大越能参考更长的对话历史(默认:512) -n 控制回复生成的最大长度(默认:128) --repeat_penalty 控制生成回复中对重复文本的惩罚力度 --temp 温度系数,值越低回复的随机性越小,反之越大 --top_p, top_k 控制解码采样的相关参数 -b 控制batch size(默认:512) -t 控制线程数量(默认:8),可适当增加 -ngl 使用cuda核心数 -m 指定模型 

llamachatpromptpromptsalpacahuggingfacegithubflowgitpythonwhispergan对话交流python代码模型推理基础模型chatgpt控制生成gptbot
  • 本文作者:李琛
  • 本文链接: https://wapzz.net/post-16066.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
本站部分内容来源于网络转载,仅供学习交流使用。如涉及版权问题,请及时联系我们,我们将第一时间处理。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
2.3W+
5
0
1
WAP站长官方

开源模型应用落地-语音转文本-whisper模型-AIGC应用探索(一)

上一篇

使用llama.cpp在linux cuda环境部署llama2方法记录及遇到的问题

下一篇
  • 复制图片
按住ctrl可打开默认菜单