Skip to content

Local inference with Ollama

Last updated: 2026-11-24T13:41:15-03:00 (UTC-3)

Ollama serves models from its own model store with an OpenAI-compatible API under /v1. This page sets up a local inference pool the gateway starts and supervises. The commands and numbers were run on a Mac Mini M4 Pro with Ollama 0.40.18 and Qwen2.5-0.5B-Instruct (GGUF, Q4_K_M).

1. Install the server and build the model store

Section titled “1. Install the server and build the model store”

The standalone archive needs no installer:

Terminal window
mkdir -p /opt/ollama /opt/models/ollama-store
curl -fsSL https://github.com/ollama/ollama/releases/download/v0.40.18/ollama-darwin.tgz | tar -xz -C /opt/ollama

The gateway never pulls a model. Put your model in the store yourself, here from a GGUF file you already have:

Terminal window
OLLAMA_HOST=127.0.0.1:11500 OLLAMA_MODELS=/opt/models/ollama-store /opt/ollama/ollama serve &
printf 'FROM /opt/models/qwen2.5-0.5b-instruct-q4_k_m.gguf\n' > /tmp/Modelfile
OLLAMA_HOST=127.0.0.1:11500 /opt/ollama/ollama create qwen05 -f /tmp/Modelfile
kill %1
features:
local_inference: true
local_inference_gpu: true # leave these two off, and gpu.mode off, to serve on the CPU
local_inference_metal: true
local_inference:
supervise: true
runtimes:
ollama: /opt/ollama/ollama
model_dirs: [/opt/models]
pools:
- id: qwen-ollama
backend: ollama
mode: supervise
model: qwen05 # the name you gave the model in the store
alias: local-qwen-ollama
weights: /opt/models/ollama-store
slots: 2
context_tokens: 4096
port_base: 14231
gpu: {mode: metal}

weights is the model store directory. What the gateway runs for the replica:

Terminal window
OLLAMA_HOST=127.0.0.1:14231 OLLAMA_MODELS=/opt/models/ollama-store OLLAMA_NOPRUNE=1 OLLAMA_NO_CLOUD=1 \
OLLAMA_NUM_PARALLEL=2 OLLAMA_CONTEXT_LENGTH=4096 /opt/ollama/ollama serve
  • slots becomes OLLAMA_NUM_PARALLEL and context_tokens becomes OLLAMA_CONTEXT_LENGTH.
  • The store is never pruned, and the cloud models are off: the replica serves what is in the store and nothing else. A model that is not there answers 404.
  • Ollama keeps a client key and a small cache under ~/.ollama of the user the gateway runs as.
  • The health check is /api/version. Ollama publishes no Prometheus metrics, so scrape_metrics does nothing here.

Ollama decides GPU use by itself. With gpu.mode: off the gateway adds LLAMA_ARG_N_GPU_LAYERS=0 (and OLLAMA_LLM_LIBRARY=cpu and CUDA_VISIBLE_DEVICES=-1 for other versions and hosts). Verify it on your version, because the setting that works has changed between releases:

Terminal window
OLLAMA_HOST=127.0.0.1:14231 /opt/ollama/ollama ps
# NAME ID SIZE PROCESSOR CONTEXT
# qwen05:latest 9806541f10f4 406 MB 100% CPU 4096

On 0.40.18, OLLAMA_LLM_LIBRARY=cpu alone left the model at 100% GPU; LLAMA_ARG_N_GPU_LAYERS=0 moved it to 100% CPU.

Streamed chat, 160 output tokens, through the gateway:

Setup Concurrent streams First token (median) Decode per stream Total tokens/s GPU utilization
Metal, two slots 1 16 ms 269 tok/s 246 58% average, 76% peak
Metal, two slots 2 16 ms 222 tok/s 405 83%
CPU, two slots 1 13 ms 197 tok/s 181 3% average

The first request after a start loads the model and takes longer (about 0.3 s to the first token here). Ollama unloads an idle model after a few minutes and loads it again on the next request.

m7gtwcontact@m7gtw.com