Deploy a Local LLM, Part 1: Pick the Right Model and Engine for Your VRAM
Deploy a Local LLM, Part 1: Pick the Right Model and Engine for Your VRAM
Search
Ask the AI

Deploy a Local LLM, Part 1: Pick the Right Model and Engine for Your VRAM

This is part one of the Local AI Model Deployment series. By the end you will have an inference server running on your own machine: the right model and engine for your VRAM, installed, running as a system service with automatic restart, and verified with a single curl.

The examples use Gemma 4 on Linux with systemd. You need working NVIDIA drivers, a Vulkan or CUDA runtime compatible with the engine, and enough available VRAM. Output from nvidia-smi confirms that the driver can query the GPU; the engine device list below checks backend detection. For other models, check format, architecture and backend support separately.

Local LLM deployment series (4 parts): ① Model and engine → ② Exposing it → ③ Clients → ④ Knowledge base RAG. This is part 1.

Step 1: Find out how much VRAM you actually have

nvidia-smi --query-gpu=name,memory.total,compute_cap --format=csv
name, memory.total [MiB], compute_cap
NVIDIA GeForce RTX 4070 Laptop GPU, 8188 MiB, 8.9

All three numbers matter:

  • VRAM caps model size. Note that 8188 MiB is an 8 GB card — do not floor 8188/1024 = 7.99 to 7 GB, because one tier down means a different model.
  • Compute capability affects FP8 kernel selection. The native FP8 W8A8 path in vLLM v0.19.0 needs ≥ 8.9. An A100 has capability 8.0 and lacks that native path, but a compatible configuration can use Marlin FP8 W8A16 weights. Check the checkpoint and backend together; see the versioned FP8 documentation.
  • Subtract what is already in use. A machine driving a display typically has a few hundred MB gone before you start:
nvidia-smi --query-gpu=memory.used,memory.free --format=csv

Correction, 2026-11-07: this step previously said FP8 needs compute capability 8.9 or higher and that an A100 (8.0) cannot use it. The vLLM v0.19.0 FP8 documentation sets that floor for W8A8 computation; on Turing (7.5) and Ampere GPUs, FP8 checkpoints run as weight-only W8A16 through Marlin kernels.

Step 2: Look up real file sizes — do not estimate

A quantized checkpoint can retain unquantized tensors and metadata. After an initial estimate from parameter count and bit width, check all shards of the selected checkpoint. GPU memory also includes KV Cache, workspace and multimodal components; account for any tensors offloaded to the CPU.

The following HuggingFace API script sums all safetensors and GGUF files in a repository. If the repository contains several quantizations, it adds those alternatives together. For model sizing, count only the selected checkpoint and all of its shards.

check_size() {
  curl -s "https://huggingface.co/api/models/$1?blobs=true" | python3 -c "
import json,sys
d=json.load(sys.stdin)
w=[(s['rfilename'], s.get('size') or 0) for s in d.get('siblings',[])
   if s['rfilename'].endswith(('.safetensors','.gguf'))]
main=sum(s for n,s in w if 'mmproj' not in n)
mm=sum(s for n,s in w if 'mmproj' in n)
print(f'  main {main/1e9:.2f} GB' + (f'  + mmproj {mm/1e9:.2f} GB' if mm else ''))
"
}

check_size google/gemma-4-E4B-it-qat-w4a16-ct
check_size google/gemma-4-E4B-it-qat-q4_0-gguf

The original file listing produced these repository totals in decimal GB:

gemma-4-E4B-it-qat-w4a16-ct     main 11.51 GB
gemma-4-E4B-it-qat-q4_0-gguf    main  5.15 GB  + mmproj 0.99 GB

In the original record, these two “4-bit quantized” checkpoints differ by more than 2×. The w4a16-ct embeddings remain in bf16, while GGUF q4_0 quantizes them. Check tensor types in the specific checkpoint: the GGUF container does not itself guarantee that every tensor is quantized. The pitfalls article retains the original breakdown.

Step 3: Pick a model and engine by VRAM

