Skip to content

Port of Facebook's LLaMA model in C/C++

License

Notifications You must be signed in to change notification settings

Rayrtfr/llama.cpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

使用llama.cpp量化部署

llama.cpp工具为例,介绍模型量化并在本地部署的详细步骤。Windows则可能需要cmake等编译工具的安装。本地快速部署体验推荐使用经过指令精调的Atom-7B-Chat模型,有条件的推荐使用6-bit或者8-bit模型,效果更佳。 运行前请确保:

  1. 系统应有make(MacOS/Linux自带)或cmake(Windows需自行安装)编译工具
  2. 建议使用Python 3.10以上编译和运行该工具

Step 1: 克隆和编译llama.cpp

  1. (可选)如果已下载旧版仓库,建议git pull拉取最新代码,并执行make clean进行清理
  2. 拉取最新版适配过Atom大模型的llama.cpp仓库代码
$ git clone https://github.com/Rayrtfr/llama.cpp
  1. 对llama.cpp项目进行编译,生成./main(用于推理)和./quantize(用于量化)二进制文件。
$ make

Windows/Linux用户如需启用GPU推理,则推荐与BLAS(或cuBLAS如果有GPU)一起编译,可以提高prompt处理速度。以下是和cuBLAS一起编译的命令,适用于NVIDIA相关GPU。参考:llama.cpp#blas-build

$ make LLAMA_CUBLAS=1

macOS用户无需额外操作,llama.cpp已对ARM NEON做优化,并且已自动启用BLAS。M系列芯片推荐使用Metal启用GPU推理,显著提升速度。只需将编译命令改为:LLAMA_METAL=1 make,参考llama.cpp#metal-build

$ LLAMA_METAL=1 make

Step 2: 生成量化版本模型

目前llama.cpp已支持.safetensors文件以及huggingface格式.bin转换为GGUF的FP16格式。

$ python convert.py --outfile ./atom-7B-cpp.gguf  /path/Atom-7B-Chat

$ ./quantize ./atom-7B-cpp.gguf ./ggml-atom-7B-q4_0.gguf q4_0

Step 3: 加载并启动模型

  • 如果想使用GPU推理:cuBLAS/Metal编译需要指定offload层数,在./main中指定例如-ngl 40表示offload 40层模型参数到GPU

使用以下命令启动聊天。

text="<s>Human: 介绍一下北京\n</s><s>Assistant:"
./main -m \
./ggml-atom-7B-q4_0.gguf \
-p "${text}"  \
--logdir ./logtxt 

如果要带聊天的上下文,上面的text需要调整成类似这样:

text="<s>Human: 介绍一下北京\n</s><s>Assistant:北京是一个美丽的城市</s>\n<s>Human: 再介绍一下合肥\n</s><s>Assistant:"

更详细的官方说明请参考:https://github.com/Rayrtfr/llama.cpp/tree/master/examples/main

About

Port of Facebook's LLaMA model in C/C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 65.6%
  • C 18.8%
  • Cuda 5.0%
  • Python 4.2%
  • Metal 2.6%
  • Objective-C 1.7%
  • Other 2.1%