Skip to content

Remote models: models on another machine, as a first-class kind - #2

Open
yuhuanowo wants to merge 5 commits into
NoobBandi:mainfrom
YuhuanStudio:remote-models
Open

yuhuanowo wants to merge 5 commits into
NoobBandi:mainfrom
YuhuanStudio:remote-models

Conversation

@yuhuanowo

@yuhuanowo yuhuanowo commented Nov 16, 2026 •

Copy link
Copy Markdown

Closes #1.

A model can live on another machine: llama-swap's proxy: already
forwards to a server elsewhere, and OpenRouter needs no hardware at all.
Until now the console had no shape for that. Such entries were read as
local llama.cpp models: the Models page grouped them under llama.cpp,
every /v1 request ran makeRoom for them -- pausing and unloading
local models, and possibly freeing a ComfyUI mid-image, to make room on
this machine for a model this machine does not start -- and the props
poller walked their /props on each request.

Four commits, each one thing:

1. Never make room on this machine for a model it does not start.
llamaswap.Store.RemoteProxy answers "which URL does this entry
forward to" -- an explicit proxy that is not loopback, or loopback with
the lifecycle placeholder (an ssh -L or tailscale tunnel). makeRoom
skips those entries; readModels stops polling their /props. A
loopback proxy without the placeholder stays what it was: a local
server on a fixed port. The rule is deliberately conservative -- a
fixed-port llama.cpp on 127.0.0.1 with a hand-written proxy could take
the same answer and would be safe; the reverse (treating a remote entry
as local) frees VRAM nobody owns.

2. Read the answer once per config change, not once per request.
Same mtime-cache pattern as CanonicalModel, same invalidation.

3. docs/remote-models.md: the config shape and what is measured.
The entry (placeholder cmd that anchors llama-swap's lifecycle, the
proxy, useModelName for servers that validate the model field, a
health check), what the console owns (load/unload of the forwarding
side, /v1, bench of the whole path) and what it never does (install,
GPU-place, poll, evict for it), and a pairing run with a real Mac
engine: an A/B shows the unpatched console hitting the upstream 8 times
per 8 requests, the patched one 0.

4. The model editor adds remote servers too, and the list says what they are.
The form asks where the model lives (本機模型 / 遠端服務器) and its answer
retires the fields a server elsewhere makes meaningless: file, card,
context, layers, quantisation. Upsert writes the documented shape,
ReadSpec reads it back, and one rule -- RemoteProxy, the same view
commits 1 and 2 use -- decides everywhere: the Models page groups these
under their own 遠端模型 engine rather than lying that they are
llama.cpp; the Engines page keeps its three installable records; a
moved-back-to-local entry loses the keys the console wrote, and nobody's
hand-written proxy is ever touched.

Measured end to end (Mac engine behind a relay, llama-swap v273, patched
console): create via the form -> config written -> spec read back ->
chat answers; OpenAI stream and non-stream, aliases, legacy
completions, Anthropic /v1/messages and count_tokens, tools; API-key
authz, admin/member split; unload-all and reload; edit name+URL round
trip; delete (no files, siblings untouched); a quick-tier bench run
against a remote entry, 6/6, real numbers (ttft 1.26 s, prompt 807
tok/s, gen 71 tok/s), /v1 paused and resumed around it. Full Go
suite green (31 packages, postgres 17); go vet; web tsc and build
green, no new lint warnings.

Known and documented in the doc's limits: a model entry cannot carry an
Authorization header (serve on a network you trust, or bring a tunnel);
bench times the whole path, network included; the ComfyUI-eviction guard
is unit-covered but this machine has no GPU to race it for real; and
because the placeholder loads instantly, a remote entry reads as loaded
until llama-swap is told otherwise.

Why this is not an engine is written in the doc: nothing to install, no
card to place it on. What it is instead is the first rung of the ladder
#1 sketches -- remote kind, then a console that runs where the engine
is, then host-runtime engines, then whatever apple vendor follows --
each one mergeable on its own, and the unified-memory question the
vendor doc poses never has to be answered for the first rung at all.

A model served by another machine can be reached today by a hand-written
llama-swap entry: a placeholder cmd, an explicit proxy, a checkEndpoint.
The console read such an entry as a local one: makeRoom sized "the whole
card" for it and freed -- or waited on -- every ComfyUI on the machine
before any request naming it, and readModels polled /props on the
foreign server twice a poll as if it were llama-server. Neither helps
the model, and both cost the machine.

Recognise the form (a proxy that is explicit, not loopback, and carries
no ${PORT} or macro) as llamaswap.Store.RemoteProxy, keep makeRoom out
of such entries, and stop polling them as llama-server.
docs/remote-models.md records the entry, measured against llama-swap
v273 with the OpenAI-API stub it forwards to, and the MLX section of
adding-a-gpu-vendor.md points at it: until that port exists, this is
how a server on another platform joins the machine.
The guard in makeRoom asks RemoteProxy on every /v1 request that names
a model, and parsing the YAML there would charge a parse per request
for something that changes once a config edit. Cache the remote view
between file changes exactly as CanonicalModel caches the aliases:
same mtime stamp, same lock, same failure behaviour.
The recipe was written from the protocol and measured against a stub;
now it has been run end to end -- a Linux console, llama-swap v273, and
Yunshu on an Apple Silicon Mac serving Qwen3-4B-MLX-4bit -- through
chat (streaming and not), the legacy completions, Anthropic messages
and count_tokens, a tool call, unload and reload, and the admin and
member accounts. useModelName joins the example: servers that check
the model field refuse the entry's id otherwise.
… are

The recipe in docs/remote-models.md worked only as hand-written YAML
and the Models page then filed it under llama.cpp -- a lie about where
the weights are. The form now asks where the model lives (本機模型 or
遠端服務器) and its answer retires the fields a server elsewhere makes
meaningless: file, card, context, layers, quantisation. Upsert writes
the documented shape -- placeholder cmd, explicit proxy, useModelName,
health check -- ReadSpec reads the same fields back, and one rule
(the RemoteProxy view, already what makeRoom and the /props guard use)
decides everywhere: ProviderKeys, the group dropdown and the table's
tag all say 遠端模型; the Engines page keeps its three installable
records; a moved-back-to-local entry loses the keys the console wrote
and nobody's hand-written proxy is ever touched. Loopback with the
placeholder (ssh -L, a tailscale serve) is remote; loopback without it
is still a local server on a fixed port, as before.
@yuhuanowo
yuhuanowo requested a review from NoobBandi as a code owner November 16, 2026 15:03
Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote models: a model served on another machine, as a first-class kind

2 participants