国有平台公司是什么意思,台州seo网站推广,乐清 网站建设,网络游戏中心首先讲一下环境
这是2024 年12月#xff0c;llama.cpp 的编译需要cmake 呜呜呜 网上教程都是make 跑的。反正我现在装的时候make已经不再适用了#xff0c;因为工具的版本#xff0c;捣鼓了很久。 ubuntu 18 conda env内置安装。
以下是可以完美编译llama.cpp的测试工具版…首先讲一下环境
这是2024 年12月llama.cpp 的编译需要cmake 呜呜呜 网上教程都是make 跑的。反正我现在装的时候make已经不再适用了因为工具的版本捣鼓了很久。 ubuntu 18 conda env内置安装。
以下是可以完美编译llama.cpp的测试工具版本号 gcc9 g9 #只要大于等于9 版本都集成了cmake是要的c17指令集gcc8测试了要手动软链 麻烦 反正凉 cuda 11.8 #cuda 版本11 或者12 都行10测试了不行 cmake 3.22 # camke 大于等于3.14 都行 安装gcc 9/g 9
ubuntu 18默认只能安装到gcc/g 8 需要安装gcc9需要添加新的ppd
添加ppa源
sudo add-apt-repository ppa:ubuntu-toolchain-r/test#有问题的话在https://launchpad.net/~ubuntu-toolchain-r/archive/ubuntu/test?field.series_filtertrusty网址中找到ppa源可以尝试手动添加 #打开 .list文件
vim /etc/apt/sources.list
# 文件末尾添加 bionic 是代表系统ubuntu18
deb https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu bionic main
deb-src https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu bionic main 2. 更新apt-get
sudo apt-get update更新时可能出错
#我在apt-get update 的时候报错
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [102 kB]
Err:1 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InReleaseThe following signatures couldn\t be verified because the public key is not available: NO_PUBKEY 2C277A0A352154E5 NO_PUBKEY 1E9377A2BA9EF27F
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [102 kB]
Reading package lists... Done
W: GPG error: http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease: The following signatures couldn\t be verified because the public key is not available: NO_PUBKEY 2C277A0A352154E5 NO_PUBKEY 1E9377A2BA9EF27F
E: The repository http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease is not signed.解决 根据错误消息中的 NO_PUBKEY 部分系统丢失了两个公钥分别是 2C277A0A352154E5 和 1E9377A2BA9EF27F。可以手动添加这两个公钥。
#添加公钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2C277A0A352154E5
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F
#重新更新
sudo apt-get update其他错误参考这几个文章实在不行的话自行google看看了 有bug时查ubuntu无法添加PPA的解决办法 因不能翻墙时查ubuntu下apt添加第三方ppa源
3.下载gcc9和g9
sudo apt install gcc-9 g-9切换版本90是当前版本优先级数值越大优先级越高系统默认使用优先级最高的
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g g /usr/bin/g-9#其他指令
# 查看当前系统有的gcc
ls /usr/bin/gcc*
# 查看当前所用gcc/cmake
gcc --version
cmake --version如果上面在线安装你网络有问题建议离线安装 最后办法参考离线安装gcc/g 9
离线安装需要注意
如果你是手动安装的话要注意libstdc的版本是否匹配上gcc 9.5.0 需要libstdc支持至少GLIBCXX 3.26以上版本 #查看你的系统libstdc是否有GLIBCXX 3.26
strings /usr/lib/x86_64-linux-gnu/libstdc.so.6 | grep GLIBCXX没有的话要安装或更新 libstdc
sudo apt-get update
sudo apt-get install libstdc6可以通过以下程序测试一下你的gcc是否能够正确编译c17指令集
//可以尝试编译一个简单的 C17 示例程序创建一个简单的 test_filesystem.cpp 文件如下所示
#include iostream
#include filesystemint main() {std::filesystem::path p .;for (const auto entry : std::filesystem::directory_iterator(p)) {std::cout entry.path() std::endl;}return 0;
}然后使用以下命令进行编译没报错就是 正常
g -stdc17 test_filesystem.cpp -o test_filesystem
./test_filesystem接下来可以下载和编译llama.cpp
1.下载 llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git2.cmake编译参考这个官方https://github.com/ggerganov/llama.cpp/blob/master/docs/build.md cd llama.cpp
# 如果需要llama支持 cudacpu版本的话直接去掉-DGGML_CUDAON就可以了
cmake -B build -DGGML_CUDAON
cmake --build build --config Releaseeee… 按照这几个版本工具编译 应该没问题 亲测跑通
测试使用llama.cpp 跑本地模型
参考这个https://zhuanlan.zhihu.com/p/690548599
以mistral 7b v3 为例子先下载模型
pip install -U huggingface_hub
# 建议将下面这一行写入 ~/.bashrc。若没有写入则每次下载时都需要先输入该命令
export HF_ENDPOINThttps://hf-mirror.com huggingface上申请你的token然后执行下载
huggingface-cli download mistralai/Mistral-7B-Instruct-v0.3 --local-dir Mistral-7B-Instruct-v0.3 --local-dir-use-symlinks False --resume-download --token your_name_token_hf进入llama.cpp 目录利用llama.cpp 转化工具 把模型转成.guff文件/XX/model/Mistral-7B-Instruct-v0.3/是你本地的模型路径
python3 convert_hf_to_gguf.py /XX/model/Mistral-7B-Instruct-v0.3/3.量化模型压缩一下让跑的时候别吃太多内存当然性能会有影响。XXX/model/Mistral-7B-Instruct-v0.3/Mistral-7B-Instruct-v0.3-F16.gguf是你本地需要压缩模型路径./myllms/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf是压缩完存储名称。Q4_K_M表示压缩类型是INF4
#camke后生成的压缩指令路径是这个./build/bin/llama-quantize./build/bin/llama-quantize /XXX/model/Mistral-7B-Instruct-v0.3/Mistral-7B-Instruct-v0.3-F16.gguf ./myllms/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf Q4_K_M压缩成功长这样 4.执行量化模型./build/bin/llama-cli 指令
#不知道指令在哪的话 find 一下
#在当前目录及子目录中查找包含字符串的文件
find . -type f -exec grep -H search_string {} \;./build/bin/llama-cli -m ./myllms/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf -n 128
## 自动化跑了个测试,test example as follows:
## Q: Solve 5*u - 4*m 33, -3*u - 2*m 3 - 12 for u.
## A: 3 [end of text]想要和模型交互的话用这个
./build/bin/llama-cli -m ./myllms/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf --color -cnv交互界面如下绿色是我输入的问题mistral 正在回答
llama-cli的参数 参考这里 https://github.com/ggerganov/llama.cpp/tree/master/examples/main