继续折腾下 llama.cpp + Chinese-LLaMA-Alpaca

五一有点空,继续折腾下 llama.cpp。

本来应该优先折腾这个的,毕竟更出名,不过同事折腾过 gpt4all,也是 llama,但似乎中文支持不怎么样的,觉得不行就没看。顺便网上找找,看看融合 Chinese-LLaMA-Alpaca 的中文怎么样

操作环境:Windows 11 Python 3.10


下载并生成 llama.cpp

下载代码

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

生成

mkdir build
cd build
cmake ..
cmake --build . --config Release

试运行

cd bin\Release
./main -h

下载 llama 7b 模型

下载 llama 半精度模型

$env:GIT_LFS_SKIP_SMUDGE=1
git lfs install
git clone https://huggingface.co/decapoda-research/llama-7b-hf
git lfs pull

下载 Chinese-LLaMA-Alpaca

git clone https://ghproxy.com/github.com/ymcui/Chinese-LLaMA-Alpaca.git

下载 chinese alpaca lora-7b 模型

$env:GIT_LFS_SKIP_SMUDGE=1
git lfs install
https://huggingface.co/ziqingyang/chinese-alpaca-lora-7b
git lfs pull

模型融合

使用 ymcui/Chinese-LLaMA-Alpaca 里面的 scripts/merge_llama_with_chinese_lora.py 脚本对原版 LLaMA 模型(HF格式)扩充中文词表,并与 LoRA 权重进行合并,生成全量模型权重 consolidated.*.pth(建议检查生成模型的 SHA256 值)和配置文件 params.json

cd Chinese-LLaMA-Alpaca
python scripts/merge_llama_with_chinese_lora.py --base_model D:\test\ai\llama\llama-7b-hf --lora_model D:\test\ai\llama\chinese-alpaca-lora-7b --output_dir ./ggml-model-chinese-alpaca-lora-7b/

把生成的 tokenizer.model 文件放入 llama.cpp/models 目录下,其他小文件放入 llama.cpp/models/7B 目录下。

转换为 ggml fp16 模型

cd llama.cpp
python convert.py D:\test\ai\llama\Chinese-LLaMA-Alpaca\ggml-model-chinese-alpaca-lora-7b

量化为 4bit

cd build/bin/Release
./quantize  D:\test\ai\llama\Chinese-LLaMA-Alpaca\ggml-model-chinese-alpaca-lora-7b/ggml-model-f16.bin ../../../models/7B/ggml-model-q4_0.bin q4_0 4

删除临时文件

rm -R D:\test\ai\llama\Chinese-LLaMA-Alpaca\ggml-model-chinese-alpaca-lora-7b

运行

./main -m ../../../models/7B/ggml-model-q4_0.bin --color -f ../../../prompts/alpaca.txt -ins -c 2048 --temp 0.2 --repeat_penalty 1 -n 4096

速度倒是很快。不过这中文理解能力有问题啊。。前面问小说,后面不问了也是回答小说。。。

写一段 c 操作串口的代码,还是不行。。


Share Tweet Send
0 Comments
Loading...

Related Articles

You've successfully subscribed to 隔窗听雨
Great! Next, complete checkout for full access to 隔窗听雨
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.
豫ICP备19045256号-1