The table below retains the original selection guide based on file sizes. Its VRAM tiers describe historical reference configurations; fit depends on context, concurrency, cache type, multimodal components and engine version. The FP8 row refers to the W8A8 path above. Use the VRAM calculator for its supported models and assumptions, then check actual startup allocation.

Available VRAM Model Engine
≥ 72 GB 31B bf16 vLLM
≥ 40 GB and compute ≥ 8.9 31B FP8 vLLM
≥ 28 GB 31B W4A16 vLLM
≥ 22 GB 31B q4_0 GGUF llama.cpp
≥ 18 GB 26B-A4B q4_0 GGUF llama.cpp
≥ 13 GB 12B W4A16 vLLM
≥ 9 GB 12B q4_0 GGUF llama.cpp
≥ 7 GB E4B q4_0 GGUF llama.cpp
≥ 5 GB E2B q4_0 GGUF llama.cpp

Why the engine changes

Choose the engine according to what fits in VRAM:

  • Plenty of VRAM: use vLLM. Continuous batching and PagedAttention suit concurrent serving. Measure throughput for your model, request lengths and batch size.
  • Tight VRAM: use llama.cpp with GGUF. Of the two historical checkpoints compared here, the GGUF version is smaller. Other quantization formats or CPU offloading can also change memory requirements; check the specific files and latency.

Both expose an OpenAI-compatible API, so the basic reverse-proxy and client setup can be reused. Verify chat templates, image inputs, tool calls and extension fields for the chosen model and engine version.

Step 4: Install the engine

Path A: llama.cpp (tight VRAM)

This correction checks the fixed b10216 release, which provides an Ubuntu Vulkan package and no Ubuntu CUDA package. The NVIDIA driver must expose a Vulkan ICD, and the system must satisfy the build’s shared-library requirements. The original script below resolves latest and is retained as historical code. Use the versioned download that follows to reproduce the corrected parameter semantics.

Correction, 2026-11-07: this step previously said the official releases ship no CUDA build for Linux, and its install script downloaded the Vulkan asset of releases/latest. As of 2026-11-08 the latest release is v0.9.0, which carries only nightly-tag.txt, so that download returns 404; b10216 has no Ubuntu CUDA package, while b12184 ships Ubuntu CUDA 12.8 and 13.5 packages for x64.

# Confirm the driver exposes Vulkan
ls /usr/share/vulkan/icd.d/nvidia_icd.json

# Resolve the latest tag and download the Vulkan build
TAG=$(curl -fsSL https://api.github.com/repos/ggml-org/llama.cpp/releases/latest \
      | python3 -c 'import json,sys; print(json.load(sys.stdin)["tag_name"])')

curl -fL -o /tmp/llama.tar.gz \
  "https://github.com/ggml-org/llama.cpp/releases/download/${TAG}/llama-${TAG}-bin-ubuntu-vulkan-x64.tar.gz"

# Verify the archive before extracting — truncated downloads are common
tar tzf /tmp/llama.tar.gz >/dev/null || { echo "archive is corrupt"; exit 1; }

sudo mkdir -p /opt/llama.cpp
sudo tar xzf /tmp/llama.tar.gz -C /opt/llama.cpp --strip-components=1

Corrected b10216 download: the SHA-256 below comes from the release asset metadata. Once it matches, use this archive in the extraction step above. This correction checked source, release metadata and syntax; it did not reinstall the service.

# Corrected download: fixed b10216 asset and official release SHA-256
set -eu
TAG=b10216
curl -fL -o /tmp/llama-b10216-vulkan.tar.gz \
  "https://github.com/ggml-org/llama.cpp/releases/download/${TAG}/llama-${TAG}-bin-ubuntu-vulkan-x64.tar.gz"
printf '%s  %s\n' \
  '43793a565c0cfe1fdec430050950d6eed3e87aa7d14ebba8517125d78da15d79' \
  '/tmp/llama-b10216-vulkan.tar.gz' | sha256sum -c -
tar tzf /tmp/llama-b10216-vulkan.tar.gz >/dev/null
# Use this verified archive in place of /tmp/llama.tar.gz in the extraction step.
# After extraction, record the installed version:
LD_LIBRARY_PATH=/opt/llama.cpp /opt/llama.cpp/llama-server --version

b12184 maintenance example: download and a text-only service

