llama.cpp
{{Short description|Software library for LLM inference}}
{{Infobox software
| name = llama.cpp
| logo = File:Llama1-logo.svg
| author = Georgi Gerganov
| developer = Georgi Gerganov and community
| released = {{Start date and age|2023|3|10}}
| programming language = C++, C
| genre = Library for large language models
| license = MIT License
| repo = {{URL|github.com/ggml-org/llama.cpp}}
}}
{{Lowercase title}}
llama.cpp is an open source software library that performs inference on various large language models such as Llama. It is co-developed alongside the GGML project, a general-purpose tensor library.
Command-line tools are included with the library, alongside a server with a simple web interface.
Background
Towards the end of September 2022, Georgi Gerganov started work on the GGML library, a C library implementing tensor algebra. Gerganov developed the library with the intention of strict memory management and multi-threading. The creation of GGML was inspired by Fabrice Bellard's work on LibNC.
Before llama.cpp, Gerganov worked on a similar library called whisper.cpp which implemented Whisper, a speech to text model by OpenAI.
Development
llama.cpp began development in March 2023 by Georgi Gerganov as an implementation of the Llama inference code in pure C/C++ with no dependencies. This improved performance on computers without GPU or other dedicated hardware, which was a goal of the project. llama.cpp gained traction with users who lacked specialized hardware as it could run on just a CPU including on Android devices.{{cite web |last1=Hood |first1=Stephen |title=llamafile: bringing LLMs to the people, and to your own computer |url=https://future.mozilla.org/builders/news_insights/introducing-llamafile/ |website=Mozilla Innovations |access-date=28 July 2024 |language=en}}{{cite web |title=Democratizing AI with open-source language models |url=https://lwn.net/Articles/931853/ |website=lwn.net |access-date=28 July 2024}} While initially designed for CPUs, GPU inference support was later added. As of November 2024 it has more than 67,000 stars on GitHub.
In March 2024 Justine Tunney introduced new optimized matrix multiplication kernels for x86 and ARM CPUs, improving prompt evaluation performance for FP16 and 8-bit quantized data types. These improvements were committed upstream to llama.cpp. Tunney also created a tool called llamafile that bundles models and llama.cpp into a single file that runs on multiple operating systems via the Cosmopolitan Libc library also created by Tunney which allows C/C++ to be more portable across operating systems.
Architecture
llama.cpp supports multiple hardware targets including x86, ARM, CUDA, Metal, Vulkan (version 1.2 or greater) and SYCL. These back-ends make up the GGML tensor library which is used by the front-end model-specific llama.cpp code. llama.cpp supports ahead of time model quantization as opposed to on-the-fly quantization. llama.cpp makes use of several CPU extensions for optimization: AVX, AVX2 and AVX-512 for X86-64, and Neon on ARM. Apple silicon is an important target for the project. It supports grammar-based output formatting as JSON. It also supports speculative decoding.
GGUF file format
{{Infobox file format
| name = GGUF
| icon = GGML_logo.svg
| _noextcode = on
| extension = {{code|.gguf}}
| magic = {{code|0x47}} {{code|0x47}} {{code|0x55}} {{code|0x46}}
| developer = Georgi Gerganov and community
| released = {{Start date and age|2023|8|22}}
| type = Machine-learning tensors
}}
The GGUF (GGML Universal File) file format is a binary format that stores both tensors and metadata in a single file, and is designed for fast saving, and loading of model data. It was introduced in August 2023 by the llama.cpp project to better maintain backwards compatibility as support was added for other model architectures. It superseded previous formats used by the project such as GGML.
GGUF files are typically created by converting models developed with a different machine learning library such as PyTorch.
= Design =
The format focuses on quantization, the act of reducing precision in the model weights. This can lead to reduced memory usage, and increased speed at the expense of lower model accuracy.
GGUF supports 2-bit to 8-bit quantized integer types; common floating-point data formats such as float32, float16, and bfloat16; and 1.56 bit quantization.
This file format contains information necessary for running a GPT-like language model such as the tokenizer vocabulary, context length, tensor info and other attributes.
Supported models
{{div col|colwidth=15em}}
- LLaMA
- Llama 2
- Llama 3
- Mistral 7B
- Mixtral 8x7B
- Mixtral 8x22B
- DBRX
- BERT
- GPT-2
- BLOOM
- Gemma
- Grok-1
- Mamba
- GPT-NeoX
- Flan T5
- DeepSeek
- IBM Granite
{{div col end}}
References
{{Reflist|refs=
{{cite web |last1=Gerganov |first1=Georgi |title=ggerganov/ggml |website=GitHub |url=https://github.com/ggerganov/ggml |date=17 May 2024}}
{{cite web |title=ggerganov/llama.cpp |website=GitHub |url=https://github.com/ggerganov/llama.cpp}}
{{cite web |title=ggerganov/whisper.cpp |website=GitHub |url=https://github.com/ggerganov/whisper.cpp}}
}}
Category:Large language models