Skip to content

Local inference

Last updated: 2026-11-24T13:28:29-03:00 (UTC-3)

Local inference puts model servers you host behind the gateway as pools of replicas. You say where the replicas are, or let the gateway start them, and it does the rest: it health-checks every replica, sends traffic only to the ones that are ready, spreads requests by how busy each replica is, restarts a replica that dies and tells you why it died.

You run Backend Page
A Mac with Apple Silicon llama.cpp with Metal llama.cpp
A Mac with Apple Silicon MLX MLX
A Mac with Apple Silicon Ollama Ollama
A host or a cluster with NVIDIA GPUs vLLM in Docker or Kubernetes vLLM
Any host without a GPU llama.cpp, Ollama or vLLM on the CPU the same pages

On a Mac the model servers run as native processes, not containers: Docker on macOS does not see the Apple GPU.

Three rules hold everywhere:

  • The weights are yours. You download or build the model and put it in a directory you name. The gateway never downloads weights and never installs a model server.
  • A replica is a destination of its own. Each one becomes a provider connection named <pool>-r<n>, so the router, the circuit breaker, the request log and the metrics treat it like any other destination.
  • Everything is off until you turn it on. The feature has its own flag, and each GPU capability has one more.
  1. Set features.local_inference: true. This alone is enough for replicas on the CPU and for replicas you run yourself.
  2. Turn on the GPU flags you need (see Flags).
  3. To let the gateway start model servers, set local_inference.supervise: true and the path of each executable under local_inference.runtimes in the gateway YAML, then restart. Skip this step if you only register servers that already run.
  4. Declare a pool under local_inference.pools, in the YAML or on the console’s Local inference screen.
  5. Call the pool’s alias like any model.

The smallest pool registers two servers that already run and gives them one alias:

features:
local_inference: true
local_inference:
pools:
- id: qwen
backend: vllm
model: qwen05
alias: local-qwen
endpoints:
- url: http://10.0.0.5:8000/v1
- url: http://10.0.0.6:8000/v1
Terminal window
curl -s http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer $GATEWAY_KEY" -H "Content-Type: application/json" \
-d '{"model":"local-qwen","messages":[{"role":"user","content":"Say hi"}]}'

A key may call the alias when the alias is in its allowed models, like any other model.

Every flag is off by default and is an operator control, changed in the YAML or under Settings & sources without a restart.

Flag What it allows Needs
local_inference Pools, health checks, routing by replica load, supervision. With only this flag on, every replica runs on the CPU —
local_inference_gpu A pool may use a GPU at all (gpu.mode other than off) local_inference
local_inference_metal Pools with gpu.mode: metal: llama.cpp with Metal, MLX and Ollama on Apple Silicon local_inference_gpu
local_inference_nvidia Pools with gpu.mode: nvidia: vLLM, or llama.cpp and Ollama built for CUDA local_inference_gpu
local_inference_mig One replica bound to each NVIDIA MIG slice by its UUID local_inference_nvidia

A pool whose flags are not all on does not run: its replicas show Blocked with the missing flag named, and receive no traffic. Turning a flag off stops the replicas that need it. A pool with gpu.mode: off (the default) needs only local_inference: llama.cpp is started with no layers offloaded, a vLLM container gets no GPU, and Ollama is started with its GPU offload disabled.

Two more flags matter. routing_strategies (on in the shipped configuration) is what makes least_busy order the replicas; without it the alias keeps its declared order. provider_metrics_scrape shows each replica’s own queue next to the gateway’s numbers (see Metrics).

Mode Who runs the model server What the gateway does Use it when
register (default) You: a Kubernetes Deployment, systemd, another host Health-checks each endpoint, routes by load, takes a replica out of routing when it stops answering The servers run in Kubernetes or on other hosts, or more than one gateway replica serves them
supervise The gateway process All of the above, plus: starts each replica, restarts it with backoff when it dies or hangs, stops it on request and when the gateway shuts down One gateway process on the host that has the GPU: a Mac, a single GPU server

Supervision belongs to one gateway process on one host. Every gateway replica runs its own supervisor, and two of them on the same host would compete for the same ports, so run a single gateway process there. With several gateway replicas (Kubernetes), use register.

These settings decide what a gateway process is allowed to execute. They are read from the gateway YAML at start, need a restart to change and cannot be set through the API or the console, which only show them. A pool written through the API can only combine what they admit.

Setting Default What it is
local_inference.supervise false true lets this process start model servers. With false, a pool with mode: supervise is refused
local_inference.runtimes.llama_cpp empty Absolute path of llama-server. Empty: the backend cannot be supervised on this host
local_inference.runtimes.mlx empty Absolute path of mlx_lm.server
local_inference.runtimes.ollama empty Absolute path of ollama
local_inference.runtimes.container empty Absolute path of the container runtime (docker) that runs the vLLM backend
local_inference.runtimes.nvidia_smi empty Absolute path of nvidia-smi, used to find the GPUs and MIG slices when a pool lists no gpu.devices
local_inference.model_dirs empty Up to 16 directories weights may be read from. A pool’s weights must be inside one of them, also after symbolic links are resolved
local_inference.container_images empty Up to 16 images a vLLM pool may run, written exactly as the pool names them. Pin a digest

The gateway builds every argument itself from the typed fields below. It runs no shell, starts each model server with a minimal environment (none of the gateway’s own variables, so none of its secrets) and binds every supervised replica to 127.0.0.1: the gateway is the only way in.

local_inference.pools takes up to 16 pools, 16 replicas per pool and 32 replicas in all.

Setting Default Bounds What it is
local_inference.pools[].id required 1–40 lowercase letters, digits, hyphens Names the pool and its replicas: replica 2 of qwen is the connection qwen-r2
local_inference.pools[].backend required llama_cpp, mlx, ollama, vllm The model server
local_inference.pools[].mode register register, supervise Who runs the servers (see Two modes)
local_inference.pools[].model required 1–128 characters The model name the replicas serve; it is what the gateway sends upstream
local_inference.pools[].alias none 1–128 characters, one pool per alias The gateway declares a chat model with this ID over every replica. Leave it empty, or declare a model with the same ID in the YAML, to write the targets by hand. The generated alias follows the pool and is not edited in the model catalog
local_inference.pools[].routing_strategy least_busy; ordered with gpu.share_device least_busy, ordered How the generated alias orders the replicas (see Routing)
local_inference.pools[].disabled false Keeps the pool in the configuration and runs and routes nothing
local_inference.pools[].scrape_metrics true Declares /metrics on each llama.cpp or vLLM replica for the model server metrics scrape

Supervised pools (mode: supervise):

Setting Default Bounds What it is
local_inference.pools[].weights required inside model_dirs Where you put the model: a .gguf file (llama.cpp), a model directory (MLX, vLLM) or the model store directory (Ollama)
local_inference.pools[].replicas 1 1–16 How many servers run
local_inference.pools[].port_base required 1024–65535 The loopback port of replica 1; replica n listens on port_base + n - 1. Ports may not overlap between pools
local_inference.pools[].slots the server’s default 1–256 Requests one replica serves at the same time
local_inference.pools[].context_tokens the server’s default 256–1048576 The context window of one request. Not for MLX, which takes the model’s own
local_inference.pools[].image required for vLLM one of container_images The container image of a vLLM pool
local_inference.pools[].stop_grace 10s 1s–5m How long a stop waits for requests in flight, and then for the process to end, before it is killed
local_inference.pools[].extra_args none 32 arguments of up to 256 characters Appended to the model server’s own arguments. YAML only. They may not set the model, the address, the credential or a download source, which the gateway owns

GPU use (local_inference.pools[].gpu):

Setting Default Bounds What it is
local_inference.pools[].gpu.mode off off, metal, nvidia off keeps the pool on the CPU. The others need their flags
local_inference.pools[].gpu.devices discovered up to 16 With nvidia: one replica is bound to each entry, a GPU UUID, a MIG UUID or a GPU index. Empty: the gateway asks nvidia-smi and takes the MIG slices of a card in MIG mode, the whole card otherwise. Discovery hands the whole host to one pool: to split a host between pools, name the devices in every one of them
local_inference.pools[].gpu.share_device false Allows more replicas than devices: several replicas on one GPU without MIG. Accepted with a warning (see One replica per GPU)
local_inference.pools[].gpu.memory_fraction 0.85 of a GPU, 0.70 of a small MIG slice 0.05–0.95 vLLM only: the share of the device’s memory one replica may take (see Memory headroom). With share_device, the replicas on one device must fit in it together

Registered pools (mode: register):

Setting Default Bounds What it is
local_inference.pools[].endpoints[].url required 1–16 endpoints The replica’s OpenAI-compatible base URL, such as http://10.0.0.5:8000/v1. No credentials, query or fragment
local_inference.pools[].endpoints[].device none 1–96 characters A label for the GPU or MIG slice behind the replica, shown on the screen. A label starting with MIG- needs local_inference_mig
local_inference.pools[].api_key_env none an environment variable name The variable holding the bearer key the replicas ask for. Empty sends no credential. YAML only, like extra_args: it sends a variable of the gateway’s environment to the endpoints