The following maintenance example pins b12184 and retains that version’s download and systemd code. The b10216 route above traces the earlier parameters and records. Each example has its own fixed version; the historical memory and throughput figures are not b12184 benchmark results.

The Ubuntu Vulkan asset SHA-256 below was checked against official b12184 release metadata. Verify the digest and archive as shown. Before replacing an installation, record its current version and retain a copy for rollback.

ls /usr/share/vulkan/icd.d/nvidia_icd.json

# Pin the build and verify the downloaded archive
TAG=b12184
curl -fL -o /tmp/llama.tar.gz \
  "https://github.com/ggml-org/llama.cpp/releases/download/${TAG}/llama-${TAG}-bin-ubuntu-vulkan-x64.tar.gz"
echo '14892046c17f0883e3604fca862b01ae69133870babda74a6cbddf364010da8c  /tmp/llama.tar.gz' | sha256sum -c - || exit 1
tar tzf /tmp/llama.tar.gz >/dev/null || exit 1

sudo mkdir -p /opt/llama.cpp
sudo tar xzf /tmp/llama.tar.gz -C /opt/llama.cpp --strip-components=1

Confirm it sees the GPU:

LD_LIBRARY_PATH=/opt/llama.cpp /opt/llama.cpp/llama-server --list-devices
Available devices:
  Vulkan0: NVIDIA GeForce RTX 4070 Laptop GPU (8188 MiB, 7756 MiB free)

Path B: vLLM (plenty of VRAM)

curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv /opt/llm/venv --python 3.12
uv pip install --python /opt/llm/venv/bin/python 'vllm>=0.19.0' huggingface_hub

In the original environment, vLLM and its CUDA runtime dependencies occupied over 10 GB. Size varies by platform and version. The vllm>=0.19.0 range above is open-ended; record the resolved version for reproducibility.

Step 5: Download weights

These are the original measurements for one network and time window; mirror throughput varies with location, routing and load:

ModelScope     16.7 MB/s
hf-mirror       2.4 MB/s
HuggingFace     2.1 MB/s

ModelScope was fastest in that test. The specific repository below uses master, not main; check its actual branch and filename before downloading:

mkdir -p /opt/llm/models

curl -L --retry 20 --retry-delay 5 --retry-all-errors -C - \
  -o /opt/llm/models/gemma-4-E4B_q4_0-it.gguf \
  "https://modelscope.cn/models/gpustack/gemma-4-E4B-it-qat-q4_0-gguf/resolve/master/gemma-4-E4B_q4_0-it.gguf"

-C - requests resume. When the server supports Range requests, rerunning after an interruption continues from the downloaded offset.

Verify the size and, when provided by the repository, the file digest. A completed transfer alone does not verify file integrity:

