weirdnet-backends
The Weirdnet model-node wrapper. A model node runs models and takes requests, like a llama.cpp, vLLM or MLX-LM server (it can even be one: a stock server it only wraps). This crate starts and stops the engines and serves them to inference nodes; what to load is always the caller's decision.
EngineConfig/ModelLaunch: howllama-server,vllm serveand MLX-LM'smlx_lm.serverare launched (loopback only, random port, per-process API key in the environment, or checked by a proxy for MLX-LM) and probed. Ready means the server on the port takes the launch's key and lists its model; a port taken by another process before the engine binds it is retried on a new one.Wrapattaches to a stock OpenAI-compatible server on loopback without owning it.Capabilities: what each model takes (chat, embeddings, images, audio), inModelStatusand so in capability records, so routing keeps image, audio and embedding requests off models that can't serve them.ModelLaunch::capabilitiesderives it: embedding models only embed; llama.cpp models with a multimodal projector (--mmproj) take images and audio; vLLM and MLX-LM models are text only.Supervisor: load and unload with draining, swap groups (loading one model of a group unloads the others), idle unload, crash restarts with exponential backoff and crash-loop detection,SupervisorEvents, per-model logs; chat, completion and embedding forwarding.Supervisor::reserve(holder)holds the node's GPU for one job (a training run, say): it stops every engine and starts none untilrelease(holder).add_modelandremove_modelchange the served models at run time, without a restart.ChunkDecoder/ToolCalls: OpenAI server-sent events decoded intoChunks (text, reasoning, tool-call fragments, finish reason and usage).ModelHost: aweirdnet-agent0.5InferHostserving raw infer/2 from the supervisor's models. Cancel aborts the engine request; assistant prefixes continue (resume); draining refuses new requests.- Images and audio:
weirdnet-agent0.5 content parts (image_urlwith adata:URL,input_audio) reach llama.cpp unchanged, in the OpenAI shape.ModelHostrefuses them for a model whoseCapabilitieslack them (Unsupported, so a pool tries another node) and refuses remote image URLs (BadRequest).Capabilities::inputs()gives theModalitiesan inference node puts in its catalog entry (CatalogModel::with_inputs).
use Arc;
use ;
let chat = new;
let sup = new;
sup.load.await?;
let host = new; // serve with weirdnet_agent::remote::infer::v2::serve
Managing model files (models/1)
models::ModelsService serves /weirdnet-backends/models/1 to the node's owner only: pass it
an Authorize such as weirdnet_agent::serve::RosterAuth (the owner's linked devices, narrowed
with require_roles if you like). Commands: Search (Hugging Face Hub, GGUF repos), Files
(a repo's models with each footprint against the node's memory budget), Pull (download with
progress, resuming a partial file; split GGUFs too; without a named model, the largest that
fits), with serve/load to hand it to the supervisor without a restart, List and Remove.
Closing a pull's stream cancels it. The Hugging Face token is the node's own
(weirdnet-model HfToken) and never crosses the
wire. ModelsServer::start serves it on a weirdnet-net node; ModelsClient is the owner's side.
use ;
let svc = new;
let _server = start?;
// From the owner's device:
let fits = client.files.await?;
let pulled = client.pull.await?;
Uploading your own models (models/1)
Model files made elsewhere (a fine-tune, a merge, a quantization) go to a node with
ModelsCommand::Upload. The client reads them with
weirdnet-model artifact::inspect (GGUF models,
split models, LoRA adapters and vision projectors; Hugging Face safetensors and MLX model
folders; PEFT adapters), which hashes every file and refuses pickles, code and symlinks. The
node checks names, size, free space, its engine and (for adapters) the base before any bytes
move, checks headers as the first bytes arrive, and checks every SHA-256 at the end before
placing the files with ModelStore::import. Uploads go in 48 KiB chunks and resume: a closed
stream leaves the parts staged next to the store (kept 7 days by default), and the next upload of
the same files sends only the rest. Each stored entry keeps a provenance.json (origin, license,
base, dataset, trainer, who uploaded it and when), which List returns.
serving() hands a model to the supervisor (GGUF on llama.cpp, safetensors on vLLM, MLX on
MLX-LM, when the node runs that engine), an adapter to its base (with_adapter_for, live where
the engine allows) and a projector to its llama.cpp model (with_projector_for, which gives it
image input). Pulled::revision is the files' content revision for the node's capability record.
Writes (upload, remove, peer copies) follow the service's WritePolicy: by default any caller
the service's Authorize admits, such as any linked device under RosterAuth; with_auth adds
a separate check (for example a device role). It also sets a largest upload, a total quota for
uploads and how much disk stays free (KeepFree, by default the larger of 10% and 20 GiB).
Refusals carry a stable reason (refusal_reason: exists, too-big, no-space, quota,
wrong-engine, wrong-arch, no-base, bad-name, bad-format, not-adapter, not-allowed,
checksum, not-found). Disk reports free space, the limits and what uploads use.
A node copies an upload from another node with Pull::from_peer(node, upload) (over
ModelsCommand::Fetch, resuming like an upload), given ModelsService::with_peer_dialer.
After one upload, ModelsClient::replicate has the other nodes pull it from that node.
use Upload;
use ;
let files = vec!;
let found = inspect?;
let upload = new.serving;
let pulled = client.upload.await?;
let copies = client.replicate.await;
LoRA adapters
A ModelLaunch can carry LoRA adapters (LoraAdapter::new(id, path), optionally
with_scale), each served under its own id next to the base model. On llama.cpp the adapters
are GGUF LoRA files for the base's architecture, loaded with --lora and
--lora-init-without-apply; each request names its adapter and scale in the lora field, so
the base stays plain. On vLLM they are PEFT LoRA directories (or Hub ids) in one
--lora-modules list with --enable-lora and --max-loras, and a request names the adapter
as its model. Embedding models and MLX-LM take no adapters.
Supervisor::add_adapter adds one to a served base: AdapterChange::Live when the base is not
running, AdapterChange::NextLoad when it is (loading the adapter's id restarts the base with
it). remove_adapter takes one off; remove_model on a base removes its adapters too.
load(adapter) loads its base and unload(adapter) is refused. status() has a row per adapter
with base set.
Changes while the base keeps running:
add_adapter_liveandremove_adapter_livealso load and unload the adapter in a running vLLM engine (/v1/load_lora_adapter,/v1/unload_lora_adapter). The supervisor starts vLLM withVLLM_ALLOW_RUNTIME_LORA_UPDATING=Truewhenever LoRA is on: the base has adapters, orModelLaunch::with_lora_slots(n)turns it on with none (--max-lorasis at leastn).- llama-server loads adapter files only at start. An adapter whose file the running engine
already has (removed and added back, under any id) is live at once; a new file is
AdapterChange::NextLoad. set_adapter_scale(id, scale)changes a llama.cpp adapter's scale from the next request, and a request can set its own with infer/2Request::adapter_scale(weirdnet-agent 0.5.2;complete_scaledfor raw completions). vLLM applies adapters at full strength and refuses both. Scales must be finite and within ±MAX_ADAPTER_SCALE.
use ;
let chat = new
.with_adapters;
With the node feature, models/1 pulls an adapter for a served base:
Pull::new(repo).with_adapter_for("qwen3-8b").serving(true) downloads it with
weirdnet-model download_adapter and adds it.
Adapters whose architecture or base model does not match the base are refused. Files lists a
repo's adapters in RepoFits::adapters, and List and Remove cover adapters.
ServeAdapter, UnserveAdapter and AdapterScale (ModelsClient::serve_adapter,
unserve_adapter, set_adapter_scale) put a stored adapter on a base, take one off while
keeping its files, and change its scale, live where the engine allows.
MLX-LM (Apple silicon)
EngineKind::Mlx runs MLX-format models with mlx_lm.server on macOS on Apple silicon:
use ;
let server = install?; // pinned mlx-lm in a venv (uv, else python3)
let mut qwen = new;
qwen.context = Some; // becomes --max-tokens
let engines = vec!;
- Launch:
mlx_lm.server --model <dir> --host 127.0.0.1 --port <p> --max-tokens <context>(32768 when no context is set; MLX-LM's own default is 512). - MLX-LM has no API key, so it runs on a private loopback port and the model's port is a small
proxy in the node that checks the per-process key as a bearer token, rewrites each request's
modelto MLX-LM'sdefault_model, lists the pool id in/v1/modelsand streams responses through. - A wrapped stock
mlx_lm.server(ModelLaunch::wrapwithEngineKind::Mlx) gets the same proxy. - Ready only after a one-token completion succeeds (MLX-LM's
/healthis 200 before the weights are loaded). - Text only: image and audio content parts get 400, and so does
/v1/embeddings;Supervisor::embedrefuses MLX models, and an MLX model withembeddingset fails to load. Run embedding and vision models on llama.cpp. mlx::installputsmlx-lm==0.32.2(mlx::MLX_LM_VERSION) into a venv made byuv(Python 3.12) when it is onPATH, else bypython3 -m venv;mlx::install_commandsgives the commands for apps that run them themselves.
The node feature: /weirdnet-backends/node/1
How inference nodes drive model nodes over weirdnet-net.
- Capability records, pushed to every subscriber: hardware and memory budget
(
weirdnet-modelhw), engines, every configured model (state, revision, quantization, context and slot limits, load-time estimate, measured prefill/decode speed and time to first token), load (queued, active, slots, in flight), warm prefix hashes, swap groups, draining, its reservation, whether the node takes group jobs and its private links (NodeService::set_links,link::local_links: address, class, interface, nominal and declared speed; public and CGNAT addresses are never advertised). Each is signed by the node key, chained to the user by itsNodeCert, carries an increasing sequence number and expires after 90 s; it is refreshed every 15 s and on every change.Verifierchecks the signature, the signer, the expiry and the user's certificate, and withVerifier::with_rosterthat the node is still linked (a revoked node's record is refused even with its old certificate);Subscriptionalso rejects sequence numbers that go backwards. - Commands:
Load(withforcefor a crash loop),Unload,Drain(stop admissions and wait for requests under way, or resume),Reserve/Release(hold the GPU for a holder: nothing loads, runs or joins a group there until released; since 0.4.3),GroupUp/GroupDown,Health. Cross-machine swap groups (a Ray worker, anrpc-serveron a private link) are started by the application'sGroupWorkers; without one a node answersUnsupportedand advertisesgroup_jobs: false. NodeServer::startserves node/1 and raw inference on/weirdnet-backends/infer/1(RAW_INFER_PROTOCOL, the infer/2 framing) and, for 0.1.0 inference nodes, on/weirdnet-agent/infer/2;NodeServer::start_with(.., NodeServerOptions::default().with_legacy_infer2(false))leaves infer/2 free for a node that is also an inference node. Inference nodes wrap their model-node dialer inRawInferDialer, which tries the new id and falls back to infer/2. It announcesweirdnet-backends-nodewith the protocols served;NodeService::withdrawends subscriptions when the node leaves.NodeClientis the inference node's side, over anyweirdnet-agentDialer.- Who may drive a model node is an
Authorizehook;weirdnet_agent::serve::RosterAuthadmits the user's linked devices.
Platforms
| Linux | macOS | Windows | |
|---|---|---|---|
| llama.cpp | yes | yes | yes |
| vLLM | yes | no (vLLM is Linux-only) | no |
| MLX-LM | no | Apple silicon only | no |
| Graceful stop (SIGTERM, then SIGKILL after a grace period) | yes | yes | no: killed outright |
| Engine in its own process group (children stopped too) | yes | yes | no |
| Engine dies with the node process | yes (PR_SET_PDEATHSIG) |
no | no |
node feature |
yes | yes | yes |
The Unix-only pieces are behind cfg(unix); the library builds everywhere.
Tests
The adapter tests run against a mock engine (the test binary re-executes itself as a fake
llama-server/vllm serve/mlx_lm.server), never a real one. The MLX proxy has unit tests
against a fake MLX-LM server in src/mlx.rs; no test runs a real mlx_lm.server. tests/node.rs runs node/1 and raw infer/2
between in-process weirdnet-net nodes on the memory transport.