Back to projects

FIELD NOTES / LOCAL LLMS

Local LLMs

Running open-weight language models on local hardware, and tuning how they run. Two machines: an Apple M5 Pro laptop with 48 GB of unified memory, and an 8 GB AMD RX 5700 in a home lab server. The tuning is inference tuning: quantization, context length, KV cache type, GPU offload, batch sizes, grammar-constrained decoding, sampling penalties and memory limits, then swapping models after measuring them.

llama.cpp MLX Vulkan Metal GGUF Proxmox

Inference only · no fine-tuning, LoRA or training

APPLE SILICON
M5 Pro, 48 GB37.4 GiB of it usable by the GPU, per Metal
HOME LAB GPU
RX 5700, 8 GBllama.cpp on Vulkan, in a container
FIT IN 8 GB OF VRAM
3 models0.9B OCR, 4B extractor, 2B vision, all three at once
OCR GENERATION
~260 tok/sGLM-OCR 0.9B Q8_0 on the RX 5700
JSON UNDER GRAMMAR
24 to 35 tok/sQwen3-4B Q4_K_M on the RX 5700
RECEIPT BASELINE
89 photos0 failed extractions, mean extraction 20.2 s

Hardware

  • Apple M5 Pro (MacBook Pro, 18 cores: 6 Super and 12 Performance), 48 GB of unified memory. Metal reports 37.4 GiB of it as usable by the GPU. Runs llama.cpp on Metal, MLX models, and Ollama.
  • AMD Radeon RX 5700 (Navi 10, 8 GB GDDR6) in a single-node Proxmox server in the home lab. The card can't be passed through to a VM: it shares an IOMMU group with the SATA controller and the host's network port, and Navi 10's reset bug has no fix on current Proxmox kernels. Its render node is shared into an unprivileged Debian 13 container (4 cores, 6 GB of RAM) instead. The stack is Mesa 25.0 (RADV) and a llama.cpp b10948 Vulkan build. No host driver change, no reboot, and removing one line from the container config undoes it.
  • Apple M3 Pro (the earlier laptop, 11 cores, 18 GB of unified memory). Metal reported 13.3 GiB usable. Its models ran in LM Studio, inventoried in January 2026.

Runtimes and tools

  • llama.cpp (llama-server). Metal on the Mac, Vulkan on the RX 5700. On the GPU server it runs in router mode: one OpenAI-compatible endpoint, a preset file with per-model settings, models loaded on demand and up to three resident.
  • MLX through oMLX. An MLX inference server for Apple Silicon. It is set up to serve Qwen3.6-27B at 8 bits as the local backend for a coding agent, with the context window capped at 32,768 tokens.
  • MTPLX. An MLX runtime for multi-token-prediction (MTP) speculative decoding on Apple Silicon. Used often; no MTPLX numbers are given here.
  • Ollama. A launch agent with flash attention on and a q8_0 KV cache, used for embeddings.
  • LM Studio. The runtime on the M3 Pro, for GGUF and MLX models behind a local OpenAI-compatible server. In 2025 an LM Studio server backed natural-language-to-SQL queries over a DuckDB file.
  • Langfuse for reviewing LLM traces.
  • faster-whisper for speech to text, on CPU with int8 compute.

Models

The RX 5700 and M5 Pro rows come from server configs, logs and the files on disk. The M3 Pro rows come from a January 2026 inventory of what LM Studio had installed and what each model was meant for; for those rows the last column is the intended use. Parameter counts come from the model names, and for GLM-OCR from the GPU server's README.

Table 1 · Models, by machine

MoE: mixture of experts. A3B: about 3B parameters active per token.

MODEL PARAMS QUANTIZATION RUNTIME USED FOR
AMD RX 5700, 8 GB · HOME LAB
GLM-OCR 0.9B Q8_0 GGUF llama.cpp, Vulkan Reads the page: image to text
Qwen3-4B-Instruct-2507 4B Q4_K_M GGUF llama.cpp, Vulkan OCR text to JSON under a schema grammar
Qwen3-VL-2B-Instruct 2B Q8_0 GGUF llama.cpp, Vulkan Questions about images. Replaced as the extractor
APPLE M5 PRO, 48 GB
Qwen3.6-35B-A3B 35B MoE, 3B active UD-Q4_K_M GGUF, 22.1 GB llama.cpp, Metal Tool-calling agent loop at 40,960 tokens of context
Qwen3.6-27B 27B MLX 8-bit (affine, group size 64), one MTP layer, 28.85 GB oMLX Set up as the local backend for a coding agent
Community 9B with MTP layers 9B BF16 GGUF; Q8_0 builds also pulled llama.cpp, Metal Trying a checkpoint with an MTP head in the same agent loop
APPLE M3 PRO, 18 GB · EARLIER · INTENDED USE
gpt-oss 20B 20B MXFP4 GGUF, 11.28 GB LM Studio Reasoning and code
olmOCR 2 7B 7B Q4_K_M GGUF, 5.62 GB LM Studio Text from documents and images
Ministral 3 3B 3B Q4_K_M GGUF, 2.78 GB LM Studio Fast answers to simple tasks
Qwen3 4B Thinking 2507 4B MLX 4-bit, 2.12 GB LM Studio Step-by-step reasoning and tool calls

