Skip to main content
Use llama.cpp for CPU-only environments, local development, or edge deployment and on-device inference.
For GPU-accelerated inference at scale, consider using vLLM instead.

Installation

Install via Homebrew:

Downloading GGUF Models

llama.cpp uses the GGUF format, which stores quantized model weights for efficient inference. All LFM models are available in GGUF format on Hugging Face. See the Models page for all available GGUF models. You can download LFM models in GGUF format from Hugging Face as follows:
  • Q4_0: 4-bit quantization, smallest size
  • Q4_K_M: 4-bit quantization, good balance of quality and size (recommended)
  • Q5_K_M: 5-bit quantization, better quality with moderate size increase
  • Q6_K: 6-bit quantization, excellent quality closer to original
  • Q8_0: 8-bit quantization, near-original quality
  • F16: 16-bit float, full precision

Basic Usage

llama.cpp offers two main interfaces for running inference: llama-server (OpenAI-compatible server) and llama-cli (interactive CLI).
llama-server provides an OpenAI-compatible API for serving models locally.Starting the Server:
The -hf flag downloads the model directly from Hugging Face. Alternatively, use a local model file:
Key parameters:
  • -hf: Hugging Face model ID (downloads automatically)
  • -m: Path to local GGUF model file
  • -c: Context length (default: 4096)
  • --port: Server port (default: 8080)
  • -ngl 99: Offload layers to GPU (if available)
Using the Server:Once running at http://localhost:8080, use the OpenAI Python client:
Using curl:

Generation Parameters

Control text generation behavior using parameters in the OpenAI-compatible API or command-line flags. Key parameters:
  • temperature (float): Controls randomness (0.0 = deterministic, higher = more random). Typical range: 0.1-2.0
  • top_p (float): Nucleus sampling - limits to tokens with cumulative probability ≤ top_p. Typical range: 0.1-1.0
  • top_k (int): Limits to top-k most probable tokens. Typical range: 1-100
  • min_p (float): Filters tokens below min_p * max_probability. Typical range: 0.05-0.3
  • max_tokens / --n-predict (int): Maximum number of tokens to generate
  • repetition_penalty / --repeat-penalty (float): Penalty for repeating tokens (>1.0 = discourage repetition). Typical range: 1.0-1.5
  • stop (str or list[str]): Strings that terminate generation when encountered
For command-line tools (llama-cli), use flags like --temp, --top-p, --top-k, --min-p, --repeat-penalty, and --n-predict.

Vision Models

LFM2-VL GGUF models can be used for multimodal inference with llama.cpp.

Quick Start with llama-cli

Download llama.cpp binaries and run vision inference directly:
Download a test image:
Run inference (works on CPU):
The -hf flag downloads the model directly from Hugging Face. Use --image-max-tokens to control image token budget.

Alternative: Manual Model Download

If you prefer to download models manually:
Run inference directly from the command line:
Start a vision model server with both the model and mmproj files:
Use with the OpenAI Python client:
For a complete working example with step-by-step instructions, see the llama.cpp Vision Model Colab notebook.

Converting Custom Models

If you have a finetuned model or need to create a GGUF from a Hugging Face model:
Use --outtype to specify the quantization level (e.g., q4_0, q4_k_m, q5_k_m, q6_k, q8_0, f16).

Example Applications

For more comprehensive example applications using llama.cpp with LFM models, check out these repositories: The full list of llama.cpp language bindings can be found here.