# Llama.cpp

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. 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

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

* 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