Also on the M3 Pro: Rnj 1 (Q4_K_M) and Nomic Embed Text v1.5 for embeddings. On the M5 Pro, speech to text uses faster-whisper small on CPU with int8 compute; large-v3 is also cached.

Settings that mattered

M5 Pro: a 35B MoE with a long context

LLAMA-SERVER LAUNCH (HOST AND PORT OMITTED)

llama-server \
  --model Qwen3.6-35B-A3B-UD-Q4_K_M.gguf \
  -ngl 99 -c 40960 --flash-attn on \
  --cache-type-k q8_0 \
  --cache-type-v q8_0 \
  --batch-size 2048 --ubatch-size 1024
  • -ngl 99 puts every layer on the GPU. Unified memory has no separate VRAM pool, so the ceiling is the 37.4 GiB Metal will hand out.
  • -c 40960 sets a 40,960-token context. The server's own /slots report confirmed it.
  • --cache-type-k q8_0 and --cache-type-v q8_0 store the KV cache at 8 bits instead of the 16-bit default, about half the memory at the same context length.
  • --flash-attn on forces flash attention (the default is auto). The physical batch, --ubatch-size, is raised from the default 512 to 1024.

RX 5700: three models in 8 GB

ROUTER PRESET, MODELS.INI (EXCERPT)

[*]
c = 8192
cache-ram = 0
n-gpu-layers = 99
jinja = true

[GLM-OCR-Q8_0]
load-on-startup = true
c = 8192

[Qwen3-VL-2B-Instruct-Q8_0]
c = 8192

[Qwen3-4B-Instruct-2507-Q4_K_M]
c = 16384

ROUTER LAUNCH, SYSTEMD SERVICE (HOST, PORT, API KEY AND ALIAS OMITTED)

llama-server \
  --models-dir /opt/models \
  --models-preset /etc/llama/models.ini \
  --models-max 3
# MemoryMax=5G, in a 6 GB container
  • --models-max 3: all three models fit in the 8 GB of VRAM together. The OCR model loads at startup and the other two load on demand.
  • The extractor gets 16,384 tokens of context; the OCR and vision models get 8,192.
  • MemoryMax=5G: model files are memory-mapped and count against the service's memory limit. With all three loaded, resident memory reads about 1.6 GB; the weights live in VRAM.
  • cache-ram = 0 is load-bearing. The reason is under what broke.

Extraction request: grammar and penalties

PER-REQUEST SETTINGS FOR THE 4B EXTRACTOR

temperature      0
max_tokens       2000
repeat_penalty   1.15
repeat_last_n    128
response_format  json_schema
# every key required but nullable
# strings capped with maxLength
  • The JSON schema is enforced as a grammar, so the model can only emit JSON that fits it.
  • Every key is required but nullable, so the model has to consider each field. That costs decode time (see the measurements).
  • Fields the consumer never reads are left out of the schema: fewer forced tokens.
  • repeat_penalty 1.15 and the maxLength caps went in after the 2B model looped on the payment-method field.

MLX server and Ollama

  • oMLX: context window capped at 32,768 tokens; prefill memory guard on, with a soft limit at 85% and a hard limit at 95% of memory.
  • Ollama: OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0 in the launch agent.

Measured

Table 2 · Throughput and latency

Numbers recorded during the runs. Image tokens are what a vision encoder turns one image into before the model reads it.

WHAT HARDWARE RESULT DATE
GLM-OCR 0.9B Q8_0, image encoding RX 5700 ~500 image tokens/s 2026-09-13
GLM-OCR 0.9B Q8_0, generation RX 5700 ~260 tok/s 2026-09-13
GLM-OCR on an 864 × 1296 receipt photo (1,437 image tokens) RX 5700 3.2 to 3.4 s 2026-09-13
GLM-OCR on a 3024 × 4032 phone photo, downscaled to 1200 × 1600 (2,462 image tokens) RX 5700 8.3 s prefill at ~296 tok/s, decode ~240 tok/s, 10 to 15 s in all 2026-09-14
OCR again on the same image (prompt cache hit) RX 5700 0.5 to 0.9 s 2026-09-13
Vision encoding of one photo: Qwen3-VL-2B vs GLM-OCR RX 5700 11.9 s vs 2.8 s 2026-09-13
Qwen3-4B Q4_K_M, grammar-constrained decoding RX 5700 ~24 to 35 tok/s 2026-09-13
PDF with a text layer, pdftotext, no model CPU ~0.1 s 2026-09-13
Qwen3.6-27B MLX 8-bit, prefill (8,479 tokens in 34.9 s) M5 Pro ~243 tok/s 2026-07-09 to 2026-09-06
Qwen3.6-27B MLX 8-bit, decode (504 tokens in 54.4 s) M5 Pro ~9.3 tok/s 2026-07-09 to 2026-09-06

