llama.cpp¶
What it is¶
llama.cpp is a lightweight C/C++ inference runtime for running GGUF/quantized LLMs locally on commodity hardware. It is the foundational library that enables efficient local execution of frontier-class models like Llama 4 Maverick and Gemma 3.
What problem it solves¶
It makes local LLM inference practical on CPUs and smaller devices by combining quantization support with optimized low-level inference paths. It solves the hardware barrier for running large models by allowing high-quality 4-bit and 8-bit quantized models to run with minimal performance loss.
Where it fits in the stack¶
Infrastructure / Inference Runtime. It is a core local-serving building block used directly or via wrappers like Ollama or LM Studio.
Typical use cases¶
- Running quantized LLMs offline on laptops, servers, or edge devices.
- Serving as a backend for agentic frameworks using Claude 4.8 or GPT-5.5 via OpenAI-compatible APIs.
- Powering local-first RAG applications with high throughput and low latency.
- Fine-tuning or testing quantization strategies for new model architectures.
- Providing a local inference engine for Model Context Protocol (MCP) tool-calling.
Strengths¶
- Native MCP Support: Includes built-in support for the Model Context Protocol (MCP), allowing local models to interact with tools directly.
- Portability: Minimal dependencies and high performance across Apple Silicon (Metal), NVIDIA (CUDA), and standard CPUs.
- Structured Output: Support for GBNF grammars ensures models follow strict JSON or custom formats, critical for agentic tool use.
- Broad Model Support: Rapid integration of new architectures, including Llama 4 Maverick and DeepSeek-V3.
- Efficiency: State-of-the-art quantization techniques (K-Quants, IQ-Quants) minimize VRAM usage while maintaining accuracy.
Limitations¶
- Manual Tuning: Requires understanding of parameters like thread counts, batch sizes, and GPU layer offloading for optimal performance.
- Quantization Trade-offs: While highly efficient, extreme quantization (e.g., <3-bit) can lead to noticeable degradation in reasoning.
- VRAM Constraints: Running the largest frontier models (70B+) still requires significant hardware even when quantized.
- CLI Focus: The primary interface is a command-line tool, which may be intimidating for non-technical users.
When to use it¶
- When you need maximum control over inference parameters and hardware acceleration.
- For local-first, privacy-conscious applications that cannot rely on cloud APIs.
- When running models on Apple Silicon where Metal acceleration provides significant gains.
- When developing custom applications that require a lightweight, embeddable LLM engine.
When not to use it¶
- If you prefer a "plug-and-play" experience with automatic model management (use Ollama instead).
- For massive-scale production deployments where specialized engines like vLLM may offer better multi-request batching.
- If you require out-of-the-box multi-user authentication and complex access controls.
Getting started¶
Installation¶
Clone the repository and build for your hardware:
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
# For Apple Silicon
make LLAMA_METAL=1
# For NVIDIA CUDA
# make LLAMA_CUDA=1
Quick Start: Running a Server¶
Download a GGUF model and start the OpenAI-compatible server:
./llama-server -m models/llama-4-maverick-8b.Q4_K_M.gguf -c 4096 --port 8080
CLI examples¶
1. Basic Inference¶
Run a simple completion from the command line:
./llama-cli -m models/llama-4-maverick-8b.Q4_K_M.gguf -p "The capital of France is" -n 10
2. GPU Layer Offloading¶
Offload 99 layers to the GPU (useful for Metal or CUDA):
./llama-cli -m models/llama-4-maverick-8b.Q4_K_M.gguf -ngl 99 -p "How does quantization work?"
3. Using GBNF Grammars¶
Force the model to output a valid JSON object:
./llama-cli -m models/llama-4-maverick-8b.Q4_K_M.gguf --grammar-file grammars/json.gbnf -p "Respond with a JSON object containing name and age."
API examples¶
Python Integration (OpenAI Compatible)¶
Since llama.cpp server provides an OpenAI-compatible endpoint, you can use the standard openai library:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8080/v1", api_key="sk-no-key-required")
response = client.chat.completions.create(
model="llama-4-maverick",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the benefit of GGUF format."}
]
)
print(response.choices[0].message.content)
MCP Tool Access¶
llama.cpp can serve as an MCP client or server. Example of configuring a tool in an MCP-aware environment:
{
"mcpServers": {
"llama-cpp": {
"command": "./llama-server",
"args": ["-m", "models/llama-4-maverick-8b.Q4_K_M.gguf", "--mcp"]
}
}
}
Related tools / concepts¶
- Ollama - Opinionated wrapper for llama.cpp.
- vLLM - High-throughput inference engine for NVIDIA GPUs.
- ExLlamaV2 - Optimized inference for 4-bit EXL2 models.
- Local LLMs - Overview of the local inference ecosystem.
- MCP (Model Context Protocol) - Standard for connecting models to tools.
- Llama 4 Maverick - Target model architecture for local deployment.
- Quantization Concepts - Technical background on weights compression.
- GGUF Format - The standard file format for llama.cpp.
Sources / references¶
Contribution Metadata¶
- Last reviewed: 2026-06-28
- Confidence: high