Skip to main content
Use llama.cpp for CPU-only environments, local development, or edge deployment and on-device inference.
Building an application with llama.cpp? Jump to Build with llama.cpp for mobile, desktop, chat, tool-calling, structured-output, and multimodal guides.
For GPU-accelerated inference at scale, consider using vLLM instead.

Installation

Install Llama, the desktop app from the llama.cpp team, for macOS and Windows. It runs llama.cpp with one-click model downloads, a built-in chat, and a local OpenAI-compatible API, with no command-line setup.
This guide uses llama.cpp v0.8.0 (b11960) or later, which LFM3 models require.

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 serve (web chat UI and OpenAI-compatible server) and llama cli (interactive CLI).
llama serve starts a web chat UI and 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: 9931)
  • -ngl 99: Offload layers to GPU (if available)
Using the Server:Open http://localhost:9931 in your browser to chat, or 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
  • repeat_penalty / --repeat-penalty (float): Penalty for repeating tokens (>1.0 = discourage repetition). Typical range: 1.0-1.5. The server ignores the repetition_penalty name used by vLLM and Transformers.
  • stop (str or list[str]): Strings that terminate generation when encountered
For llama cli, use flags like --temp, --top-p, --top-k, --min-p, --repeat-penalty, and --n-predict.

Vision Models

LFM vision models (LFM3-VL and LFM2.5-VL) take images, and LFM3-VL also takes video. With -hf, llama.cpp downloads the matching vision projector (mmproj) automatically. The examples below use LFM3-VL-2B; the :Q4_0 tag selects its Quantization-Aware Distillation (QAD) checkpoint.

Command Line

For video, use --video clip.mp4 instead of --image. Video input needs ffmpeg in PATH. Use --image-max-tokens to cap the number of tokens per image (lower is faster, coarser).

Server

Send images as OpenAI image_url content parts, either a data: URI with base64 bytes or a public URL:
The LFM3 GGUFs store their recommended sampling parameters, so the request needs none. For LFM2.5-VL, see the sampling parameters on its model page.
Download the model and the projector, then pass both:

Audio and Omni Models

LFM3-Audio-2B and LFM3-Omni-2B take audio input, and LFM3-Omni-2B also takes images and video. With -hf, llama.cpp downloads the audio and vision projector automatically.

Speech Recognition

Pass Perform ASR in <language>. as a system prompt with -sys, and mark where the audio goes with -p "<__media__>". As a regular prompt, the model describes the audio instead of transcribing it.
To ask a question about a recording instead, drop the system prompt and put your question in -p.

Server

For LFM3-Omni-2B, add --reasoning off. Send audio as OpenAI input_audio content parts (WAV, MP3, or FLAC):
To try it with your microphone, record a clip first, for example with arecord -f S16_LE -r 16000 -c 1 -d 5 speech.wav on Linux. For live audio, the server also handles real-time voice conversations, including tool calls, on its /v1/realtime WebSocket API.

Speech Synthesis

The llama command has no TTS subcommand, so speech synthesis uses the separate llama-tts program, which ships with llama.cpp:
llama serve also exposes a POST /tts endpoint. See the LFM3-Audio-2B and LFM3-Omni-2B pages for more examples, including image and video input with LFM3-Omni-2B.

Speculative Decoding

Some LFM2.5 models have DSpark draft models that make generation faster without changing the output. In llama.cpp, the drafter is a GGUF sidecar that you load next to the target with -hfd (or -md for a local file):
The sidecar cannot run on its own. Speedups are largest with a 16-bit target. Each response’s timings report draft_n and draft_n_accepted. See Speculative Decoding for which models have drafters.

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

Building Applications

The guides below cover embedding llama.cpp in your own software — from a mobile app calling the C API to a desktop app driving the llama.cpp server:

iOS & Android

Link the XCFramework or NDK build and run LFM GGUFs in-process.

Desktop & Server Apps

llama-server as a sidecar, or Python / Node.js / .NET bindings.

Chat & Streaming

Multi-turn conversations, sampling parameters, prompt caching.

Function Calling & Agents

OpenAI-style tools with native LFM2.5 tool-call parsing.

Structured Output

JSON schema and GBNF grammar constrained generation.

Vision & Audio

LFM2.5-VL and LFM2.5-Audio in your own apps.

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.