Skip to content

Studio: serve one GGUF across N machines over llama.cpp RPC - #13726

Closed
danielhanchen wants to merge 120 commits into
spark/serving-orchestratorfrom
cluster/n-node-serving
Closed

danielhanchen wants to merge 120 commits into
spark/serving-orchestratorfrom
cluster/n-node-serving

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Stacked on #10323 (base spark/serving-orchestrator). Refs #4858.

#10323 serves one GGUF across exactly two paired DGX Sparks: one peer address, --device RPC0,CUDA0, a fixed 0.5,0.5 split, and router slots main / peer. llama.cpp RPC itself takes any number of workers, so this PR lets Studio split a GGUF over N machines of any kind (more Sparks, Macs over Metal, Linux boxes with NVIDIA or AMD GPUs, or a mix), while the two-Spark path stays exactly as it is.

How it works

Opt-in only. Nothing changes until the operator lists workers in UNSLOTH_CLUSTER_NODES or <studio home>/cluster.json; with neither, every Spark code path runs unchanged. UNSLOTH_SPARK_SERVING=0 still turns both off.

On a load the new core/inference/cluster_serving.py:

  1. Checks which workers answer (TCP probe; one dead endpoint otherwise aborts llama.cpp's whole device listing), then runs the coordinator's own llama-server --rpc ... --list-devices to read each worker's devices and free memory.
  2. Serves locally when the model plus KV cache fits this machine.
  3. Otherwise splits by layer: --rpc lists the workers that exposed a device, --device RPC0,...,RPCk,<local GPU> keeps the local device last so the output layer stays here, and --tensor-split weights each device by its usable free memory (free minus max(1 GiB, 8%), plus a 5% layer-rounding margin). Projectors, drafters and adapters are charged to the coordinator, which loads them.
  4. Refuses a load that no set of devices can hold, with the numbers, instead of failing mid-load.

Nodes marked managed get ggml-rpc-server started over non-interactive ssh with the same PeerProcess machinery the Spark peer uses (POSIX kill -0 only, so it works on macOS too). A reload strips exactly the block this module appended, so inherited extras are planned afresh. The owner-only status route reports nodes, devices, plan and the exact args.

spark_serving.py changes are dispatch only (43 lines): when a cluster is configured the module-level before_load / after_load / load_failed / shutdown / status delegate to the cluster; ssh_argv accepts user@host nodes; strip_layer_split_extra_args also removes the cluster's own block. The SparkServing class, the split args, router names and status keys are untouched.

User guide: studio/MULTI_NODE_SERVING.md.

Two Sparks do not break

  • test_spark_legacy_golden.py was recorded on Studio: two-Spark serving orchestrator with an async replica router #10323's head before any change (first commit) and freezes every launch argv, remote command, router backend and status payload for layer split (with and without pipeline groups, with inherited extras), single, replicas before and after load, and the disabled state. It passes unchanged after the change.
  • test_spark_serving.py, test_spark_router.py, tests/studio/*spark* and unsloth_cli/tests/test_spark_offbox.py pass with zero edits (git diff on them is empty).
  • Unit tests assert that with no cluster config the legacy objects and outputs are returned, and that the toggle turns the cluster off.

Evidence

Run Args Studio produced Result
CPU, 4 rpc-servers on loopback, through before_load --rpc 127.0.0.1:51060,...,51063 --device RPC0,RPC1,RPC2,RPC3 -sm layer --tensor-split 0.25,0.25,0.25,0.25 --cache-ram 0 every worker got a model buffer (28.28 / 28.28 / 28.28 / 186.97 MiB); completion " Paris, and the capital of the United"
CUDA, 3 GPU rpc-servers + CUDA coordinator, Qwen3-8B Q4_K_M --device RPC0,RPC1,RPC2,CUDA0 37/37 layers offloaded; CUDA0 1395.57 MiB, RPC 1115.76 / 972.01 / 972.01 MiB; completion " Paris, and the capital of Germany is"
One worker down unreachable endpoint left out and named in status split over the remaining workers, load succeeded

tests/test_cluster_serving_e2e.py repeats the loopback run as a test when UNSLOTH_TEST_RPC_BIN and UNSLOTH_TEST_GGUF are set (skipped otherwise): 3 workers, the planner's own probe, a real llama-server, and a check that each worker logged a model buffer.

Suites: test_cluster_serving.py (34), goldens, test_spark_serving.py, test_spark_router.py: 217 passed, 18 skipped. tests/studio/*spark* + test_spark_offbox.py + test_source_read_encoding.py: 370 passed. Security lints (lint_av_shapes, lint_exec_literals, lint_risky_loaders) clean.

Not in this PR

  • Copies of the model on several machines (replicas) stay two-Spark only; N replicas and mixed replica/split layouts are follow-ups.
  • No LAN discovery and no settings page yet: workers are configured by env or cluster.json.
  • ggml-rpc-server has no authentication; the guide says to bind it to a trusted private network.
  • A real multi-Mac run has not been done; macOS coverage is the unit suite on staging.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T12:54:56.829985Z c247109 Manual request
🔒 Security Review ✅ Completed 2026-10-14T13:30:20.185745Z 974ba7f Manual request

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 974ba7fd74

ℹ️ 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".

Comment on lines +154 to +156
port = entry.get("rpc_port", node.rpc_port)
if not isinstance(port, int) or not (0 < port < 65536):
raise ClusterConfigError(f"not a port: {entry!r}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject boolean RPC ports in JSON configuration

JSON true and false deserialize to Python booleans, which are instances of int, so a configuration such as {"rpc_port": true} passes this validation. It subsequently produces an endpoint like host:True for llama.cpp while socket probing treats the value as port 1, yielding confusing reachability and launch failures instead of the intended configuration error; require an actual integer type and explicitly exclude booleans.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: a boolean port is a malformed config, and llama.cpp and the reachability probe already fail on it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 974ba7fd74

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment on lines +398 to +402
process = ss.PeerProcess(
"ggml-rpc-server",
node.ssh_target,
argv,
log_dir / f"rpc-server-{node.host}-{node.rpc_port}.log" if log_dir else None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

P2 Badge Security: Bound managed-worker log growth

When cluster serving is enabled with a managed node, an attacker controlling or successfully impersonating that SSH endpoint can stream stdout indefinitely. This call gives PeerProcess a persistent coordinator-side log path; _drain_output() then appends and flushes every remote line without rotation, a byte limit, or rate limiting, while only the in-memory tail is bounded. The long-lived worker can therefore fill the coordinator's disk and disrupt Studio or colocated services. Use capped/rotating logs and terminate or throttle workers that exceed the budget.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: this needs a managed node the operator listed and reaches over their own ssh keys to turn hostile, which already has far more than disk to work with; it is the same PeerProcess logging the two-Spark peer has always used.

…laced model, keep live workers, match endpoints whole, honour cancel
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…oads, one projector from env, reserve KV for uncached models, retire workers when the config goes
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b264dc11ba

ℹ️ 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".

Comment on lines +571 to +573
if not any(str(a).split("=", 1)[0] in named for a in extras) and not any(
os.environ.get(k) for k in ("LLAMA_ARG_MMPROJ", "LLAMA_ARG_MMPROJ_URL")
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Account for projectors downloaded from URLs

When --mmproj-url or LLAMA_ARG_MMPROJ_URL is used, this condition suppresses sizing the automatically discovered projector, but neither sidecar_bytes() nor env_launch_files() can size the URL that llama.cpp downloads and loads. Fresh evidence after the environment-sidecar fix is that env_launch_files() deliberately returns only existing local paths, so the effective remote projector still contributes zero bytes; a near-capacity split can then OOM on projector load. Resolve the download size or conservatively avoid managed placement when it is unknown.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: a projector given only by URL is a rare setup, and llama.cpp reports an out-of-memory load clearly; sizing a download before it exists is out of scope here.

Comment on lines +594 to +596
ctx, cache_type, cache_type_v = ss.effective_kv_settings(request, extras)
kv = 0.0
if local_file and ctx:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Budget KV memory when context is automatic

Fresh evidence after the uncached-model KV fix is that LoadRequest.max_seq_length defaults to 0 and explicitly defines that value as asking llama.cpp to select a context, not as requesting a zero-length context. Here that common default leaves ctx false and therefore records zero KV bytes even for a cached GGUF whose native context is available in its header; a weights-only plan near capacity can then OOM when llama.cpp allocates the automatically selected nonzero cache. Resolve the native/fitted context before planning or conservatively reserve KV when the context is automatic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: with no context given llama.cpp fits the unset context to the free memory of the chosen devices (--fit, on by default in this build, minimum 4096), so no fixed KV is allocated beyond what fits.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
SparkServing.status() reports split_reload_pending; the frozen two-Spark
status payloads were recorded before it existed, so the whole-dict
comparison failed. Re-recorded with SPARK_GOLDEN_RECORD=1; the only change
is the new key.
--n-cpu-moe 0 / --n-cpu-ffn 0 place nothing (the loader and the env twins
only act on a positive count), so they no longer bypass cluster planning.
ctx_checkpoints sizes the host checkpoint pool and load_mode=mlock pins the
host copy, so a config-error reload changing either must not be handed the
old split. gpu_memory_mode and tensor_parallel are placement inputs too.
An automatically planned load started every managed rpc-server over ssh
before probing this machine, so a model that fits locally still paid an
ssh timeout per dead host and left unneeded workers running. When workers
would be started and the topology is not forced to layer_split, plan this
machine alone first and start workers only if it does not fit.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: bc2d32a01d

ℹ️ 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".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 6e46fdd1cd

ℹ️ 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".

A master with no accelerator listed no local device, so the planner
split even a small model across the workers. It now serves locally
when the model and its context fit the usable host RAM, as a GPU
master does, and splits only when it does not fit or the split is
forced with UNSLOTH_CLUSTER_TOPOLOGY=layer_split.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: c247109448

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

Superseded by #18277, which has the same changes rebuilt on a stack that no longer needs the DGX Spark PRs: #18276 (ships ggml-rpc-server), then #18277 (N-node serving), #18278 (home pairing) and #18279 (pairing across networks).

#10280 and #10323 stay open as optional Spark extras stacked on top. Closing this one so review continues on #18277; the discussion here stays for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant