Repository navigation
Studio cluster: pair machines on a home network, RPC over mutual TLS - #14274
danielhanchen wants to merge 118 commits into
Conversation
…ontexts, records)
…kers in cluster serving
…nsaction; use Registry.open and forget_identity
…eanly on SIGTERM; e2e harness no longer blocks on full pipes
… of hanging until expiry
… cannot leak listeners
…n agent running as pid 1 keeps it
…anished master frees its worker
… spoofed or flooded announcement cannot hide a paired worker
…usal; both arms run rpc-server with the same threads
…ed check and fair threads)
…serving on in every backend test
…mutual TLS and keep only paired announcements
…k reads Registry.open() as Path.open())
…last worker closes its relay
…losed, peers keep newer fields, a failed bind starts no rpc-server, clean pair errors, comma device lists, rpc-server gets Studio's library env
…StreamReader hop per chunk
…Windows have no PDEATHSIG)
Winsock's shutdown() from another thread does not wake a recv() already blocked on that socket, so a revoked (or half-ended) threaded session kept the relay's local-client pump blocked until the client itself closed, leaving the relay slot active. Wait for readability with WAIT_S first so the pump re-checks session.aborted / the other direction's end.
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Tested 8c76e99 end to end with a real 1. Four separate T4 machines (1 master + 3 workers)Run twice: with the shipped llama.cpp bundle (relay path) and with a CUDA build of unslothai/llama.cpp#309 (native TLS path). Same outcomes in both.
These were cloud GPU instances linked through TCP tunnels (I pointed 2. One machine with 4 x A10, one GPU per node, loopback
Text is identical to single GPU on every split path. On the direct path, killing a node fails the next chat and a reload runs on the remaining 3 devices. 3. One CPU-only Linux box, over its real LAN addressMaster plus two workers with separate state, paired over
4. Suites
These are the cluster and Spark test files under 5. llama.cpp PRs, each against its base, CPU and a 3-GPU CUDA split
Observations
|
|
Follow-up: tested on two real MacBooks on home Wi-Fi, and on a GitHub macOS 15 runner. Two MacBooks, same Wi-FiMaster: M2 MacBook Pro. Worker: second MacBook. Both on 8c76e99 via
GitHub macOS 15 runner (M1, Metal)Master and two workers on one runner, real
macOS notes
|
A dead llama-server serving a split model now returns the same lost-connection text as the streaming chat on non-streaming /v1/chat/completions, /v1/completions and /v1/messages, instead of the generic upstream error.
On macOS every connection from the master to a worker fails with No route to host until the app running Unsloth has Local Network access. cluster list and the dropped-worker notice now say where to allow it.
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@NilayYadav thanks for testing all of this, including the T4s, the A10 box, the LAN box and the two MacBooks on Wi-Fi. All three of your observations are fixed in
On the shipped bundle: until unslothai/llama.cpp#309 is in the prebuilt, installs use the relay. Your A10 numbers match what we saw: the native path was 102-109 tok/s against 88-93 for the relay at 4-way. Pinning #309 is the next step for that. The stack (#10280 -> #10323 -> #13726 -> #14274) is also merged with current main, which resolves #10280's conflicts. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Superseded by #18278, which has the same changes rebuilt on a stack that no longer needs the DGX Spark PRs: #18276 (ships #10280 and #10323 stay open as optional Spark extras stacked on top. Closing this one so review continues on #18278; the discussion here stays for reference. |
Stacked on #13726 (n-node serving). Pair machines on a home network once, then Studio splits a GGUF across them over llama.cpp RPC, with every byte between machines carried over mutually authenticated TLS. No accounts, no third party service, no internet needed.
Why
ggml-rpc-serverhas no authentication and accepts a single client: anyone who can reach its port can read and write tensor memory on that machine. Today the only safe setup is a trusted VPN. This PR keepsggml-rpc-serverbound to127.0.0.1on every worker and puts a paired, encrypted link in front of it, so a home cluster is safe on an ordinary LAN.How it works
unsloth cluster pairprints a one-time token (default 10 min). On the worker,unsloth cluster joinand paste the token at the hidden prompt (or pipe it to--token-stdin). The token is never part of a command line, where other local users could read it.unsloth workerruns the agent: mutual TLS 1.3 on port 50070, and a supervisedggml-rpc-serveron loopback. A connection is accepted only if its certificate chains to the cluster CA AND its fingerprint, node id and role match the registry.cluster.json, then paired workers). For each worker, Studio opens a loopback relay and handsllama-serverthe relay's127.0.0.1endpoint, so llama.cpp itself is unchanged.Other commands:
unsloth cluster list(status of each worker, falling back to discovery for one that moved),discover,remove <worker>(tombstoned; an open session is cut within seconds),leave(a worker leaves; a master with no workers is reset).cluster join --portrecords the portunsloth workerwill serve on.Native TLS path (no relay)
When the llama.cpp bundle on both ends carries ggml-rpc's own mutual TLS 1.3 transport (
ggml-rpc-server --tls-cert/--tls-key/--tls-ca/--tls-allow, client endpointtls://<server sha256>@host:port; the llama.cpp change is unslothai/llama.cpp#309, a pin candidate), Studio skips the relay:GGML_RPC_TLS_*environment variables, never argv.UNSLOTH_CLUSTER_NATIVE_TLS=0falls back to the relay; nothing ever falls back to plaintext.unsloth worker --native-portpicks the TLS port (default 50053).Details worth knowing
GGML_RPC_NO_RDMA=1is set on both ends of a secure link, so RPC cannot negotiate RDMA around the TLS relay.ggml-rpc-serveritself; a second client gets an immediate "busy" instead of hanging.ggml-rpc-servergoes with it:PR_SET_PDEATHSIGon Linux, and on macOS and Windows the next agent stops one left behind (pid plus creation time, so a reused pid is never touched).<studio>/cluster), keys are written 0600 atomically, the peer registry is file locked.ggml-rpc-server, so CUDA and ROCm builds find their runtime.Testing
tests/studio/test_cluster_link_pairing.py,_relay.py,_discovery.py: token round trip, transcript binding, wrong pin, wrong secret, expiry, replay, two concurrent joins with one token, revoked worker, CA signed but unregistered certificate, worker certificate used as master, truststore injected processes, malformed and oversized frames, byte exact relay in both directions with fragmented writes, backpressure, abrupt disconnects, busy refusal, killed agent takes its rpc-server with it.tests/studio/test_cluster_link_e2e.py(needsUNSLOTH_TEST_LLAMA_BIN_DIRandUNSLOTH_TEST_TINY_GGUF): a master and two paired workers with separate state directories, realllama-serverandggml-rpc-server, a forced two worker layer split through the relays. Greedy output is identical to the same split over direct RPC; an unpaired client gets nothing; the rpc-server port is not reachable from a non loopback address.studio/backend/tests/test_cluster_link_serving.py: paired workers in node selection, removal, spoofed announcements, failed status, relay cleanup.unsloth_cli/tests/test_cluster_cli.py: the CLI wiring and its error messages.Per token cost vs direct RPC (Qwen3-1.7B Q4_K_M, two workers on one VM so only the link differs, 3 alternating rounds per arm, greedy text identical to direct in every arm; direct vs direct repeats within about 1%):
UNSLOTH_CLUSTER_LINK_THREADED_SPLICE=1)TLS itself costs about 11 us per RPC round trip (C OpenSSL, 52 KB out / 16 KB back); the relay's cost is the extra hop through Python's TLS stack, which the native transport removes.
Tried
A script drives the real
unslothCLI the way a user would, on a master and two workers with separate state:cluster pair,cluster join,unsloth worker(worker B on a different port than it paired with, so only LAN discovery can find it),cluster listanddiscover, then Studio's own load planner,llama-serverthrough the relays, the same split over direct RPC, a client without a certificate, andcluster remove. All 16 steps pass:On the GPU runs Studio planned a 0.5 / 0.5 layer split over the two relays from the workers' own
--list-devices(both T4s, resp. the L4, reported through the link). These run on one host over loopback.Two physical machines on one gigabit LAN (CPU builds): master and worker on separate boxes, 14 of 14 steps pass: pair, join on the worker box, discovery over real LAN multicast (also after the worker moved to another port), Studio planning onto the remote worker, serving through the link with greedy text identical to direct RPC, a client without a cluster certificate refused, and
cluster removecutting a live session within seconds.A second LAN run (20 of 20 steps) adds the native path (TLS build on both boxes) and timing, 3 rounds of 3 generations per arm, median ms per token: relay 11.37, relay with the llama.cpp write coalescing 12.29, native TLS 11.56; the whole model on the master box alone is 4.84. Greedy text is identical on every arm. On this LAN the network dominates, so relay and native are within noise of each other. Native also passes its checks there: Studio plans
tls://endpoints, a TLS client with a certificate the cluster never issued gets no device from the worker's TLS port while the master's own certificate does, andcluster removecuts a live native session. A plaintext direct RPC run across the LAN was not done (that would expose an unauthenticated rpc-server on the lab network), so the LAN ratio against direct RPC is not measured; on one host it is 1.077x (G4) and 1.093x (T4) above.Cross platform CI (unit tests, real counts): Linux, macOS on Apple Silicon and Windows all pass the cluster link, cluster serving and CLI suites.
Not covered here
Local users on a multi-user machine: on Linux the master's loopback relay serves only clients owned by the same user (checked in /proc/net/tcp); on macOS and Windows it relies on the loopback bind alone. On a worker in relay mode, the loopback rpc-server has no authentication of its own, so another local account on that worker could reach it; native TLS mode does not have this gap.
A Studio UI for pairing (CLI only for now).
Model prefetch on workers to cut the bytes sent at load time.
Screenshots
Pairing a worker, end to end
Real runs on one host: the master is a Studio install of this PR, the worker a second identity with its own state directory, named
living-room-pc. The one-time token is replaced withxin the image (same length).Before this PR there is no
clustercommand:On the master,
unsloth cluster pairprints a one-time token and waits for the worker:On the worker,
unsloth cluster joinasks for the token at a hidden prompt (it is never on the command line), thenunsloth workerserves;ggml-rpc-serverstays on 127.0.0.1:Back on the master,
unsloth cluster listshows the worker as ready:Studio then splits a model across the paired worker and names it while loading and once loaded:
With the worker stopped, a load says which paired worker was left out and how to bring it back:
The same notice when the worker is stopped in the middle of a session, after a split load and a reload:
unsloth cluster removeunpairs it:Same split, before and after this PR
Studio's chat page, BEFORE this PR (
6e46fdd1c, the #13726 head this PR is based on) and AFTER (this PR:d7c36804efor the first three,c25543521for the lost-connection pair). Both sides are separateinstall.sh --localbuilds loading the same model the same way: Qwen3-0.6B Q4_K_M, layer split onto one CPUrpc-serveron the same host through the #13726 node list (UNSLOTH_CLUSTER_NODES,UNSLOTH_CLUSTER_TOPOLOGY=layer_split). That worker comes from the node list, so it is named by its address; a worker paired withunsloth cluster pairis shown by its name.While the model server starts: BEFORE says it is loading a cached model into memory, AFTER says the server is starting split across the worker.
While the layers go to the worker: BEFORE shows a byte counter and an ETA with nothing about the split, AFTER says the layers are being sent to the worker and warmed up.
Loaded toast: AFTER adds which machines the model is split across.
The worker is stopped mid-chat: BEFORE says the model server may have crashed, AFTER names the machines the model was split across and what to check.
Not shown: the "Model loaded with a warning" notice for a paired worker that cannot be reached (it applies only to workers paired with
unsloth cluster pair) and the refusal for a model too big for the cluster; both are covered bystudio/backend/tests/test_cluster_ux.py.