Health and restart:

Setting Default Bounds What it is
local_inference.pools[].health.path /health; /api/version for Ollama an absolute path Probed on the replica’s origin. The model list (/models under the base URL) is probed too: a replica is ready when both answer 200
local_inference.pools[].health.interval 5s 1s–5m Time between probes
local_inference.pools[].health.ready_timeout 5m 5s–1h How long a started replica may take to pass its first probe. Past it, the replica is ended and restarted. Raise it for a large model
local_inference.pools[].health.unhealthy_after 3 1–20 Failed probes in a row that take a ready replica out of routing. Twice as many end and restart a supervised replica
local_inference.pools[].restart.backoff 2s 500ms–1m Wait before the first restart. It doubles on every failure in a row, up to one minute
local_inference.pools[].restart.max_per_hour 6 1–60 Restarts in one hour after which the replica is left Failed until you start it

The generated alias uses least_busy: each request goes to the ready replica with the fewest requests in flight. That is the right default for replicas that each have their own GPU or MIG slice, and for CPU replicas. Measured on seven MIG slices of one NVIDIA A100, least_busy served 9% and 10% more tokens per second than the declared order at 6 and 32 concurrent streams and 125% more at 224, and was never worse.

A replica that is not ready is skipped before anything is sent: one still loading its model, restarting, stopped or blocked never receives a request. When no replica of the alias is ready, the answer is 503 with the code replica_not_ready.

To add a cloud fallback, or any other routing policy, declare the model yourself with the same ID as alias and name the replicas as targets:

models:
- id: local-qwen
routing_strategy: least_busy
targets:
- {provider: qwen-r1, model: qwen05}
- {provider: qwen-r2, model: qwen05}

Give each replica its own GPU or its own MIG slice. That is the rule the gateway applies: a supervised pool with more replicas than devices is refused, unless you set gpu.share_device: true.

Sharing is allowed, with a warning on the screen and in the log, because the gain depends on the load:

  • On NVIDIA without MIG, two vLLM replicas on one card take turns on it. Measured on an A100, they served 51% fewer tokens per second than one replica at 6 concurrent streams and 37% fewer at 32, and twice as many only at 224 streams, once a single server was saturated. So the generated alias of a shared pool defaults to ordered, which keeps traffic on the first replica until it fails. Prefer MIG where the card has it: the same two replicas on two slices lost nothing.
  • On Apple Silicon there is one GPU, so more than one replica always shares it. Measured on an M4 Pro, three llama.cpp replicas of two slots each served 536 tokens per second at 6 concurrent streams with a first token in 31 ms, against 444 tokens per second and 1.4 s for one replica: the replicas buy slots, so nothing queues, more than raw throughput. Set routing_strategy: least_busy on such a pool.
State Meaning Receives traffic
Starting The process runs and has not passed its health check yet (the model is loading) no
Ready Both probes answer 200 yes
Unhealthy A ready replica failed unhealthy_after probes in a row no
Restarting The process ended, or was ended for not answering; the next start waits for the backoff no
Failed Restarted restart.max_per_hour times in one hour. It stays down until you start it no
Blocked It may not or cannot start: a flag is off, no device is left, the port is taken, the weights are missing no
Stopping, Stopped An operator stopped it no

Every state comes with its reason, the way the process last ended (exit status or signal) and the last line it wrote, so a dead replica explains itself. On the same M4 Pro a replica killed under load was running again and ready 3.2 seconds later; no client saw an HTTP error, because requests that had not started were moved to another replica.

Three things to know:

  • A restarted replica also waits for its circuit. If the dying replica failed enough requests to open its circuit, it takes traffic again when its health check passes and the circuit’s open time (30 seconds by default) has run out.
  • A stop drains. It takes the replica out of routing, waits up to stop_grace for the requests in flight and only then ends the process.
  • A port that is already taken is never fought over. If another process listens on a replica’s port, such as a model server left by a gateway that was killed, the replica shows Blocked with port_in_use. End that process and the replica starts by itself.

When the gateway shuts down it ends every model server it started.

Gateway → Local inference shows the five flags, what this host may start, and one card per pool with a row per replica: state and reason, health (ready since, last check, circuit), GPU or slice, load (requests in flight from this gateway, plus the replica’s own running and waiting requests when the metrics scrape is on) and restarts (total, in the last hour, last exit and last output line). The screen refreshes every five seconds.

What you can do depends on your permissions:

