Repository navigation
trace: event tracer for the RPC backend, rpc-server and llama-server - #191
danielhanchen wants to merge 41 commits into
Conversation
…ma-server Adds one coherent timing system in place of the ad hoc counters, so the cost of a two node layer split is measured rather than inferred. ggml/include/ggml-trace.h, ggml/src/ggml-trace.cpp JSON line writer, off unless GGML_RPC_TRACE names a file. Call sites read the exported flag directly, so with tracing off the cost is one load and one branch and no clock is read. Also holds the GPU span helper: the timing hooks are resolved through the backend registry, so ggml-base does not link against any GPU runtime. ggml-cuda two entry points exported through the registry: record a CUDA event on the compute stream, and collect the events that have completed. The completions are reported on the host monotonic scale through one anchor event whose completion time was measured once, and nothing ever waits on the GPU. ggml-rpc client: one record per command with the bytes each way, the tensor or graph it belongs to, the thread, the llama-server group, and timestamps at enqueue, first byte sent, last byte sent, our turn in the reply order, first byte of the reply and reply complete. server: one record per command served with receive, execute and reply timestamps, the graph node count and payload size, and CUDA event timestamps around ggml_backend_graph_compute. new RPC_CMD_TRACE_SYNC: a four timestamp exchange at connect time, written into the client trace so the two nodes can be put on one time line. It is only sent while tracing is on. ggml-backend per scheduler split: backend, input count, node count and a GPU span around the submit; the staging path of ggml_backend_tensor_copy broken into host allocation, read back and send, which is the Spark 1 to CPU to Spark 2 cost of the split. llama-server and libllama per group and per iteration: batch build, submit, synchronize, post decode, sampling and result send with slot counts; per llama_decode the scheduler split count. scripts/rpc_trace/merge.py aligns the files with the measured clock offset and emits a Chrome trace with one row per node, thread and group plus a row per GPU, and a per step summary with the idle fraction of each GPU and the biggest idle gap. scripts/rpc_trace/cpu_check.sh two rpc-servers on the CPU backend, run with the trace off and on, output compared.
…erge by time A scheduler runs over several backends and only some of them offer the timing hooks. The probe was cached once for the process, so a split whose first backend was the CPU or the RPC backend disabled the GPU rows for the whole run, and a backend could have been handed to another registry's mark function. The answer is now kept per registry. merge.py walked every event of the file for every phase of every step. The events are indexed by start time and looked up with a bisect instead.
ggml-cuda.cu is also the HIP and MUSA source, and the GPU timing hook uses cudaEventCreate, cudaEventQuery and cudaEventElapsedTime, which the vendor headers did not map yet. Adds the three defines and a single GPU bracket script for the non RPC proof.
…r properly A traced process is normally stopped with a signal at the end of a run, and the tail of the stdio buffer was lost with it. The file is now flushed every 128 lines. The bench script launched the peer server through setsid, so the pid it captured was setsid's and the server, its child, survived every kill. The next cell then found the port taken, logged 'Failed to create server socket' and silently talked to the previous server, which is how a whole set of peer traces came back with nothing but a header. The launch no longer goes through setsid, ssh is given -n, the bind is checked, the port is waited on before and after each cell, and any leftover server on our port is matched with pgrep -x on the binary name and the port in /proc rather than with a pattern that would also match the remote shell.
…, drop the run artifacts The summary named only the single longest stretch of a step in which neither GPU was busy, which is always a prefill batch build and says nothing about the decode steps. It now also reports the total idle time attributed to each host phase, per step. Also removes the bench output and the driver script that were committed by mistake.
…ature/rpc-trace # Conflicts: # tools/server/server-context.cpp
|
Added
It also splits the cell by phase, and that turned out to be the whole answer. Time counts as prefill when any group is inside an iteration that submitted more tokens than it had slots. This has to be a SET of intervals and not a range: a serving cell interleaves prompt batches with decode for its whole length, so "everything before the last prompt iteration" puts most of the decode inside the prefill phase and reports nothing. What it found on a 27B layer split across two DGX Sparks at 128 concurrent rows with two pipeline groups, 313 s window, 557k events, both nodes clock-pinned: Nine tenths of the remaining idle is one device waiting on the other, and two thirds of it lives in the 18 percent of the window that carries a prompt batch. Median idle stretch on the peer is 6.1 ms in decode and 55.2 ms in a prompt iteration. Non-RPC and other-path proof. This commit adds one new file under |
Resolve the conflicts in ggml/src/ggml-rpc/ggml-rpc.cpp and tools/server/server-context.cpp by keeping this branch's code and the base branch's comment wording. Verified with comment_tools check that only comments changed relative to 23d52c3.
|
@codex security review |
Codex Review SummaryThis 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. |
…eline-groups into feature/rpc-trace
RPC_CMD_TRACE_SYNC was added without bumping the protocol minor, so a genuine 5.1 server passed the HELLO version check and then closed the connection on the unknown command. rpc_trace_sync only logged the failed exchange, after which get_socket cached the dead socket and the first real operation on it failed. The minor goes to 2, the peer's minor is recorded from its HELLO response, and the sync is sent only when the peer is at least 2.
Two problems in the GPU timing marks. The anchor and the pending queues were global and bound to whichever device marked first, and every mark from another device was dropped by the device check. The tracer above still handed out tags for those devices, so a multi-GPU trace silently lost all of their work and reported utilization and idle summaries computed from one device. State is now kept per CUDA device. The first mark also called cudaEventSynchronize on the anchor, which drains whatever the scheduler has already queued on that stream, so turning tracing on changed the execution it was supposed to observe. The anchor is only recorded now; its wall clock is taken in poll the first time it is seen complete. That leaves absolute timestamps with an offset bounded by the poll interval and leaves the spacing between marks exact.
…trace Takes the draft-context thread pools, the device-identity fix in the pipeline-group fit reservation, and the router child environment fix. No conflicts this time: they sit in regions the tracing spans do not touch. The merged tree builds llama-server and ggml-rpc-server before this commit was made.
…ature/rpc-trace Takes the change that stops dividing n_ctx when the KV is unified, along with the narrowed --ctx-size divisibility check and the README correction. No conflicts, and the merged tree builds llama-server before this commit was made.
Each was reproduced before being changed, and each has a control showing the unaffected path is untouched. The three script fixes are driven from synthetic traces built to contain the specific shape that breaks them. ggml-cuda: anchor GPU timestamps to the anchor's completion, not to the poll that noticed it. Marks are reported as anchor_us + elapsed(anchor, mark), and anchor_us was ggml_time_us() taken at the first poll that saw the anchor complete, so the whole device timeline shifted forward by however long it had already been complete. In the RPC server that is a full graph, because ggml_backend_graph_compute() synchronizes before the serve loop polls again, which is exactly the data cross-device overlap and idle attribution are computed from. The anchor still is not waited on at record time, since that would drain queued work and change the execution being observed. Instead poll records a probe and measures back to the anchor, but only when cudaStreamQuery reports the stream already idle, in which case the probe completes immediately and the wait drains nothing. That is the normal state at poll time in the serve loop. Busy stream or failed probe falls back to the old approximation. The anchor is frozen once established either way: refining it later would move marks reported after the change relative to those reported before, putting a step in the middle of one device's timeline. ggml-rpc: keep the RPC GPU's device identity. The GPU event carries only the span name and tag, and every device used the fixed name GRAPH_COMPUTE, so one rpc-server exposing several GPUs collapsed into a single row and a single peer-utilization figure. The device index is now part of the name, at both the compute and recompute sites. server: give each router child its own trace file. ggml_trace_open() falls back to GGML_RPC_TRACE and opens with "wb", and children inherit that variable through base_env, so every process opened the identical path. Measured on this branch: with one router and one model, a single 4216-byte file survived carrying only the child's header, the router's having been truncated away. Children now get a path derived from the base name and keyed by port. Erase before push, because execve keeps duplicate entries and getenv returns the first. server: state the phase in the iteration span instead of leaving it to be inferred. Readers cannot tell prefill from decode by tokens per slot, because under speculative decoding an ordinary decode submits several drafted tokens per slot. The span now carries an explicit prompt flag. Verified on a real trace: a 24-token request produced 1 prompt iteration of 14 ms followed by 22 decode iterations of about 1 ms. merge.py: identify logits by tensor subject rather than by response size. A GET_TENSOR over 64 KiB was counted as a logits return, but a layer split pulls staged hidden states back the same way and an 8 MiB activation was charged to the logits column. The subject is already emitted. On the staged-copy trace the logits column drops from 3.5 ms to 0.5 ms while the transfer column stays at 3.5 ms, so the copy is still accounted for, just not as an output. merge.py: associate peer traces with their own clock exchange rather than by hostname text. With peers addressed by IP or DNS alias nothing matched, the single-peer fallback stayed disabled, and both peers kept offset_us = 0 with their events on foreign clocks: peer GPU busy read 0.0% where the truth was 40.0%. On Windows the header host is blank because gethostname is skipped there, and a blank host prefix-matched the first endpoint, silently binding every peer to it and reading 20.0%. Records are now matched by which peer's TRACE_SYNC span brackets the exchange, which needs no hostname at all. Both cases now recover +499.999 and -300.001 ms and report 40.0%. Hostname matching remains as a second choice, now requiring a non-empty host and a dot-boundary match. device_idle.py: stop classifying speculative decode as prefill. max(toks) > n_slots is true for every speculative decode iteration, so t_pre_end slid to the end of the run and the decode-phase and group-offset sections came out empty. On a 2-prefill, 10-speculative-decode trace the phase split went from 12 prefill and 0 decode, with no decode section at all, to 2 and 10 with the decode section populated. It now prefers the explicit prompt flag above, and keeps a heuristic only for traces written before that flag existed.
…d report phase from the batch Five more review items. ggml-trace: initialize the timer before using it. Both llama_server() and rpc-server call ggml_trace_open() before llama_backend_init(), and ggml_trace_open() takes a timestamp. On Windows ggml_time_us() divides by timer_freq, which that later call is what sets, so setting GGML_RPC_TRACE divided by zero during startup instead of launching a traced server. ggml_time_init() is idempotent, so calling it at the top of ggml_trace_open() costs nothing when the backend is already up. This is reasoned from the source and compiled, not executed: I have no Windows machine here. ggml-trace: bound the flush window in time, not only in records. Neither ggml-rpc-server nor the capture scripts install a signal handler, so a SIGTERM runs neither ggml_trace_close() nor the static destructors and whatever sits in the stdio buffer is lost. Flushing every 128 records drops any tail shorter than that no matter how long the run was, and a capture short enough never to reach 128 keeps only its explicitly flushed header. The buffer is now also flushed once 100 ms have passed, so the loss window is bounded for any signal including SIGKILL, which no shutdown path could catch. A handler that closed the trace was the obvious alternative and is deliberately not used: fflush and fclose are not async-signal-safe, and a signal arriving while emit() holds its mutex would deadlock the handler against the thread it interrupted. Ten flushes a second cannot perturb what this tracer measures, whereas a flush per record would put a write syscall inside the very intervals being timed, and non-perturbation is a property this tooling is supposed to have. server: report the phase of the batch that was submitted. The previous flag was derived from slot states read before pre_decode(), which is wrong twice over: a slot can be in a prompt state and contribute nothing because the batch filled before it was admitted, and continuous batching mixes one slot's prompt with other slots' generation in a single batch. The iteration span now carries prompt and decode token counts taken from the rendered batch, using the is_prompt flag each token already carries. device_idle.py prefers those counts, treats a batch that is entirely prompt as prefill, treats any batch containing generation as decode so a late arrival cannot drag the end of the prefill phase forward, and ignores an iteration that submitted nothing. merge.py: attribute every phase in an idle gap. name_gap() kept only the single event with the largest overlap, so the caller charged that one event's coverage to its phase and called the whole remainder untraced, even where the rest of the gap was covered by other traced phases. Coverage is now accumulated for every phase, with each point of the gap charged to exactly one scope, the innermost covering it, so the total can never exceed the gap. On a synthetic step whose real untraced time is 1.1 ms, the reported figure goes from 5.4 ms to 1.1 ms, and on the existing cases from 4.3 ms to 0.8 ms per step. A randomized property test over 20000 gap and scope configurations found no case where the attributed coverage exceeds the gap. Gaps covered by a single phase are byte-identical, and every other column of the report is unchanged. cpu_check.sh: fail when the completions fail. The script set neither pipefail nor errexit and never checked the status of the request pipeline, and cell() ended on an assignment that always succeeds. A curl that could not connect, an HTTP 500, or a response without content therefore left an empty output file, and with both cells empty cmp compared nothing and the script printed PASS and exited 0. Demonstrated three ways: nothing listening, an HTTP 500, and a 200 whose body has no content field. All three printed the non-perturbation PASS having generated and compared zero bytes. Every request is now checked for curl failure, non-200 status, unparseable JSON and missing or empty content, both cells must record every expected completion, both files must be non-empty and carry exactly the expected number of responses before cmp runs, and the script reports how much text it actually compared. A real run against the model still passes and now says so with its evidence: 3 completions, 271 bytes of generated text.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f98e338f24
ℹ️ 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".
| d.anchor_us = ggml_time_us(); | ||
| d.anchor_fixed = true; |
There was a problem hiding this comment.
Wait for an idle anchor stream before fixing its wall time
With --pipeline-groups > 1 sharing a CUDA device, one group can call ggml_backend_sched_synchronize() and globally poll the tracer while the stream that recorded this device's anchor is still executing another group's graph. Fresh evidence after the earlier anchor fix is that this fallback still permanently sets anchor_us to that poll's wall time when cudaStreamQuery() reports the stream busy, shifting every subsequent span on the device and corrupting cross-group overlap and idle results. Leave the marks pending until the anchor stream is idle rather than freezing the approximation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: under continuous load with groups sharing a card the stream may never be idle, so holding marks until then would drop every GPU span. Freezing a consistent offset is the deliberate trade-off.
|
|
||
| llama_token id; | ||
| { | ||
| server_trace_scope span("sampling", grp.id, slot.id); |
There was a problem hiding this comment.
Instrument the speculative post-decode path
When speculative decoding has a nonempty draft, the slot returns at lines 4485–4486 before entering this sampling scope, then performs common_sampler_sample_and_accept_n() and all corresponding process_token() calls later without either sampling or result_send scopes. Consequently speculative runs—the same runs supported by the new phase classification—systematically underreport both columns and classify that time as untraced; add equivalent scopes around the speculative branch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: speculative post-decode coverage is an instrumentation extension, not a defect. That time shows as untraced and is not misattributed to another phase.
| for (const auto & tok : batch.tokens) { | ||
| n_prompt += tok.is_prompt ? 1 : 0; | ||
| } | ||
| span_iter.n_prompt = n_prompt; | ||
| span_iter.n_decode = (int) batch.tokens.size() - n_prompt; |
There was a problem hiding this comment.
Count decodes submitted while building multimodal batches
When an iteration processes only a multimodal chunk, process_mtmd_chunk() submits the image decode inside pre_decode(), but that work is not represented in batch.tokens; these counts are therefore recorded as prompt: 0, decode: 0. device_idle.py::phase_windows() gives the explicit counts precedence and skips such an iteration entirely, excluding its GPU work from the prefill window and distorting multimodal idle reports. Include the tokens decoded by the MTMD path in the recorded prompt count.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: --pipeline-groups refuses --mmproj, and the separate process_mtmd_chunk() decode is the legacy path upstream marks for removal. It stays a single-group diagnostic corner.
| for pass in base_1 new base_2 new_traced; do | ||
| case $pass in base_*) BIN=$B0;; new*) BIN=$B1;; esac | ||
| tenv=() | ||
| [ "$pass" = new_traced ] && tenv=(GGML_RPC_TRACE=$O/nonrpc_trace.jsonl) |
There was a problem hiding this comment.
Actually enable tracing for the batched-bench trace pass
The new_traced batched-bench pass only exports GGML_RPC_TRACE, but llama-batched-bench never calls ggml_trace_open() and this non-RPC workload cannot reach the fallback call in get_socket(); repository-wide call-site inspection shows only llama-server, rpc-server, and the RPC connection path open the tracer. Consequently ggml_trace_flag remains zero and this pass measures another untraced run, so the script cannot validate the tracer's non-RPC overhead as advertised.
Useful? React with 👍 / 👎.
| ggml_trace_eventf("rpc.client", "GRAPH_COMPUTE", t_enq, t_send1, | ||
| "\"t_send0\":%lld,\"t_send1\":%lld,\"bytes_out\":%zu,\"bytes_in\":0," | ||
| "\"reply\":0,\"ok\":1,\"n_nodes\":%d,\"dev\":%u,\"serialize_us\":%lld", | ||
| (long long) t_ser, (long long) t_send1, | ||
| input.size() + RPC_CMD_HEADER_BYTES, cgraph->n_nodes, rpc_ctx->device, |
There was a problem hiding this comment.
Release the RPC send lock before emitting trace records
With concurrent pipeline groups sharing an RPC connection, this trace emission still occurs while the mtx_send lock acquired at line 930 is held. Formatting the record, contending on the trace-file mutex, and occasionally calling fflush() therefore block every other group from submitting its next RPC command; because t_send1 is captured before that work, the added delay appears only as queueing in the following command and can change the overlap the trace is intended to measure. Capture the fields under the connection lock, release it, and emit the record afterward; the no-response send_rpc_cmd() helper has the same lock lifetime.
Useful? React with 👍 / 👎.
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
… interleaved phases The router rewrites each child's GGML_RPC_TRACE to a per-child path; on Windows getenv() also finds a differently cased name, so the match is case-insensitive there too. device_idle.py now reports prefill as the time any prompt chunk is in flight and decode as the decode-only rest, instead of cutting the window at the last prefill, which counted earlier decode iterations as prefill.
# Conflicts: # tools/server/server-context.cpp
…he minor version Clients reject a server whose minor version is newer than their own, so 8.1 made every 8.0 client (upstream and earlier builds) abort against an updated rpc-server even with tracing off. The spare byte of the HELLO reply now carries feature bits; servers without the tracer send 0.
…e, re-anchor idle CUDA devices - t_wait was written as t_send1, so merge.py put the whole wait for a reply (remote execution included) under reading the reply; it is now t_recv0. - GRAPH_COMPUTE and GRAPH_RECOMPUTE spans used different names and so landed on two GPU rows for one device. - CUDA marks are float milliseconds from one startup anchor and lose precision over hours; an idle device with nothing pending moves its anchor up once a minute.
|
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. 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". |
What this is
A timing and profiling system for the RPC backend and llama-server, so that the bottlenecks of a
two node layer split are measured rather than inferred. It replaces the ad hoc pieces used so far
(RPC command counters in the client, per group timers in the server) with one tracer that both
nodes write to and one tool that merges them.
Based on
feature/pipeline-groups.Design
ggml/include/ggml-trace.handggml/src/ggml-trace.cpplive in ggml-base, so every binary thattakes part (libllama, llama-server, the RPC backend, ggml-rpc-server) can raise events without a
new dependency.
Off by default, and free when off. The tracer writes nothing unless
GGML_RPC_TRACE=<path>is set, or
ggml-rpc-server --trace <path>. Call sites read the exported flag directly:so with tracing off the cost is one load and one branch; no clock is read, nothing is formatted
and no allocation happens. There is no change to any output byte with the tracer off or on.
JSON lines. One header object per file, then one object per event, one file per process.
A line is built in the calling thread and handed to the file under a mutex, and the file is
flushed every 128 lines so that a process stopped with a signal does not lose its tail.
Clock alignment. A new
RPC_CMD_TRACE_SYNCcarries a four timestamp exchange (client sendsat t1, peer stamps t2 on receive and t3 on reply, client stamps t4), done once per connection at
connect time and only while tracing is on; the peer always answers it. The resulting offset is
written into the client trace, and the merge tool uses it to put both nodes on one time line.
Measured offsets on the pair were about 1.8 s between the two boot clocks, with round trips in
the tens of microseconds.
What is recorded
RPC client, one record per command: command type, bytes sent and received, the tensor name or
graph uid it belongs to, the calling thread, the llama-server pipeline group (threads tag
themselves through a thread local), and timestamps at enqueue into the dispatcher, first byte
sent, last byte sent, our turn in the reply order, first byte of the reply, reply complete.
Scheduler, per split: the backend, the input count and the node count; and the staging path of
ggml_backend_tensor_copybroken into host allocation, read back and send. That is theSpark 1 to CPU to Spark 2 hop of a layer split, visible as its own span.
rpc-server, one record per command served: receive start and end, execute start and end, reply
start and end, bytes each way, graph node count and device.
GPU. A backend submit only queues the work, so host timestamps around it say nothing about
when the kernels ran. The CUDA backend exports two entry points through the registry
(
ggml_backend_cuda_trace_mark,ggml_backend_cuda_trace_poll), so ggml-base and the RPC backenddo not have to link against CUDA. They record CUDA events on the compute stream around
ggml_backend_graph_computeand report the completions on the host monotonic microsecond scale,anchored by one event whose completion time on the host was measured once. Nothing ever waits on
the GPU: the completed spans are collected from points where the caller is idle anyway (the serve
loop between commands, the scheduler synchronize). The hooks are looked up per backend registry,
so a scheduler that runs over a CPU or RPC backend as well still gets the CUDA rows.
llama-server, per group and per iteration: batch build, submit (
llama_decode),llama_synchronize, post decode, sampling and result send, with slot counts. libllama, perllama_decode: the scheduler split count, with the per split backend coming from the schedulerevents above.
Tools
scripts/rpc_trace/merge.pyreads the files of both nodes, aligns them with the measured clockoffset and writes
chrome://tracing, or the Perfetto UI) with one row per node, thread andpipeline group, the phases of each RPC command as nested slices, and one row per GPU carrying
the CUDA event timings, and
the idle fraction of each GPU, the longest stretch of the step in which neither GPU was busy,
and the total idle time attributed to each host phase.
scripts/rpc_trace/cpu_check.shis the CPU validation: two rpc-servers on the CPU backend and onellama-server splitting layers over them, run once with the trace off and once with it on, with the
generated text compared.
scripts/rpc_trace/gpu_trace.shandscripts/rpc_trace/nonrpc_bracket.shrun the cells below.
Overhead
Measured, not assumed: every configuration was run with the tracer off and on.
Layer split over two nodes, Qwen3.8-27B UD-Q4_K_XL, 32 concurrent, npp 128 / ntg 256,
--cache-ram 0,-c 16384, whole cell tok/s:--device CUDA0,RPC0--device RPC0,CUDA0--device RPC0,CUDA0That is +0.3, -1.2 and +1.9 percent, in both directions, so within run to run noise. The client
writes about 865 events per second (19 MB over a 170 s cell) and the peer about 60 per second.
Non-RPC and non-CUDA workloads
The tracer lives in ggml-base and adds two entry points to the CUDA backend's registry, so it is
on the path of workloads that never touch RPC. It costs them nothing.
Single GPU, no
--rpc,llama-batched-bench -c 32768 -npp 512 -ntg 128 -npl 1,8,32on the samemodel, run base / new / base / new-with-the-trace-on, prompt and generation tok/s:
The node dropped to a lower clock state between the second and the third pass (prompt throughput
falls from about 828 to about 679 for both builds), so the comparisons that hold are the ones
inside one clock state: new against base at npl 1 and 8 is -0.2 and -0.3 percent on prompt, new
against the base repeat at npl 32 is -0.2 percent on prompt and +0.8 on generation, and new with
the trace on against the base repeat is -0.3 and -0.2 percent. Nothing outside noise.
Bit exactness, five greedy prompts, 48 tokens each:
74926c4ef135f3cc89ad20cd5ec7e445for the base, for this branch withthe trace off, and for this branch with the trace on;
-DGGML_CUDA=OFF -DGGML_RPC=OFF: md5177dc61e0703eba3bdaf7bf1131f0458forthe same three.
Build configurations checked:
-DGGML_RPC=OFF -DGGML_CUDA=ONand-DGGML_CUDA=OFF -DGGML_RPC=OFFboth build clean, and the CPU only build still produces a usable trace of thellama and scheduler events with no GPU rows.
Other backends. Vulkan has no
get_proc_addressat all and the registry returns NULL for thatcase; Metal and SYCL fall through to NULL for a name they do not know.
ggml_trace_gpu_begintherefore gets no hook, returns 0 and records nothing, and no other line of those backends is
touched.
ggml-cuda.cuis also the HIP and MUSA source, and the vendor headers did not mapcudaEventCreate,cudaEventQueryorcudaEventElapsedTime, so those two builds would not havecompiled; the three defines are added.
The three timelines
Per decode step, in milliseconds, from the traces.
localGPUandpeerGPUcome from CUDA eventson the compute stream of each node, so they are what the GPUs did, not what the host queued.
idle bothis the part of the step in which neither GPU was busy.GPU busy over the whole cell, and RPC bytes per step:
What the traces say.
logits of 32 rows over a 248320 token vocabulary.
llama_decodedoes not return until thewhole step is finished (submit 303 ms, synchronize 0), because the blocking GET_TENSOR of the
logits sits inside it. The two GPUs never overlap: 150.0 and 149.7 ms of GPU work inside a
325.6 ms step, each of them idle through the other's stage. Named bottleneck: the serial chain
itself, with the logits return as the transport cost that pays for nothing.
back, and the step now splits into submit 159 ms and synchronize 130 ms. The step barely moves
(312.3 against 325.6) because the stages still alternate: 140.0 and 154.9 ms of GPU work in a
312.3 ms step. Named bottleneck: still the serial chain. The staged copy of the hidden state
through a host buffer (
ggml_backend_tensor_copy, since the RPC backend has nocpy_tensor_async) is 148.4 ms per step here, which is the span an asynchronous device todevice path would attack; that number includes the blocking wait for the peer's graph, so it is
an upper bound on the copy itself.
step, both GPUs at 88 to 90 percent, and only 5.9 to 6.6 ms per step in which neither GPU is
busy against 24 to 27 ms with one context. Named bottleneck: GPU compute. The host path is off
the critical path because one group runs it under the other group's GPU work.
(sampling and streaming) and batch build 8.3 to 9.5 ms; with two groups, batch build 2.6 to
3.3 ms and post decode 0.1 to 0.3 ms. The single longest idle gap in every cell is a prefill
step's batch build, 0.9 to 1.3 s, which is a time to first token cost and not a decode cost.
Validation
CPU harness (
scripts/rpc_trace/cpu_check.sh, two local CPU rpc-servers, three greedy prompts):the generated text is byte identical with the trace off and on, the trace files parse, and the
measured clock offsets between the local processes are 0 and 1 us with a 14 to 16 us round trip.
Scope, relative to the base branch
This PR targets
feature/pipeline-groups, and against that base it changes 20 files, 1835 insertions and 15 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.