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.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.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?;
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.
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.
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, 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),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.