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.ChunkDecoder/ToolCalls: OpenAI server-sent events decoded intoChunks (text, reasoning, tool-call fragments, finish reason and usage).ModelHost: aweirdnet-agent0.4InferHostserving raw infer/2 from the supervisor's models. Cancel aborts the engine request; assistant prefixes continue (resume); draining refuses new requests.
use Arc;
use ;
let chat = new;
let sup = new;
sup.load.await?;
let host = new; // serve with weirdnet_agent::remote::infer::v2::serve
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.