跳转到内容

llama.cpp

本页使用了标题或全文手工转换
维基百科,自由的百科全书

llama.cpp
原作者Georgi Gerganov
开发者Georgi Gerganov与社群
首次发布2023年3月10日,​3年前​(2023-03-10)[1]
当前版本
  • 0.9.0(2026年11月4日;稳定版本)[2]
编辑维基数据链接
原始码库github.com/ggml-org/llama.cpp
编程语言C++、C
类型大型语言模型函数库
许可协议MIT许可证[3]
网站llama.app/ 编辑维基数据

llama.cpp是用来在多种大型语言模型(例如LLaMA)上执行推理的开放原始码函数库。[4]此函数库中也包含了命令行工具[5]以及界面简易的网络应用程式伺服器。[6][7]

背景

[编辑]

2022年9月底,Georgi Gerganov开始开发GGML函数库,这是实现张量代数的C语言函数库。Gerganov开发GGML函数库的目的是实现严格的存储器管理与多线程。GGML的建立则是受到法布里斯·贝拉开发LibNC的启发。[8]

在开发llama.cpp之前,Gerganov曾经开发过类似的函数库,为使用OpenAI语音转文字模型Whisper(英语:Whisper (speech recognition system))的whisper.cpp。[9]

开发

[编辑]

Georgi Gerganov从2023年3月开始开发llama.cpp,llama.cpp是LLaMA推理代码的无外部依赖关系纯C/C++实现。llama.cpp改善了在没有图形处理器或其他专用硬件的电脑上的性能,这也是此项目的其中一个目标。[4][10][11]因为可以仅在中央处理器上执行(甚至可以在Android上运作),llama.cpp得到了缺乏专用硬件的用户青睐。[10][12]虽然一开始是为CPU设计的,但后来还是新增了GPU推理支持。[13]

2024年3月,Justine Tunney为x86与ARM CPU引入新的优化矩阵乘法核心至此项目,改善了FP16与8位量化数据类型的提示词评估性能。[14]Tunney也制作了llamafile这套工具,这套工具把模型与llama.cpp集成到单一个文件中,并可透过同样由Tunney开发的Cosmopolitan Libc函数库在多个操作系统上执行。[14]

架构

[编辑]

llama.cpp支持多种硬件目标,包含x86、ARM、CUDA、Metal、Vulkan(1.2或更新版本)与SYCL。[15][16][17][18]这些后端构成了GGML张量函数库,并供llama.cpp中不同模型的代码使用。[19]llama.cpp支持提前而非即时量化模型。[20]llama.cpp也使用了多种CPU扩展指令集优化性能:x86-64的AVX、AVX2与AVX-512,以及ARM上的Neon。Apple晶片也是此项目的重要目标。[21][22]

GGUF文件格式

[编辑]
GGUF
扩展名.gguf
开发者Georgi Gerganov与社群
首次发布2023年8月22日,​3年前​(2023-08-22)[23]
最新版本
格式类型机器学习张量

GGUF(GGML通用文件)[25]文件格式是二进制格式,将张量与元数据存储在同一个文件中,用以快速存储与加载模型资料。[26]此文件格式是llama.cpp项目于2023年8月开始使用,在新增对其他模型架构的支持时也维持向后兼容性。[13][27]

GGUF文件通常是透过转换以PyTorch等其他机器学习函数库开发的模型所建立的。[26]

设计

[编辑]

此格式着重于量化,亦即降低模型权重的精确度。如此可以降低存储器使用量,提升速度,缺点是会降低模型精度。[28][27]

GGUF支持2位元至8位的量化整数类型[29],以及常见的浮点资料格式(如float32、float16与bfloat16)与1.56位元量化。[5]

参考资料

