[ ABORT TO HUD ]
SEQ. 1
llama.cpp Deep Dive
⚡ llama.cpp Engine⏱ 15 min⭐ 125 BASE XP⌨ HANDS-ON LAB
The Universal Inference Engine
llama.cpp is the industry-standard engine for running LLMs on any hardware - from Raspberry Pis to multi-GPU servers.
Architecture
- GGML: Custom tensor library optimized for quantized inference
- GGUF: Universal model format supporting all major architectures
- Backends: CUDA, Metal, ROCm, Vulkan, OpenVINO (Intel NPUs)
Inference Optimization Techniques
| Technique | What It Does | Speedup |
|---|---|---|
| GPU Layer Offloading | Offload N layers to GPU, rest on CPU | 2-10x vs CPU-only |
| Speculative Decoding | Draft model proposes tokens, main model verifies | 1.5-3x throughput |
| Speculative Checkpointing | Extends speculative decoding to MoE models | Variable (MoE-specific) |
| Flash Attention | Memory-efficient attention computation | 2x+ for long contexts |
| Batch Processing | Process multiple requests simultaneously | Linear with batch size |
| Mmap Loading | Memory-map model files (instant cold start) | Near-zero startup |
llama-server (HTTP API)
# Basic server llama-server -m model.gguf --host 0.0.0.0 --port 8080 # Optimized production server llama-server -m model.gguf \ --host 0.0.0.0 --port 8080 \ -ngl 99 \ # Offload all layers to GPU --ctx-size 32768 \ # Context window -np 4 \ # 4 parallel request slots --flash-attn \ # Enable Flash Attention --cont-batching # Continuous batching
MCP Integration
llama-server now supports Model Context Protocol natively - enabling direct tool calling from your local model.
🐳 Production Container:
docker run -d --gpus all \ -v ./models:/models \ -p 8080:8080 \ --name llama-server \ ghcr.io/ggml-org/llama.cpp:server \ -m /models/mistral-large-Q4_K_M.gguf \ --host 0.0.0.0 -ngl 99 --flash-attn \ -np 8 --cont-batching
⌨ HANDS-ON LABBuild llama.cpp from Source
⭐ +200 XPOllama wraps it; now own it. Clone llama.cpp, compile the engine with CMake, and run a GGUF model directly with llama-cli - no wrapper, full control over every flag.
1Clone the llama.cpp repository and enter it.
2Configure and compile with CMake in Release mode.
3Run inference on a GGUF model straight from the binary you just built.
OBJECTIVE 1 / 3 — type "hint" if stuck
KNOWLEDGE CHECK
QUERY 1 // 2
What does the -ngl 99 flag do in llama-server?
Limits to 99 tokens
Sets 99 parallel slots
Offloads all layers to GPU
Sets context to 99K