Sources: the GPU server's README and handoff in the home lab repository; the MLX server's stats file. The M5 Pro rows are totals over three requests, so read them as a rough figure.

Figure 1 · Receipt baseline, 89 real photos

GLM-OCR, then Qwen3-4B Q4_K_M under the schema grammar. Eight of the 89 photos were not receipts, and nearly every miss on store, date and total was one of those or a photo with the date cut off.

  • Store name filled in78 / 89
  • Total filled in78 / 89
  • Date filled in73 / 89
  • Subtotal + tax + tip = total47 / 70
  • Line items sum to the subtotal (or total less tax and tip)34 / 74
FAILED EXTRACTIONS 0 MEAN EXTRACTION 20.2 s MEASURED 2026-09-14

Source: the 2026-09-14 receipts baseline report in the home lab repository. The arithmetic checks count only receipts where the fields they need were filled in.

Store, date and total came back on nearly every real receipt. The arithmetic checks passed far less often, which is why the output needs a check downstream before anything trusts it.

What broke, and what fixed it

  1. The 2B extractor dropped line items and invented quantities. Qwen3-VL-2B was the first extractor. It also looped on the payment-method field. Qwen3-4B-Instruct-2507 at Q4_K_M took over and fixed both problems on the same inputs, at about 24 to 35 tok/s under the grammar. repeat_penalty 1.15 and maxLength caps stop the loop.
  2. The prompt cache ran past the memory limit. The router's host-RAM prompt cache defaults to 8,192 MiB, above the service's 5 GB limit. It grew about 160 MB per receipt, and after about 30 images the OOM killer took the OCR model. cache-ram = 0. One-shot OCR of unique images gains nothing from that cache. Resident memory stays flat now.
  3. The GPU drops its Vulkan device under load. Four amdgpu ring resets in one night: one with two models in flight, the rest during long single extractions on the 4B model. After each one, llama-server kept running and its health check stayed green while every request failed in under a second. A small gateway in front of llama-server serializes every GPU call behind one lock. On a device-lost error it signals a root-side systemd path unit, which restarts llama-server; the gateway then retries the request once when the OCR model is back (about 20 to 30 s). The rest of the batch ran unattended. The root cause is still open. Suspects: the card's PCIe link running at x2, VRAM pressure from the 4B model's 16k context, and Navi 10 power management.
  4. Vision encoders differ a lot on Vulkan. Qwen3-VL-2B took 11.9 s to encode a photo that GLM-OCR encoded in 2.8 s. Two stages: a 0.9B OCR model reads the page, then a text-only 4B model writes the JSON. The VLM stays installed for image questions, outside the default path.
  5. Forcing every field costs decode time. With every key required, grammar-constrained decoding dominates the run: a long receipt costs about 20 s. For batch work that is fine. For interactive use, run OCR only (2 to 4 s) and extract asynchronously, or trim the schema.
  6. Re-encoding an image changes the OCR output. GLM-OCR's output varies slightly with JPEG re-encoding. JPEG and PNG images up to 1,600 px on the long side pass through untouched; larger or other-format images are re-encoded once. PDFs with a text layer skip the GPU entirely.
  7. A 4B extractor guesses. It labeled an unmarked receipt in Indonesian rupiah as US dollars, despite the prompt's instruction. Treat the currency field as a hint, and check that items plus tax equal the total downstream instead of trusting the model.
  8. On Apple Silicon, the GPU's share of memory sets the ceiling. Metal reported 13.3 GiB usable on the 18 GB M3 Pro and 37.4 GiB on the 48 GB M5 Pro. Pick the quantization to fit that number, with room for the KV cache. The largest model on the M3 Pro was the 11.28 GB gpt-oss 20B at MXFP4. The M5 Pro holds a 22.1 GB MoE checkpoint with a 40,960-token q8_0 cache, or the 28.85 GB 8-bit 27B through MLX.

Scope

Everything on this page is inference: choosing quantizations, context lengths, cache types, offload, batch sizes, grammars, penalties and memory limits, then swapping models after measuring them. Nothing on this page involves fine-tuning, LoRA adapters or training; no weights were changed.

Sources: the GPU server's README, session handoff, router preset, systemd unit, gateway code and 2026-09-14 receipts report in the home lab repository; the llama-server launch preset; the MLX server's settings and stats files; model configs and file names in the local Hugging Face cache; the Ollama launch agent and log; a January 2026 model inventory for the M3 Pro; system_profiler; llama-server --help for defaults; the MTPLX package page on PyPI; the README of a 2025 natural-language-to-SQL project; a speech-to-text script. MTPLX and Langfuse use: author, 2026-11-07. Checked 2026-11-07.