§ LLMS.FREERUN LOCALLYVERIFIED 2026

llama.cpp Setup: Install, llama-server and GGUF Models

llama.cpp is the MIT-licensed C/C++ inference engine that powers Ollama, LM Studio and Jan under the hood. Running llama-server directly gives you day-one model support, zero background daemons, direct Hugging Face -hf pulls and exact control over GPU layers and KV-cache quantization on port 8080.

# install via Homebrew (Metal GPU enabled by default)
brew install llama.cpp
llama-server -hf ggml-org/gemma-3-1b-it-GGUF --port 8080
§ 01 · CLI FLAGSGPU OFFLOAD & KV QUANTIZATIONLLAMA-SERVER

Essential Server Flags for Speed and Long Context

The biggest advantage of running llama-server directly over wrappers is explicit flag control — especially KV-cache quantization and Flash Attention, which let you fit 32K–64K context windows onto 8–16 GB GPUs.

Key llama-server CLI flags for GPU offload, Hugging Face downloads and KV cache quantization
FlagExamplePurpose
-hf-hf ggml-org/gemma-3-1b-it-GGUFDownloads and caches a GGUF checkpoint straight from Hugging Face.
-m-m /models/qwen2.5-7b-q4_k_m.ggufLoads any local GGUF file completely offline with zero network calls.
-ngl-ngl 99Offloads all transformer layers to CUDA, Metal, Vulkan or ROCm GPU.
-c-c 16384Sets exact active context window size (controls KV cache VRAM).
-fa -ctk q8_0 -ctv q8_0-fa -ctk q8_0 -ctv q8_0Enables Flash Attention and 8-bit KV cache to cut long-context VRAM nearly in half.
--port / --api-key--port 8080 --api-key secretConfigures bind port and optional bearer authentication for LAN access.
§ 02 · OPENAI APILOCALHOST:8080/V1 + WEB UIZERO DEPENDENCIES

Calling the Local Server With the OpenAI SDK

llama-server exposes /v1/chat/completions, /v1/completions and /v1/embeddings on http://localhost:8080/v1, plus a built-in browser chat UI at http://localhost:8080.

import os
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="ollama",
)
r = client.chat.completions.create(
    model="gemma-3-1b-it",
    messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)
§ 03 · CACHE & TROUBLESHOOTINGLLAMA_CACHE & GPU BACKENDSCUDA / METAL / VULKAN

GGUF Cache Folders and Fixing CPU-Only Fallback

Set LLAMA_CACHE to change where -hf downloads GGUF files, or pass any explicit path with -m /path/to/model.gguf.

Default llama.cpp Hugging Face GGUF cache folders by operating system
Operating SystemDefault Cache Directory
macOS~/Library/Caches/llama.cpp
Linux~/.cache/llama.cpp
Windows%LOCALAPPDATA%\llama.cpp

Why Is llama.cpp Running Only on CPU?

Two things must both be true for GPU acceleration: pass -ngl 99 to offload layers, and make sure you downloaded the matching GPU release build (CUDA for NVIDIA, Vulkan for cross-vendor GPUs, ROCm for AMD, or Homebrew/Metal on Apple Silicon).

§ FAQCOMMON QUESTIONSANSWERS

llama.cpp Questions

Is llama.cpp Faster Than Ollama?

Ollama uses llama.cpp internally for GGUF inference, so raw speed is similar on identical settings. Running llama.cpp directly often wins on brand-new kernels, speculative decoding and quantized KV caches.

Can llama-server Download Models Directly From Hugging Face?

Yes. Pass -hf <org>/<repo-GGUF> and llama-server automatically fetches and caches the GGUF weights under LLAMA_CACHE.

Does llama.cpp Work Without a Dedicated GPU?

Yes. llama.cpp is heavily optimized for modern x86 AVX2/AVX-512 and ARM NEON CPUs, making 3B–8B Q4_K_M models runnable on CPU-only laptops.

How Do I Benchmark Throughput in llama.cpp?

Use the bundled llama-bench binary with your GGUF file to measure repeatable prompt-processing (pp512) and token-generation (tg128) tokens per second.