Repository navigation
Studio cluster: pair machines on a home network, RPC over mutual TLS - #18278
danielhanchen wants to merge 11 commits into
Conversation
unsloth cluster pair on the master prints a one-time code; unsloth worker --join on another machine enrols it. Pairing issues each worker a certificate from a cluster CA kept on the master, and every connection after that is mutual TLS with pinned certificates: the native TLS transport when the bundle's ggml-rpc-server has it, an authenticated relay otherwise. Paired workers join splits without a cluster.json, and cluster list / remove manage them.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34e92fba5f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| if thing is not None: | ||
| thing.stop() |
There was a problem hiding this comment.
Close native sessions before discarding the relay manager
If the master identity is reset while native-session revocation is still pending—for example, removing the workers and then running unsloth cluster leave --yes—the next status refresh reaches this cleanup through _relays_locked(). However, RelayManager.stop() only closes relay connections and cancels its tasks, including the native revocation watches; it never sends native_close. The native RPC connection bypasses those relays, and the worker still trusts the old master in its own registry, so the removed worker's live session can continue indefinitely. Close the tracked native sessions before stopping their manager, or preserve their revocation tasks until closure succeeds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 34e92fb: RelayManager.stop() now sends native_close to every node with a live native session (tracked by its revocation watch) before cancelling the watches and removing the relays, best effort with a 3 s timeout each. Covered by test_stopping_the_relays_closes_a_live_native_session, which fails on the previous relay.py.
There was a problem hiding this comment.
Correction: the fix commit is 19bd7e3 (the hash in my previous reply was the PR's earlier head).
Studio drops its relay manager when the master identity changes, for example cluster leave right after cluster remove. That cancelled the revocation watch before it sent native_close, and a native RPC session bypasses the relays, so the removed worker kept serving it. stop() now closes every tracked native session (best effort, 3 s each) before tearing the relays down.
# Conflicts: # studio/backend/tests/test_rpc_serving.py
|
@codex review |
# Conflicts: # studio/backend/tests/test_rpc_serving.py
|
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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 |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ded54c9b0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| transport = "native_tls" if native_port else "link", | ||
| relay = endpoint, | ||
| name = getattr(peer, "name", None), | ||
| native_port = native_port or 0, | ||
| tls_fp = str(peer.fingerprint).lower() if native_port else None, |
There was a problem hiding this comment.
Fall back to the relay when the native port is unreachable
If the worker's agent port is reachable but its separate native RPC port is blocked by a firewall, native_ok still succeeds because the worker only checks that RPC accepts connections locally. This code then selects the native endpoint unconditionally. _reachable() checks only the agent, and _place() drops the worker after the native device probe fails without retrying its working mTLS relay. Consequently, automatic native negotiation excludes an otherwise usable worker and can prevent models from loading. Verify the native connection before selecting it, or retry through the relay when the native probe fails.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a2f732c. After native_ok, the master now opens a TCP connection to the worker's TLS port from this machine (_native_port_open, REACH_TIMEOUT_S). If it cannot connect, it sends native_close and keeps the worker on its mTLS relay. A worker behind a firewall that only allows the agent port is therefore still planned. The new tls_port_firewalled case of test_native_tls_falls_back_to_the_relay_never_plaintext and a real-socket test cover this. On the tailcat PR the direct dial is skipped for tunnelled workers, because the forward is the check there.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
…ve session intact
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
Stacked on #18277 (n-node serving). This replaces #14274, rebuilt on the Spark-free stack (#18276, #18277) with the same content. 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 the original #14274 was 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.