中文Llama & Alpaca大模型2:https://github.com/ymcui/Chinese-LLaMA-Alpaca-2
使用方法:https://github.com/ymcui/Chinese-LLaMA-Alpaca-2/wiki/llamacpp_zh
使用方法
1、克隆和编译llama.cpp。
地址:https://github.com/ggerganov/llama.cpp
2、生成量化版本模型。
在llama.cpp根目录,执行以下代码,将完整模型权重转换为GGML的FP16格式。
python convert.py E:/temp/chinese-alpaca-2-7b-hf
进一步对FP16模型进行4-bit量化。
./quantize E:/temp/chinese-alpaca-2-7b-hf/ggml-model-f16.gguf E:/temp/chinese-alpaca-2-7b-hf\ggml-model-q4_0.gguf q4_0
3、加载并启动模型。
创建文件 智能助手.cmd,写入以下代码。
@echo off
@chcp 65001
cd E:/github/llama.cpp
main -m E:/temp/chinese-alpaca-2-7b-hf/ggml-model-f16.gguf -n -1 --color --in-prefix "[User] " --in-suffix "[AI] " --interactive-first -e -c 4096 ^
-t 6 --temp 0.5 --top_k 40 --top_p 0.9 --repeat_penalty 1.1 --in-prefix-bos
命令使用请参考:https://github.com/ggerganov/llama.cpp/tree/master/examples/main
更多命令请参考:llama.cpp命令
常见问题
1、编译llama.cpp报错:d:/temp/w64devkit-1.21.0/w64devkit/bin/sh: nvcc: not found。
解决方法:w64devkit版本错误,应该下载 w64devkit-fortran-1.21.0.zip,而不是 w64devkit-1.21.0.zip 。
下载地址:https://github.com/skeeto/w64devkit/releases
需要安装CUDA Toolkit。
~ 2、编译llama.cpp报错:collect2.exe: error: ld returned 1 exit status。
清理llama.cpp仓库,重新打开命令行窗口,重新编译。
3、 undefined reference to `cblas_sgemm'。
安装 CUDA Toolkit 后使用 make LLAMA_CUBLAS=1 编译,不要使用 make LLAMA_OPENBLAS=1 编译。
主要:CUDA Toolkit路径不要包含空格。
4、使用 make LLAMA_CUBLAS=1 编译报错:nvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored. cl: 命令行 error D8021 :无效的数值参数“/Wno-array-bounds”
测试。
5、使用cmake编译报错:No CUDA toolset found.。
改为以下命令编译:
cmake .. -G "MinGW Makefiles" -DLLAMA_CUBLAS=ON -DLLAMA_CUDA_FORCE_DMMV=TRUE -DLLAMA_CUDA_DMMV_X=64 -DLLAMA_CUDA_MMV_Y=4 -DLLAMA_CUDA_F16=TRUE -DGGML_CUDA_FORCE_MMQ=YES
6、nvcc fatal : Cannot find compiler 'cl.exe' in PATH。
将目录加到环境变量Path中:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64。