Repository navigation
server: --pipeline-groups, run the slots over several contexts of one model - #187
danielhanchen wants to merge 289 commits into
Conversation
…pstream PRs into the prebuilds
Add AGPLv3 SPDX headers to the Unsloth prebuild workflows
Prebuilds: merge a set of upstream PRs into the GitHub Actions builds via `pr-set.json`
The mix-build pin for ggml-org#24423 lagged behind the PR head, so the prebuilds predated the streaming visual server. Bump the pin to the head that carries the visual server (self-tokenizing, on-device entropy-bound decoder) and its fixes, and make the build actually produce and ship it: - scripts/unsloth/pr-set.json: pin ggml-org#24423 at 10a2613 (was c84e85a, 8 commits behind -- before the visual server existed). - CUDA (Linux + Windows) and macOS children: a best-effort step builds llama-diffusion-gemma-visual-server + llama-diffusion-cli after the required server/quantize build. It reconfigures with LLAMA_BUILD_EXAMPLES=ON and builds only those targets, and it can never fail the job: a toolchain that cannot build them still publishes the normal bundle. ROCm already builds all examples and tars the whole bin dir, so it picks them up with no change. - scripts/unsloth/package_bundle.py: ship the two DiffusionGemma binaries when the build produced them (optional, absent in a plain upstream build, so unlike the required binaries their absence is not an error). They join the closure walk; their only local libs (libllama, libggml, libllama-common) are already pulled by llama-server, and they inherit the same $ORIGIN rpath, so the bundle stays self-contained and relocatable. This lets Unsloth Studio serve unsloth/diffusiongemma-26B-A4B-it-GGUF natively from the prebuilt bundle, with no DG_* env or source build.
The -j 2 pin on the CUDA Linux and Windows builds was a conservative hedge against nvcc memory spikes. A 10-run sweep on stock GitHub runners (4 vCPU / 16 GB) over the multi-arch fanout this prebuild compiles shows peak host RSS near 3 GB and zero OOMs, so 3 parallel TUs leave about 13 GB free. -j 3 cuts build time roughly 23 percent (about 70 down to 54 min per job); -j 4 adds no further speed (the runner is about 2 physical cores plus HT). macOS and ROCm already build at full cores and are unchanged. Applies to both the required server/quantize build and the best-effort DiffusionGemma example build in each CUDA child.
…de vs visualization STATS split Picks up the honest per-turn stats: separates model decode time from the per-step visualization overhead and drops the meaningless prompt tok/s, plus VRAM-aware MAXTOK auto-sizing and a toolong budget report. Rebuilds llama-diffusion-gemma-visual-server.
…greater overload The windows-latest image rolled from VS 2022 to VS 2026 (MSVC 14.51), whose STL marks math builtins like isgreater constexpr (implicitly host+device); that collides with clang's HIP __device__ forward declares and breaks the ggml-cuda .cu compile (ggml-org#22570). Pin vswhere -latest to the 17.x line so the build uses the VS 2022 toolset this job already installs, matching the last known-good release.
…M auto-size)
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…at once Slot selection now only considers the least loaded groups that still have a free slot, so below full load requests no longer pile into one group. An idle group wakes as soon as a slot is launched into it instead of on its 5 ms timer, and a group decoding a long prompt lets a waiting task thread in between chunks.
|
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". |
# Conflicts: # tools/server/server-context.cpp
… control handler With --pipeline-groups > 1, wait_for() lets the group finish its in-flight decode, which can finish the request and release the slot; reasoning_end then dereferenced a null slot->task.
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
|
@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". |
Adds
--pipeline-groups Ntollama-server: the slots are run overNindependentllama_contextobjects created from the same model, each with its own batch, its own samplingand its own decode thread. The model weights, the task queue, the results queue and the HTTP
layer are shared. With
N = 1nothing changes.The point is a layer split across two machines. With one context the split is a two-stage
pipeline fed one batch at a time, so each stage is idle while the other computes. With two
groups there are two batches in flight.
Result
Two DGX Sparks (GB10, 111.9 Gb/s per rail), Qwen3.8-27B-UD-Q4_K_XL, layer split over one
ggml-rpc-serveron the peer,-c 16384 --parallel 32 --cache-ram 0 -fa on -ngl 99 -t 6,32 concurrent clients, 64 requests, npp 128 / ntg 256, best of two repeats, all cells inside one
clock state (2386 to 2402 MHz local, 2433 to 2463 MHz peer, no thermal cap markers).
CUDA0,RPC0CUDA0,RPC0CUDA0,RPC0RPC0,CUDA0RPC0,CUDA0RPC0,CUDA0--backend-samplingRPC0,CUDA0--backend-sampling1.32x over one context on the same split, at 76 to 79 percent GPU busy per node against 43 to 47
percent. Two things had to be true at once:
-sm layerthe devices are filled inthe order they are listed, so the last device holds the output layer. List the RPC device
first and the local one last (
--device RPC0,CUDA0): the logits are then produced locally,which removes a
n_vocab * n_rows * 4byte return from every decode step (31.8 MB per step at32 rows on this 248320-token vocabulary) and lets the sampler read them out of local memory.
Slot count sweep,
RPC0,CUDA0,--cache-ram 0,-csized so every slot keeps 512 tokens:What the cost was, and how it was found
LLAMA_SERVER_PIPE_PROF=1(added here) prints, per group and every five seconds, how long aniteration spends waiting for the engine, in
pre_decode, inllama_decode, inllama_synchronizeand inpost_decode, and splitspost_decodeper token into sampling,detokenization, stop-string handling and the result queue. On the pair, per group iteration:
pre_decodellama_decodellama_synchronizepost_decodecommon_sampler_samplecommon_token_to_pieceprocess_token(stop strings, streaming)queue_results.sendSampling one row builds a candidate array over a 248320-token vocabulary, about 4 MB of memory
traffic. With one context that pass runs in the gap where both GPUs are idle and gets the full
memory bandwidth of the node. With two groups it runs against the other group's GPU work on the
same LPDDR5X and costs six to seven times more per row, while sitting on each group's critical
path between the synchronize and the next submit. Every other candidate was measured and
falsified: the results queue and the task queue are three orders of magnitude too small, and the
engine lock was never contended (0.00 ms in every window; forcing the old single shared host lock
back on with an A/B switch gave 74.7 against 73.5 to 75.3 tok/s).
Changes
--pipeline-groups N, parsed intools/serverbecause it only means anything for the server.Slots are partitioned contiguously; each context gets
n_ctx / Nandn_seq_max = P / N, sothe per-slot context and the total KV over all groups are what the user asked for. Slot
selection still runs over all slots, so prompt-cache similarity and the slot save / restore
endpoints behave exactly as before.
N > 1is refused together with speculative decoding,multimodal, control vectors and
--sleep-idle.own row of the logits), so the tokens are the ones the serial pass would have produced. The
thread budget is divided by the number of groups, so a pipeline-groups run is not simply given
more CPU than the single-context run.
LLAMA_SERVER_SAMPLE_THREADS=1turns it off.is worth nothing on its own on this hardware and is reported as such, but it is what the
feature is supposed to guarantee.
group. This is what fixed TTFT (29 s to 7 s at 32 concurrent).
get_available_slot()calledprompt_save/prompt_load, which read and write the slot'ssequence KV, before the guard waited for the owning group's decode to finish. With
--cache-ram 0the cache is null so it never fired; with the cache on it is a live raceagainst a running decode and it matches the 29 s TTFT and the abort seen while developing this.
The cache update now happens after the wait.
server_metricsis no longer written from several group threads at once, and each group countsits own slots instead of every slot of the server (which double counted
n_busy_slots).shared by every backend of that endpoint, and a message was three unlocked writes, so two
contexts interleaved their command streams and
--pipeline-groups 2aborted with "Remote RPCserver crashed or returned malformed response" within seconds. Responses are handed out in
request order by a ticket, so a waiter does not hold the send lock.
last_graph_uidmoved tothe connection and is checked under that lock, which closes a hazard where GRAPH_RECOMPUTE
could re-run the other context's graph.
Correctness
Per-group speculative decoding (the section below), on top of the proofs already listed here:
base,
--pipeline-groups 1and--pipeline-groups 2on this branch, md5e154ffeace8e6d57298e1963f16529b5for all three.--parallel 8: groups 1 and groups 2 give the same sequential greedymd5 with MTP (
4dae418e8227bddb0fc0e93ab11a9e67) and the same without it(
43e68a9c6ffafce623dd8089192cdfc3); all eight slots of both groups serve requests and/metricsreports drafted and accepted tokens in both MTP arms.tools/server/tests/unit/test_speculative.py(--model-draftsidecar, context shift,context-not-exceeded, parallel requests): 6 passed with one group, 6 passed with two.
test_basic.py,test_completion.py,test_ctx_shift.py,test_slot_save.py: 59 passed,1 skipped, 1 failed in both arms, the failure being a preset whose model is not in the offline
cache. Slot save / restore and context shift therefore also run over two groups.
N = 1,N = 2andN = 4over a CPU-only two-RPC split,five prompts, md5
177dc61e0703eba3bdaf7bf1131f0458, same as the unmodified binary.tools/server/testsrun serially against this build and against the unmodified branch head onthe same machine: 325 passed, 233 failed, 6 skipped, 9 errors on both, with byte-identical
failure name sets. The failures are pre-existing in that environment (the cached test models do
not match), not introduced here.
--pipeline-groups 2with the sampling pool on and off gives the same test results.Speculative decoding per group
--pipeline-groups Nnow combines with speculative decoding (--spec-type draft-mtpwith the MTPhead inside the GGUF, and
--model-draftwith a sidecar draft model). Each group owns its ownspeculative state:
llama_context, created bycommon_speculative_init_from_paramsagainst thegroup's target context, so
ctx_otherand the next-token embedding hooks point at that context;common_speculative, sized for the group'sP/Nsequences and addressed by the slot'ssequence id inside the group (
slot.seq_id, which isslot.idwith one group);llama_decodealready does; the two task-queue yields around the drafter are only taken on thesingle-group main-thread path.
Slot save / restore, context checkpoints (the drafter state is stored and restored with the
checkpoint) and the prompt cache behave as before, per slot. With
N = 1the code path is the sameas before, spelled through
groups[0]. With--model-draftthe sidecar model is loaded once pergroup.
validate_pipeline_groupsno longer refuses drafters;--mmproj,--control-vectorand--sleep-idle-secondsare still refused withN > 1.Two DGX Sparks, Qwen3.8-27B-UD-Q4_K_XL, layer split over one
ggml-rpc-serveron the peer(
--rpc peer:50055 --device RPC0,CUDA0 -sm layer),-c 16384 --parallel 32 --cache-ram 0 -fa on -ngl 99 -t 6, real-text prompts, npp 128 / ntg 256, 2 requests per client. MTP is--spec-type draft-mtp --spec-draft-n-max 3off the head inside the GGUF. Two passes with the armorder reversed, because the SM clock decays through a window; the cells below all ran with both
GPUs at 2390 to 2400 MHz and no cap marker (the three cells that were capped or straddled a cap
stage are listed after the table, and each of them has a clean repeat).
At 32 users the combination is the best cell measured: 1.38x over one context without speculation,
1.17x over one context with MTP and 1.16x over two groups without it. At 8 users it is not: one
context with MTP is faster (95.5 against 77.1), because two groups halve the rows per group and the
draft head is at its most valuable when the batch is small and the step is memory bound. The
crossover is between 8 and 32 rows, which is the same crossover the
--pipeline-groupsresultitself has.
Cells with a clock caveat, each superseded by the clean repeat in the table: one group without MTP
in the first pass ran at 1828 MHz (53.6 / 95.5), two groups without MTP in the reversed pass at
1690 MHz (51.5 / 108.7), two groups with MTP in the reversed pass straddled a cap stage
(92.0 / 128.3). Every 32-user cell in every arm, including the two without speculation, had one
request of 64 return no tokens; it is present in the arms this PR does not touch, so it is not a
property of per-group speculation.
Known limits
--cache-ram 0with a layer split. The RAM prompt cache moves a whole slot state onevery slot handover, and on a split most of that state lives on the remote node, so it crosses
the wire. At 32 concurrent clients on the pair, with the cache at its default: one group 75.9
tok/s and 33 s median TTFT (against 99.7 and 7.5 with
--cache-ram 0); two groups 6.9 tok/swith 14 of 64 requests timing out, because the handover runs on the single task thread and the
other group starves while it does. This is a property of the cache on a split, and one group is
already badly hurt by it, but two groups make it much worse and it is not fixed here.
HTTP response; the server log records no error, so the truncation is on the HTTP path at 256
concurrent streams, and the node crossed 80 C during that cell. That row is reported with its
error count and is not a clean measurement. 32, 64 and 128 slots are clean.
Update 2026-09-07: the flag is worth a good deal more than the figures above
The best number in this description is 1.38x at 32 users with two groups and MTP. That was measured before three launch settings were understood, and with all three the same mechanism reaches 1.77x: 209.5 tok/s against 118.6 for one context on the same split. Qwen3.8-27B UD-Q4_K_XL, two nodes,
--device RPC0,CUDA0 -sm layer, both GPUs pinned at 1690 MHz.What the earlier cells were missing:
--kv-unified. Worth 23 to 30 percent at 32 rows on a two group arm and nothing at all on one context, so it never showed up in a single context comparison.--tensor-split 0.5,0.5. Without it llama.cpp splits by free memory at load time, so the layer boundary moves between runs and two cells are not comparable. Five boundaries were measured and the even one wins.Two other things worth recording for anyone reading the numbers above. Speculation does not compose with this at high concurrency:
--spec-draft-n-max 3is the worst of the three depths at every row count on a split, and above 64 rows speculation of any depth loses (212.72 tok/s off against 164.06 at n=1 and 132.24 at n=3 at 128 rows). Acceptance is a property of the depth rather than the rows, 0.87 / 0.78 / 0.69 at depths 1 / 2 / 3, so a deeper draft accepts strictly more tokens per step and still loses throughput. And more groups is not better: four groups is 10.3 percent slower than two and three groups 11.0 percent slower, because the bottleneck GPU is already 91.55 percent busy on CUDA event accounting at two groups and what is left is scheduling inside prompt batches, not idle waiting for a neighbour.Cost, stated honestly: at 128 rows the TTFT of a saturating burst is 18.1 s median and 27.2 s p99, against 4.6 and 5.6 at 32 rows.
--parallelshould be sized to the expected load. A server built for 128 rows and driven at 32 gives 110.3 tok/s against 143.3, so oversizing loses 23 percent of throughput and 38 percent of median TTFT at the same time.Correction 2026-09-08: quote the mean, not the best leg
The 1.814x above was the best of three legs. Re-measured with the original harness on the same binaries, two further legs read 1.789x and 1.665x, with server-side token counters agreeing with the client to 0.01 percent and resident memory matching to the megabyte, so the layer boundary was identical. Pooling all five legs gives a two-group arm of 197.2 to 215.8 tok/s, mean 209.47, against a one-context arm of 118.42 to 118.96, mean 118.63.
So the honest headline for this flag is 1.77x, range 1.67 to 1.81 over five legs, on a saturating 128-row burst whose leg-to-leg spread is 9 percent. The mechanism and the magnitude are unchanged; only the statistic was too flattering.
Two things confirmed while settling this. The comment-reduction pass on this branch is inert: stripping comments with
gcc -fpreprocessed -dD -E, all five touched files are token-identical betweena1dd7c5e8andd98d90dd8, and the current head measures 1.759x in the same clock state, inside the leg scatter. And generation length is a real axis worth stating: the same leg reads 1.789x at ntg 256 and 1.714x at ntg 128, because the aggregate ratio is diluted by prefill. The decode-only TPOT ratio is 1.947x.Scope, relative to the base branch
This PR targets
master, and against that base it changes 7 files, 1197 insertions and 231 deletions.Stated explicitly because a reviewer diffs against the base, not against the point in a stack a
branch was cut from, and a scope claim measured from the wrong reference is exactly the sentence a
reviewer trusts instead of checking.