5.llama.cpp编译及使用

llama.cpp的编译及使用

下载源码

安装依赖库

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

编译

支持cuda

复制代码
cd llama.cpp
mkdir build
cd build
cmake .. -DLLAMA_CUBLAS=ON
make -j8

最后在build/bin目录下生成

下载模型

模型量化

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

在build/bin找到quantize

在较新版本默认生成的是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 指定模型

相关推荐
爱跑步的程序员~9 小时前
SpringBoot集成SpringAI与Ollama本地大模型
java·后端·spring·ai·llama·springai
向量引擎小橙2 天前
视觉艺术的“奇点”:深度拆解 Gemini-3-Pro-Image-Preview 绘画模型,看这只“香蕉”如何重塑 AI 创作逻辑!
人工智能·python·gpt·深度学习·llama
正宗咸豆花2 天前
开源大模型涨价策略分析:Llama 3.5 与 GLM-5 的商业化博弈
开源·llama
qq_214803293 天前
使用 LLaMA-Factory 微调 Qwen2.5 模型,并转换为 GGUF 格式部署
llama
yyoc976 天前
Mac基于LLaMA Factory微调模型导入Ollama踩坑记录
大模型·微调·llama·ollama
zhangfeng11336 天前
大语言模型调试框架 Hugging Face vs LLaMA-Factory详细对比
人工智能·语言模型·llama
zhangfeng11336 天前
大语言模型 llama-factory 通常不推荐只用 LoRA 做新词库预热 embedding
深度学习·语言模型·llama
木卫二号Coding7 天前
第八十篇-E5-2680V4+V100-32G+llama-cpp运行+Qwen3-Next-80B-UD-Q2_K_XL.GGUF
llama
小明_GLC8 天前
大模型微调 PEFT vs LLaMA-Factory
人工智能·llama·peft·大模型微调·方法对比
打工小熊猫8 天前
langSmith接入说明
llama