Repository navigation
Studio: serve one GGUF across N machines over llama.cpp RPC - #18277
danielhanchen wants to merge 9 commits into
Conversation
cluster_serving plans a layer split over the ggml-rpc-server workers listed in UNSLOTH_CLUSTER_NODES or cluster.json: it lists each worker's devices through the llama-server that will launch, sizes the KV cache and largest layer from the GGUF header, weights --tensor-split by usable free memory, adds --pipeline-groups when the bundle has it, starts managed workers over ssh and refuses a load no set of devices can hold. rpc_serving holds the load hooks the inference routes call and the helpers the planner shares (binary resolution and capability probes, GGUF and KV sizing, launch files, ssh and peer processes). The status stays at GET /api/inference/spark/status, the toggle at UNSLOTH_SPARK_SERVING and the field at spark_topology, so an optional serving provider can take the hooks over without changing 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: 1f335ceb4a
ℹ️ 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 ( | ||
| str(getattr(request, "gguf_variant", "") or "").strip().lower() | ||
| != str(source[1] or "").strip().lower() | ||
| ): | ||
| return None |
There was a problem hiding this comment.
Resolve model identity before deciding which extras to inherit
When a same-model reload omits a previously explicit gguf_variant, or names the Hub repo instead of its snapshot directory, this helper rejects inheritance even if the resolved GGUF is unchanged. If the planner then chooses a layer split, it populates request.llama_extra_args with its new block, causing _resolve_inherited_extra_args to return early instead of performing its existing canonical-model/resolved-variant comparison. Consequently, previously supplied context, RoPE, or chat-template arguments silently disappear on these reloads. Resolve the identity consistently with the existing inheritance helper before materializing the planned extras.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 29733d9: the planner now also inherits when the request resolves to the same cached GGUF file as the stored extras (repo id vs snapshot path, or an omitted variant that resolves to the same quant), with the canonical model identity checked first so two files sharing a stem stay distinct. It runs off the event loop. Covered by test_split_extras_follow_the_same_gguf_whatever_the_reload_names_it.
| tail = tokens[end:] | ||
| if not tail or (len(tail) == 2 and tail[0] == PIPELINE_GROUPS_FLAG): | ||
| return tokens[:start] |
There was a problem hiding this comment.
Strip only split blocks known to have been generated by Studio
This fallback removes a caller-authored two-device RPC configuration solely because its arguments match the hard-coded shape, without requiring any recorded managed block. For example, with _MANAGED_BLOCKS empty, --rpc 10.0.0.2:50052 --device RPC0,CUDA0 -sm layer --tensor-split 0.5,0.5 --cache-ram 0 is reduced to an empty list. Since _resolve_inherited_extra_args now invokes this stripping even when cluster serving was never configured, a subsequent same-model reload that omits extras silently loses the user's remote placement and may no longer fit locally. Require provenance rather than treating this argument pattern as necessarily Studio-owned.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 29733d9: strip_layer_split_extra_args strips only blocks the cluster recorded; the fixed two-node shape is no longer assumed to be Studio's here (two-Spark serving, which does append that block, strips its own as the provider). Covered by test_a_callers_own_rpc_placement_is_never_read_as_ours.
…ed split blocks The planner decided which extras a reload inherits by comparing the typed model path and variant, so a reload naming the repo instead of its snapshot, or dropping a variant it sent before, planned without them; its split block then made the route skip its own inheritance and the user's context and RoPE arguments disappeared. It now also accepts a request that resolves to the same cached GGUF file, decided off the event loop. strip_layer_split_extra_args removed any argument list shaped like a two-node split even when Studio never added it. Only blocks the cluster recorded are stripped now; an installed provider may strip its own.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 590b115a82
ℹ️ 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 not _split_extras_share_a_source(request, source, resolved): | ||
| return None | ||
| # Our own split block, shadow-stripped as the route would, so it is never read as a caller --rpc. | ||
| return drop_managed_flags(_shadow_stripped_inherited(request, stored))[0] |
There was a problem hiding this comment.
Resolve the effective template before stripping inherited extras
When a same-model Gemma-4 reload omits both llama_extra_args and chat_template_override, this call retains a previously supplied --chat-template-file because it does not pass the effective bundled template to _shadow_stripped_inherited. If the planner chooses a layer split, it materializes those inherited arguments into request.llama_extra_args, so _resolve_inherited_extra_args subsequently returns early and never performs its existing template stripping. The stale extra then overrides the bundled template at launch, changing prompt formatting and potentially breaking thinking/tool behavior. Resolve and pass the effective template before materializing the inherited extras, or preserve the later inheritance normalization.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 981d700: _split_inherited_extra_args now resolves the effective chat template (the user override, else the bundled gemma-4 template) and passes it to _shadow_stripped_inherited, so the planner's inherited extras are stripped exactly as the route would strip them, including the stale --chat-template-file. Covered by test_split_extras_drop_a_template_file_the_bundled_gemma4_template_replaces, which fails on the previous head.
The planner's inherited extras replace the route's own inheritance, so they must be stripped the same way. Without the effective template, a gemma-4 reload kept a stale --chat-template-file that then overrode the bundled template at launch.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 981d700079
ℹ️ 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".
| f"a micro-batch of {min(batch, ubatch)} is placed by the caller", | ||
| ) | ||
| return request | ||
| model_bytes, kv_bytes, local_extra = await self._size(request, n_parallel, flags, ss) |
There was a problem hiding this comment.
Size the split using the effective parallel-slot count
When a hybrid/recurrent GGUF load supplies a larger slot count through llama_extra_args than through request.n_parallel or the app default, _size still receives only the latter count. It consequently underestimates per-sequence recurrent state, checkpoints, and slot-dependent compute buffers, while the larger override survives into the launch. The planner can therefore approve a split that runs out of memory during loading. Resolve the effective slot count before sizing, or decline automatic placement when the override differs, as the existing local placement paths do with _extra_args_n_parallel.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c17d788: the planner reads the slot count that will launch (an extras -np/--parallel, inline or not, else LLAMA_ARG_N_PARALLEL) with the same _extra_args_n_parallel the local placement uses, and sizes recurrent state, checkpoints and compute for it. Covered by test_the_split_is_sized_for_the_slot_count_that_launches (3 of its 4 cases fail on the previous head).
An extras --parallel or LLAMA_ARG_N_PARALLEL wins at launch, but the planner priced recurrent state, checkpoints and slot-dependent compute for request.n_parallel, so it could approve a split that ran out of memory while loading. It now sizes with the caller's count when one is set.
|
@codex review |
|
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". |
|
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. Already looking forward to the next diff. 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 #18276 (ships
ggml-rpc-serverwith the llama.cpp bundle). Refs #4858.This replaces #13726. That PR sat on top of the DGX Spark toolkit (#10280) and two-Spark serving (#10323), about 30k lines that multi-machine serving does not use. Here the same N-node serving depends only on #18276. The two Spark PRs become optional and stack on top of this one.
What this does
Studio can split a GGUF that does not fit one machine across any number of machines through llama.cpp RPC: Macs over Metal, Linux boxes with NVIDIA or AMD GPUs, DGX Sparks, or a mix. This machine runs
llama-server, and every other machine runsggml-rpc-serverand holds a share of the layers.It is opt-in. Nothing changes until the operator lists workers in
UNSLOTH_CLUSTER_NODESor<studio home>/cluster.json.UNSLOTH_SPARK_SERVING=0turns it off.On a load,
core/inference/cluster_serving.py:llama-server --rpc ... --list-devicesto read each worker's devices and free memory.--rpclists the workers that exposed a device;--device RPC0,...,RPCk,<local GPU>keeps the local device last, so the output layer stays here;--tensor-splitweights each device by its usable free memory.llama-serverhas--pipeline-groups(server: --pipeline-groups, run the slots over several contexts of one model llama.cpp#187), the split gets pipeline groups sized to the slots.Nodes marked
managedgetggml-rpc-serverstarted over non-interactive ssh. A reload strips exactly the block this module appended, so inherited extras are planned afresh. The owner-onlyGET /api/inference/spark/statusreports the nodes, the devices, the plan and the exact arguments.User guide:
studio/MULTI_NODE_SERVING.md.Code layout
core/inference/rpc_serving.pyholds two things:before_load,after_load,load_failed,reconcile_internal_load,status,current_topologyandshutdown.llama-server --help, GGUF and KV sizing, sidecar and launch files, and the ssh and peer process.spark_serving.pyunchanged. The only difference is that the RPC binary falls back tostudio/llama_rpc.pyfrom Studio: ship ggml-rpc-server with the llama.cpp bundle and locate it #18276, not the Spark toolkit.spark_topologyin the status response, the/api/inference/spark/statuspath and theUNSLOTH_SPARK_SERVINGtoggle keep their names, so stacking Studio: two-Spark serving orchestrator with an async replica router #10323 on top changes no field or route.llama_cppreadsrequested_identifier/requested_variantandlaunched_env, and keeps--parallela multiple of--pipeline-groups.loggers/structlogin three backend tests now declare__path__, so they no longer shadow the real packages when the directory runs as a whole.Tests
test_cluster_serving.py(220 tests): config, device listing, placement, launch arguments, pipeline groups, reload stripping, managed workers, refusal, and that nothing runs without a cluster config.test_rpc_serving.py:test_cluster_serving_e2e.py(withUNSLOTH_TEST_RPC_BINandUNSLOTH_TEST_GGUF): three realggml-rpc-serverworkers on loopback, the planner's own probe, a realllama-server, and every worker logs a model buffer. It passes on this branch with no Spark code in the tree...._keeps_the_spark_one,..._spark_toggle_...) or moved (intotest_rpc_serving.py, plustest_cluster_spark_handoff.pyon Studio: two-Spark serving orchestrator with an async replica router #10323).test_ssh_user_defers_to_the_cluster_module, covered a delegation to an identical function in the toolkit.Evidence (measured on #13726; the planner code is unchanged)
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--device RPC0,RPC1,RPC2,CUDA0tests/test_cluster_serving_e2e.pyrepeats the loopback run as a test whenUNSLOTH_TEST_RPC_BINandUNSLOTH_TEST_GGUFare set (skipped otherwise): 3 workers, the planner's own probe, a real llama-server, and a check that each worker logged a model buffer.Not in this PR
ggml-rpc-serverhas no authentication, and the guide says to bind it to a trusted private network.