Permission Built-in roles Allows
local_inference:read admin, viewer, operator Seeing the screen and GET /api/v1/admin/local-inference
local_inference:operate admin, operator Start, Stop and Restart on a replica
local_inference:manage admin Edit pools, Save pools and Revert to YAML

A custom role based on viewer or operator may keep or drop local_inference:read. Team roles never see the screen: pools are the operator’s infrastructure, shared by every organization.

Replica state belongs to the gateway process that answers. With several gateway replicas, each one probes on its own and the screen shows the one your request reached. An action applies to that process and is not stored: after a gateway restart every replica starts again.

Route Permission What it does
GET /api/v1/admin/local-inference local_inference:read The flags, what the host may start (without the executable paths), the limits and every pool with the state of its replicas
PUT /api/v1/admin/local-inference local_inference:manage Stores {"version": n, "pools": [...]} as the pool list, replacing the YAML’s on every gateway replica. Validated like the YAML; extra_args and api_key_env are accepted only unchanged, for a pool the YAML declares with the same backend, mode, weights, image and endpoints; 409 on a stale version, 422 with the pool and field named
DELETE /api/v1/admin/local-inference local_inference:manage Removes the stored list: the YAML’s pools are in force again
POST /api/v1/admin/local-inference/pools/{id}/replicas/{replica}/{action} local_inference:operate action is start, stop or restart; replica is the number from 1. Answers 202; read the state from the GET. restart of a registered replica answers 409
Terminal window
curl -s -X POST -H "Authorization: Bearer $GATEWAY_ADMIN_TOKEN" -H "Content-Type: application/json" -d '{}' \
http://localhost:8080/api/v1/admin/local-inference/pools/qwen/replicas/2/stop
{"action":"stop","pool":"qwen","replica":"qwen-r2","scope":"process"}

A saved pool list is a versioned, audited configuration change (local_inference.set, local_inference.revert). The connections <pool>-r<n> cannot be edited or deleted through the provider routes, nor the generated alias through the model routes; change the pool.

Three cases to know:

  • Editing a pool. A change to how a replica is started (backend, model, weights, image, ports, slots, context, GPU settings, replica count) replaces the replica: the old one finishes its requests in flight, up to stop_grace, before the new one starts, and a replica you had stopped stays stopped. Any other change (the alias, the routing strategy, health and restart settings) applies in place and leaves the process alone.
  • A stored list the YAML stops admitting. If you later turn supervise off, remove a runtime, an image or a model directory, or change the extra_args a stored pool repeats, the stored list is set aside: nothing of it runs, the YAML’s pools are in force, the GET answers the reason in override_ignored and the log has one local_inference_override_ignored line. Save a valid list or revert.
  • With gitops.source_of_truth: file and pools declared in the YAML, the file wins: the PUT and the DELETE answer 409 source_of_truth_file and a stored list is set aside.

With metrics_endpoint on, /metrics (and OTLP metrics) carries one series per replica, labelled pool, replica and backend:

Series Meaning
gateway_local_inference_replica_ready 1 while the replica receives traffic
gateway_local_inference_replica_state 1 on the state it is in (label state)
gateway_local_inference_replica_in_flight Requests this gateway process has in flight on it
gateway_local_inference_replica_restarts_total Times the gateway restarted it

The gateway’s usual series (gateway_upstream_attempts_total, gateway_provider_errors_total, gateway_circuit_breaker_state and the rest) carry each replica as provider="<pool>-r<n>".

The model server’s own metrics come through the model server metrics scrape: turn on provider_metrics_scrape and every llama.cpp and vLLM replica is scraped at /metrics with no further setting. MLX and Ollama publish no Prometheus metrics.

Every change of a replica’s state is a structured log line named local_inference_replica, with event (replica_starting, replica_ready, replica_unhealthy, replica_backoff, replica_failed, replica_blocked, replica_stopping, replica_stopped), pool, replica, backend, mode, state, reason, device, pid, restarts_total and, for a replica that ended, last_exit. An operator action is local_inference_replica_action with the request’s correlation IDs, and a pool warning is local_inference_pool_warning. With otlp_logs on they reach your collector like every other line. Nothing a model server wrote is logged.

  • Supervision is for one gateway process per host. Use register with several gateway replicas.
  • Replica state, and a stop or start, live in the memory of one gateway process.
  • The gateway reads the GPU layout; it does not create MIG slices or switch a card to MIG mode.
  • Replicas of one pool are treated as equal. Do not mix slices of different sizes in one pool.
  • least_busy counts the gateway’s own requests in flight. Traffic that reaches a replica without passing through the gateway is not counted.
  • Weights are checked for being where you said. Their content is not verified.

m7gtwcontact@m7gtw.com