What llama-server needs from the machine
Memory first, then everything else. The model file has to fit somewhere: in GPU memory for full speed, split between GPU and system RAM for a model larger than the card, or entirely in RAM for a CPU-only box. llama.cpp's quantize documentation publishes the sizes for Llama 3.1 8B, and they are the cleanest reference for how bits per weight translate into gigabytes.
| GGUF type | Bits per weight | Llama 3.1 8B file |
|---|---|---|
| Q4_K_M | 4.89 | 4.58 GiB |
| Q5_K_M | 5.70 | 5.33 GiB |
| Q6_K | 6.56 | 6.14 GiB |
| Q8_0 | 8.50 | 7.95 GiB |
| F16 | 16.00 | 14.96 GiB |
Scale by parameter count: the same document lists Llama 3.1 70B at 43.1 GB in Q4_K_M. Then add the KV cache, which grows with context length and with every concurrent slot. A 70B Q4_K_M therefore wants a 48 GB card, not a 40 GB one, and an 8B model at Q8_0 (7.95 GiB, about 8.5 GB) is comfortable on a 12 GB card and does not fit entirely on an 8 GB one: there, drop to Q6_K or lower -ngl.
GPU layers, partial offload and the CPU path
-ngl (--n-gpu-layers) is the maximum number of layers stored in VRAM. Current builds accept a number, auto (the default) or all; 999 works everywhere and means every layer. Set it below the model's layer count and the remaining layers run from system RAM on the CPU. That is how llama.cpp runs a model larger than the card, at a speed set by memory bandwidth on the CPU side.
--fit is on by default and adjusts unset arguments, context size included, to fit device memory. If a log shows the model loading entirely on the CPU, check that the binary was built with CUDA (--list-devices prints the GPUs it sees) before touching flags. For Mixture-of-Experts models, --n-cpu-moe N keeps the expert weights of the first N layers in RAM while attention stays on the GPU.
A CPU-only llama.cpp server is a real option for quantised 7-14B models with one or two users. Our LLM hosting page sizes that machine class: many cores and fast DDR5 rather than a card.
More than one GPU in the chassis
With several GPUs visible, llama-server splits by layer across all of them (-sm layer, the default): each card holds a contiguous block of layers and the KV cache for those layers. -ts 3,1 sends 75% to GPU 0 and 25% to GPU 1, which is how two cards of different sizes share one model. -sm tensor splits every layer across cards for lower latency, but the project marks it experimental, it requires flash attention and an unquantised KV cache, and it does not support every architecture.
Layer split tolerates a slow link between cards, which matters on PCIe 3.0 platforms. A second card in one machine is quoted by hand rather than configured; the multi-GPU page compares the platforms by PCIe lanes.
Build with CUDA and start the server
- Install the NVIDIA driver and the CUDA toolkit for your card. On a dedicated server the version is yours to pin; nothing upgrades it underneath you.
- Clone the repository and build with
-DGGML_CUDA=ON. The default build targets the GPU present at compile time; add-DGGML_NATIVE=OFFfor a binary that runs on any CUDA card. AMD Instinct cards build with-DGGML_HIP=ONagainst ROCm instead. - Put a GGUF file on local disk, or let
-hf user/repo:Q4_K_Mdownload one from Hugging Face. - Start
llama-serverbound to localhost, with keys read from a file, and check/healthbefore sending traffic.
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release -j 8
./build/bin/llama-server -m /srv/models/model-Q4_K_M.gguf \
-ngl 999 -c 32768 -np 4 \
--host 127.0.0.1 --port 8080 \
--api-key-file /etc/llama/keys
curl http://127.0.0.1:8080/health
curl http://127.0.0.1:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LLAMA_KEY" \
-d '{"messages":[{"role":"user","content":"Say hello"}]}'
Pass --port explicitly. The current server README lists 9931 as the default while its Docker examples use 8080, so a client written for one build can miss the other.
Context size and parallel slots
-c sets the context the KV cache is sized for; 0 takes the model's own maximum, which on a long-context model can be far more memory than the card has. -np sets the number of slots, the requests decoded at the same time with continuous batching. Slots draw on the same cache, so raise -c when you raise -np, or cap each slot with --kv-unified-per-slot.
-ctk q8_0 -ctv q8_0stores the cache at 8 bits, roughly half of the f16 default. A quantised V cache needs flash attention, which-fa autoenables where supported.GET /slots(on by default) shows what each slot is doing;--metricsadds a Prometheus endpoint.- Router mode: start
llama-serverwith--models-dirand no model, and it loads models on demand by the request'smodelfield, up to four at once by default (--models-max).
Exposing it safely
llama-server listens on 127.0.0.1 unless --host says otherwise, and with no --api-key it accepts any request. For anything reachable from outside, the project's own recommendation is an API key plus a reverse proxy. /health stays public by design. TLS works either at the proxy or natively, by building with -DLLAMA_OPENSSL=ON and passing --ssl-key-file and --ssl-cert-file.
Leave --tools, --agent and the MCP options off on an exposed server: they let the model read and write files and run shell commands, and the documentation says not to enable them in untrusted environments. Run the process as an unprivileged user under systemd, keep model files read-only, and firewall the port to the hosts that call it.
Which of our machines fit
Our GPU dedicated servers are physical machines rented to one account, with the card passed straight through to your operating system: no hypervisor, no vGPU profile, no MIG partition. You install the driver and the CUDA or ROCm release your build was tested against, and you get every core, all the RAM, root and the server's iLO or iDRAC console on a separate management network, so a driver change that drops the network is recoverable. The port is unmetered, so pulling a 43 GB GGUF or serving tokens all month adds nothing to the bill.
- 7-8B at Q4_K_M to Q6_K: the 8 GB cards, older Tesla and Quadro parts included; Q8_0 wants 12-16 GB.
- 13-14B at 4-bit: the 12-16 GB cards. 30-34B at 4-bit (about 19 GB of weights): 24 GB, for example an RTX 3090 or RTX A5000, leaving room for context.
- 70B at Q4_K_M: a 48 GB card such as the L40S, A40 or RTX A6000. Past 96 GB on one card it is a multi-GPU build.
- AMD Instinct MI50 and MI210 run the HIP backend for teams already on ROCm.
The GPU is a separate monthly line beside the machine, so moving from an 8 GB card to a 24 GB one later changes the bill by the difference between the two cards. Servers run in New York, Miami, San Francisco, Amsterdam and Bucharest on our own network, AS19624.
When another engine is the better fit
llama.cpp is at its best with GGUF quantisations, mixed CPU and GPU memory, older or mismatched cards, and one machine serving a handful of users. If you want models pulled and managed by name with fewer flags, read Ollama server hosting. If the job is many concurrent users on a GPU big enough for the model with headroom left, compare it with a vLLM server.
Questions
Does llama-server use the GPU automatically?
Only if the binary was built with a GPU backend such as CUDA or HIP. With one, -ngl defaults to auto and --fit places as many layers as fit. Run llama-server --list-devices to confirm the card is seen; if it is missing, the build or the driver is the problem, not the flags.
How much GPU memory for a 70B model in llama.cpp?
The Q4_K_M file of Llama 3.1 70B is 43.1 GB according to the project's quantize documentation, before any KV cache. A 48 GB card is enough when the context is short and concurrency low. On a smaller card, lower -ngl and the remaining layers run from system RAM, which works but is much slower per token.
Is the llama.cpp server compatible with OpenAI clients?
Yes. It serves /v1/chat/completions, /v1/completions, /v1/responses and /v1/models, plus an Anthropic-style /v1/messages; /v1/embeddings needs its own instance, launched on an embedding model with --embeddings. Point the client's base URL at http://host:port/v1 and send the key you set with --api-key as a Bearer token.
Can one llama-server serve several models?
Yes, in router mode. Start it without -m and with --models-dir pointing at your GGUF files; it loads the model named in each request and keeps up to --models-max loaded at once, four by default. Each loaded model takes its own memory, so size the card for the set you keep warm.
Do I need a GPU at all?
Not for small quantised models with light traffic. llama.cpp has AVX2, AVX-512 and AMX paths on x86, and a 7-8B model at Q4_K_M fits easily in server RAM. Throughput scales with memory bandwidth, so a GPU becomes worth it as soon as response time or concurrency matters.