llama.cpp编译和运行 API调用
llama.cpp介绍
llama.cpp是一个开源项目,官方地址:https://github.com/ggerganov/llama.cpp,使用纯 C/C++推理 Meta 的LLaMA模型,专门为在本地CPU上部署量化模型而设计。
它提供了一种简单而高效的方法,将训练好的量化模型转换为可在CPU上运行的低配推理版本,可加快推理速度并减少内存使用。
llama.cpp优势
-
高性能:llama.cpp针对CPU进行了优化,能够在保证精度的同时提供高效的推理性能。
-
低资源:由于采用了量化技术,llama.cpp可以显著减少模型所需的存储空间和计算资源,可运行在端侧设备上。
-
易集成:llama.cpp提供了简洁的API和接口,方便开发者将其集成到自己的项目中。
-
跨平台支持:llama.cpp可在多种操作系统和CPU架构上运行,具有很好的可移植性。
llama.cpp编译
安装编译环境
sudo apt install cmake g++ git
下载源代码
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp/
cd build/
编译
cmake ..
make
gcc --version
g++ --version
cmake .. -DCMAKE_CXX_FLAGS="-mavx -mfma"
cmake --build build --config Release -march=native -mtune=native
cmake -march=native -mtune=native --build build --config Release
cmake -DLLAMA_NATIVE=OFF
cmake -B build -DGGML_LLAMAFILE=OFF
编译完成后,会生成很多可执行文件,如图
llama.cpp运行
llama.cpp提供了与OpenAI API兼容的API接口,使用make生成的llama-server来启动API服务
本地启动 HTTP 服务器,使用端口:8080 指定Llama-3.1-8B-Instruct推理模型
.llama-server.exe -m E:ai_modelImstudio-ailmstudio-communityMeta-Llama-3.1-8B-Instruct-GGUFMeta-Llama-3.1-8B-Instruct-Q4_K_M.gguf --port 8080
调用API服务
curl --request POST --url http://localhost:8080/completion
--header "Content-Type: application/json"
--data '{"prompt": "介绍一下llama.cpp"}'
```
文章来源于互联网:llama.cpp编译和运行 API调用
前言 哈喽~大家好! 今天为大家带来一份史无前例的人工智能学习路线。相信大家都喜欢看修仙小说,修仙小说中的炼气、筑基、金丹等各种境界,让人热血沸腾。今天,我就将AI学习路线和修仙故事巧妙地融合在一起,通过修仙等级来形象地展示学习Stable Diffusion…
5bei.cn大模型教程网