[编辑]
  1. ^ Initial release · ggerganov/llama.cpp@26c0846. GitHub. [2025-07-12]. (原始内容存档于2025-01-16) (英语). 
  2. ^ Release 0.9.0. 2026年11月4日 [2026年11月4日]. 
  3. ^ llama.cpp/LICENSE at master · ggerganov/llama.cpp. GitHub. [2025-07-12]. (原始内容存档于2025-01-30) (英语). 
  4. ^ 4.0 4.1 Connatser, Matthew. How this open source LLM chatbot runner hit the gas on x86, Arm CPUs. theregister.com. [2025-07-12]. (原始内容存档于2024-05-10). 
  5. ^ 5.0 5.1 Mann, Tobias. Honey, I shrunk the LLM! A beginner's guide to quantization – and testing it. theregister. 2024-07-14 [2025-07-12]. (原始内容存档于2025-07-06). 
  6. ^ Alden, Daroc. Portable LLMs with llamafile [LWN.net]. lwn.net. [2024-07-30]. (原始内容存档于2025-03-06). 
  7. ^ Mann, Tobias. Intro to speculative decoding: Cheat codes for faster LLMs. theregister. 2024-12-15 [2025-07-12]. (原始内容存档于2026-04-30) (英语). 
  8. ^ Bringing Whisper and LLaMA to the masses with Georgi Gerganov (Changelog Interviews #532). Changelog. 2023-03-22 [2025-07-12]. (原始内容存档于2025-07-08) (英语). 
  9. ^ ggerganov/whisper.cpp. GitHub. [2025-07-12]. (原始内容存档于2025-04-03). 
  10. ^ 10.0 10.1 Edwards, Benj. You can now run a GPT-3-level AI model on your laptop, phone, and Raspberry Pi. arstechnica.com. 2023-03-13 [2025-07-12]. (原始内容存档于2024-01-09). 
  11. ^ Wiest, Isabella Catharina; Ferber, Dyke; Zhu, Jiefu; van Treeck, Marko; Meyer, Meyer, Sonja K.; Juglan, Radhika; Carrero, Zunamys I.; Paech, Daniel; Kleesiek, Jens; Ebert, Matthias P.; Truhn, Daniel; Kather, Jakob Nikolas. Privacy-preserving large language models for structured medical information retrieval. npj Digital Medicine. 2024, 7 (257): 257. PMC 11415382 可免费查阅. PMID 39304709. doi:10.1038/s41746-024-01233-2. 
  12. ^ Democratizing AI with open-source language models. lwn.net. [2025-07-12]. (原始内容存档于2024-07-28). 
  13. ^ 13.0 13.1 Rajput, Saurabhsingh; Sharma, Tushar. Benchmarking Emerging Deep Learning Quantization Methods for Energy Efficiency. 2024 IEEE 21st International Conference on Software Architecture Companion (ICSA-C). 2024-06-04: 238–242. ISBN 979-8-3503-6625-9. doi:10.1109/ICSA-C63560.2024.00049. 
  14. ^ 14.0 14.1 Connatser, Matthew. Llamafile LLM driver project boosts performance on CPU cores. www.theregister.com. [2024-05-10]. (原始内容存档于2024-05-10) (英语). 
  15. ^ Gerganov, Georgi; Nguyen, Xuan Son; Slaren. Introduction to ggml. Huggingface. 2024-08-13 [2025-07-12]. (原始内容存档于2025-06-03). 
  16. ^ Kluska, Piotr; Castell´o, Adri´an; Scheidegger, Florian; I. Malossi, A. Cristiano; Quintana-Ort´ı, Enrique. QAttn: Efficient GPU Kernels for mixed-precision Vision Transformers (PDF). Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops. June 2024 [2025-07-12]. (原始内容存档 (PDF)于2024-11-10). 
  17. ^ Jianyu, Zhang; Hengyu, Meng; Ying, Hu; Yu, Luo; Xiaoping, Duan; Corporation, Majumder Abhilash Intel. Run LLMs on Intel GPUs Using llama.cpp. The Parallel Universe. No. 57 (Intel). 2024-07: 34–37 [2025-07-12]. (原始内容存档于2026-04-23) (英语). 
  18. ^ Bolz, Jeff. Machine Learning in Vulkan with Cooperative Matrix 2 (PDF). Cambridge, UK: The Khronos Group/Nvidia. 2025-02-11 [2025-07-12]. (原始内容存档 (PDF)于2025-04-17) (英语). 
  19. ^ Pounder, Les. How To Create Your Own AI Chatbot Server With Raspberry Pi 4. tomshardware.com. 2023-03-25 [2025-07-12]. (原始内容存档于2023-08-15). 
  20. ^ Walkowiak, Bartosz; Walkowiak, Tomasz. Implementation of language models within an infrastructure designed for Natural Language Processing (PDF). International Journal of Electronics and Telecommunications. 2024, 70 (1): 153–159 [2025-07-12]. doi:10.24425/ijet.2024.149525. (原始内容存档 (PDF)于2026-04-22). 
  21. ^ ggerganov/llama.cpp. GitHub. [2025-07-12]. (原始内容存档于2025-02-12). 
  22. ^ Larabel, Michael. Llamafile 0.7 Brings AVX-512 Support: 10x Faster Prompt Eval Times For AMD Zen 4. www.phoronix.com. 2024-03-31 [2025-07-12]. (原始内容存档于2025-03-13) (英语). 
  23. ^ GGUF by ggerganov · Pull Request #2398 · ggerganov/llama.cpp. GitHub. [2025-07-12]. (原始内容存档于2025-01-16) (英语). 
  24. ^ ggml/docs/gguf.md at master · ggerganov/ggml. GitHub. [2025-07-12]. (原始内容存档于2025-01-31) (英语). 
  25. ^ ggerganov/llama.cpp/gguf-py/README.md. GitHub. [2025-07-12]. (原始内容存档于2025-02-14). 
  26. ^ 26.0 26.1 GGUF. huggingface.co. [2025-07-12]. (原始内容存档于2026-07-17). 
  27. ^ 27.0 27.1 Mucci, Tim. GGUF versus GGML. www.ibm.com. 2024-07-03 [2025-07-12]. (原始内容存档于2025-06-04) (美国英语). 
  28. ^ Labonne, Maxime. Quantize Llama models with GGUF and llama.cpp. Medium. Towards Data Science. 2023-11-29 [2024-05-09]. (原始内容存档于2024-05-09) (英语). 
  29. ^ Cabezas, Darío; Fonseca-Delgado, Rigoberto; Reyes-Chacón, Iván; Vizcaino-Imacaña, Paulina; Morocho-Cayamcela, Manuel. Integrating a LLaMa-based Chatbot with Augmented Retrieval Generation as a Complementary Educational Tool for High School and College Students. Proceedings of the 19th International Conference on Software Technologies. 2024: 395–402. ISBN 978-989-758-706-1. doi:10.5220/0012763000003753.