llama.cpp Guide: Run, Serve and Quantise Models Yourself
Use llama.cpp directly: prebuilt binaries, llama-cli and llama-server, GPU offload and context flags, KV cache quantisation and making your own GGUFs.
llama.cpp is the engine under much of local AI. Using it directly gives you every option.
Get it
Download a prebuilt release for your platform and backend (CUDA, Vulkan, Metal, CPU), or build from source.
Run a server
llama-server -m ./model.Q4_K_M.gguf -c 16384 -ngl 99 --port 8080
-m: model file.-c: context length.-ngl: GPU layers (99 means as many as possible).--port: server port.
Open the built-in web UI, or connect apps to the OpenAI-compatible API. See local OpenAI-compatible server.
Useful options
- Flash attention for speed and memory.
- KV cache quantisation (for example q8_0) to fit longer contexts.
- CPU expert offload for MoE models.
Make your own GGUF
Convert a Hugging Face safetensors model with the conversion script, then quantise, optionally with an importance matrix. See GGUF vs safetensors.
Compare
Common questions
How do I start llama-server?
Run llama-server with -m pointing to a GGUF, set context with -c and GPU layers with -ngl. It serves a web UI and API on a local port.
What does -ngl do?
It sets how many layers are offloaded to the GPU. Use a high number to offload all layers if memory allows.
Can llama.cpp run on CPU only?
Yes. It was designed for CPUs and runs small and medium models at usable speeds on modern processors.
Related reading
Ollama Modelfile Guide: System Prompts, Templates and Parameters
GuideLM Studio Guide: Download, Run and Serve Local Models
GuideHow to Download Models from Hugging Face (GGUF and Full Weights)
Comparisonllama.cpp vs Ollama: Raw Engine or Friendly Wrapper?
Free toolLLM VRAM Calculator
Browse more: all guides · comparisons · glossary · free tools