ls -l /opt/llm/models/*.gguf | awk '{printf "%.0f MB  %s\n", $5/1048576, $9}'

This Gemma 4 GGUF multimodal route needs a matching projector file, usually named with mmproj. For text-only inference, omit the projector file and its service argument. For vision, check the matching pair and backend support.

Step 6: Wrap it in a systemd unit

A process started with nohup does not survive reboot or restart after a crash, and its logs are scattered. The original systemd unit is retained below. Save it as /etc/systemd/system/llm-server.service and replace the user, key and model paths; vision inference needs the matching projector file first. Correction: add --no-kv-unified after --parallel 4 in ExecStart to select independent KV slots explicitly in b10216. For text-only startup, remove the --mmproj line.

[Unit]
Description=Local LLM inference server
After=network-online.target
Wants=network-online.target

[Service]
Type=exec
User=youruser
Environment=LD_LIBRARY_PATH=/opt/llama.cpp
ExecStart=/opt/llama.cpp/llama-server \
  --model /opt/llm/models/gemma-4-E4B_q4_0-it.gguf \
  --mmproj /opt/llm/models/gemma-4-E4B-it-mmproj.gguf \
  --alias gemma4 \
  --host 127.0.0.1 --port 8000 \
  --ctx-size 131072 \
  --parallel 4 \
  --n-gpu-layers 99 \
  --flash-attn on \
  --cache-type-k q8_0 --cache-type-v q8_0 \
  --jinja \
  --metrics \
  --no-webui \
  --api-key sk-replace-me
Restart=on-failure
RestartSec=10
# Loading a large model can take minutes; do not let systemd declare it dead
TimeoutStartSec=1800
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/opt/llm

[Install]
WantedBy=multi-user.target

b12184 maintenance example: a text-only systemd service

This unit is text-only by default and omits mmproj. Replace the user, key and model paths, then save it as /etc/systemd/system/llm-server.service. Image input requires a matching projector file and the corresponding argument.

[Unit]
Description=Local LLM inference server
After=network-online.target
Wants=network-online.target

[Service]
Type=exec
User=youruser
Environment=LD_LIBRARY_PATH=/opt/llama.cpp
ExecStart=/opt/llama.cpp/llama-server \
  --model /opt/llm/models/gemma-4-E4B_q4_0-it.gguf \
  --alias gemma4 \
  --host 127.0.0.1 --port 8000 \
  --ctx-size 131072 \
  --parallel 4 \
  --no-kv-unified \
  --n-gpu-layers 99 \
  --flash-attn on \
  --cache-type-k q8_0 --cache-type-v q8_0 \
  --jinja \
  --metrics \
  --no-webui \
  --api-key sk-replace-me
Restart=on-failure
RestartSec=10
# Loading a large model can take minutes; do not let systemd declare it dead
TimeoutStartSec=1800
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/opt/llm

[Install]
WantedBy=multi-user.target

This version explicitly selects 4 independent KV slots: 131072 total context gives 32768 per slot. The argument source supports –no-kv-unified and –flash-attn on, and the allocation source retains the distinction between independent and shared KV. Enabling FlashAttention is this example’s configuration choice; check actual backend support in startup logs and measure performance under matching conditions. This correction checked official assets, source and syntax. It did not install b12184 or rerun GPU inference.

The flags that matter

The following explanations apply to b10216. This version already supports unified KV and automatic slots, so specify the mode and parallelism explicitly:

  • Interpret --ctx-size together with the KV mode. In the corrected independent-slot setup with --no-kv-unified, --parallel divides the total context: 131072 / 4 = 32768, or 32K per slot. A total of 16384 with 4 slots gives 4096 per slot; 16384 per slot requires a total of 65536. With unified KV, slots access a shared pool, so multiplying slot count by each slot’s limit overcounts the pool. See the allocation code in this version.
  • --parallel sets the number of concurrent slots. Short concurrent requests and long prompts call for different budgets; measure your workload. The b10216 server default is automatic slots, so a fixed default of 4 cannot be assumed.
  • Test --flash-attn on with the model and backend. The original E-series Vulkan record reported prompt processing about 40× slower with it disabled. That is a performance observation for that configuration, not a fixed ratio or correctness requirement for every sliding-window model. In b10216 and b12184 the default is auto (b10216, b12184): llama.cpp turns flash attention on unless the backend cannot run it on a layer’s device, and a quantized V cache such as the q8_0 in these units forces it on.
  • --cache-type-k/v q8_0 stores 8-bit data plus block-quantization metadata. The data portion is about half the FP16 size. Weights, workspace and backend limits also constrain context capacity; validate quality and performance for the task.
  • --api-key provides service authentication. Set a dedicated key for the reverse proxy and clients.

Correction, 2026-11-07: this list previously said that --ctx-size 16384 with the default of 4 slots allocates KV cache for 65536 tokens, and that --flash-attn on is mandatory for sliding-window models on Vulkan. In b10216 and b12184, --ctx-size is the total for all slots, and the server’s automatic mode shares it as one unified pool; the 40× gap comes from one E-series Vulkan measurement.

sudo systemctl daemon-reload
sudo systemctl enable --now llm-server

Step 7: Verify

7.1 Is it running

systemctl is-active llm-server
curl -s 127.0.0.1:8000/health

7.2 Read the values the engine actually computed

After startup, record the effective version, KV mode, context and slot count. The original excerpt below omits version and KV mode, so interpret it alongside the complete log:

sudo journalctl -u llm-server --no-pager | grep -iE "n_slots|n_ctx|loaded"
srv load_model: initializing, n_slots = 4, n_ctx_slot = 32768
srv load_model: loaded multimodal model, '.../gemma-4-E4B-it-mmproj.gguf'

n_slots × n_ctx_slot gives total token capacity in independent-slot mode, not the cache size in bytes. It overcounts a unified pool. The multimodal line confirms projector loading. A separate historical record showed 4 slots of 16384; that implies 65536 total only after confirming independent-slot mode. The saved --ctx-size 16384 command fragment lacks a matching version and complete startup log, so it cannot be paired with that slot record or establish that these arguments caused CPU offloading or a slowdown.

7.3 Does VRAM usage match expectations

nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader

The original record reports 5.2 GB for E4B q4_0, mmproj and a 128K q8_0 configuration. The saved excerpt lacks that run’s complete allocation log, so this remains a historical observation. For the current configuration, read GPU usage again. Check --ctx-size, --parallel and KV mode, then inspect GPU-resident weights, KV allocation, projector components and workspace separately.

7.4 Send a real request

KEY=sk-replace-me
curl -s 127.0.0.1:8000/v1/chat/completions \
  -H "Authorization: Bearer $KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"gemma4","max_tokens":2048,
       "messages":[{"role":"user","content":"Explain KV cache in one sentence"}]}' \
  | python3 -m json.tool

If content comes back as an empty string, inspect reasoning_content, the finish reason and token counts. With thinking enabled, the output budget can be exhausted before the final answer. In that case, raise max_tokens above 2048 and retry; the required budget depends on the task.

7.5 Measure real throughput

Record cold-start and warmed-up throughput separately. Lazy Vulkan shader compilation can slow the first large prompt; the original record reported about an order of magnitude. The script below warms up twice with a few-hundred-token input, then measures the warm state:

python3 -c "
import json
p = 'Summarize the following. ' + 'Machine learning has evolved through several eras. ' * 20
print(json.dumps({'model':'gemma4','max_tokens':200,
                  'messages':[{'role':'user','content':p}]}))" > /tmp/warm.json

for i in 1 2; do
  curl -s -o /dev/null 127.0.0.1:8000/v1/chat/completions \
    -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' --data @/tmp/warm.json
done

curl -s 127.0.0.1:8000/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' --data @/tmp/warm.json \
| python3 -c "
import json,sys
t = json.load(sys.stdin).get('timings', {})
print(f\"prompt {t.get('prompt_per_second',0):.0f} t/s   generation {t.get('predicted_per_second',0):.1f} t/s\")"

This script repeats the same prompt and can hit the prompt cache. Record cold/warm state and the number of tokens actually processed. To compare uncached prefill, also test different content of similar length and record cache hits.

The original E4B record on an 8 GB laptop GPU reports 900–1700 t/s prompt, 63–66 t/s generation. Align the model, engine version, input length, cache hits and cold/warm state before comparing. For slow prompt processing, check --flash-attn, the actual backend, CPU offloading and input length.

Troubleshooting

The service will not start

sudo journalctl -u llm-server -n 50 --no-pager

Three common causes:

  • unrecognized arguments — a flag does not match the engine version. Check this binary’s help and version first; preserve required KV-mode and authentication settings when adapting the configuration.
  • failed to load model — inspect the full error, then check paths, permissions, format support and file integrity.
  • An immediate out-of-memory exit — reduce --ctx-size or pick a smaller model.

Can I run two models at once

Yes: use two systemd units on different ports. Both sets of weights, KV caches and workspaces share VRAM. With CPU offloading, also check host memory and latency. If the second model only does embeddings, test the CPU route used in part four of this series.

Why bind to 127.0.0.1 only

Deliberately. Right now the only protection is an API key; binding to 0.0.0.0 would put it bare on the network. Part two covers putting a reverse proxy in front and exposing it safely, including rate limiting, path routing, and TLS.

Next

You now have a stable, auto-starting local inference service reachable from the machine itself. Part two covers two ways to expose it to the internet — a zero-open-port tunnel and direct port forwarding — and which one suits which situation.

If something behaves strangely along the way, this companion article catalogues 11 real failures by symptom.

Leave a Reply

Scroll down