Repository navigation
rpc : typed request helpers and a single validation step on the server - #32651
Merged
Merged
Conversation
Client and server share one table (rpc_msg_types) that maps each fixed-size command to its request and response structs. The client sends them with dispatcher->call<CMD>() and call_async<CMD>(), the server serves them with rpc_serve<CMD>(), so the per-command code in rpc_serve_client and at the call sites is gone and a wrong struct for a command does not compile. SET_TENSOR, SET_TENSOR_2D and GRAPH_COMPUTE get header structs, written with rpc_writer and parsed with a bounds-checked rpc_reader. The wire format is unchanged. Validation of client data is now in one place: - deserialize_tensor rejects what ggml_new_tensor would assert on (op range, ne[0] not a multiple of the block size, element count overflow) and computes the tensor size without overflow before the buffer check - rpc_check_region replaces the per-handler bounds checks and checks the request against the tensor size, which ggml_backend_tensor_set/get/memset assert on, so an in-buffer but out-of-tensor request no longer aborts - graph_compute builds the graph in one pass over the tensors, which the client sends in topological order: no recursion, and unknown or duplicate ids, duplicate nodes, sources sent after their users, compute nodes with unallocated operands and views outside their view_src buffer are rejected; a tensor may be its own source (ggml_cast) - GET_ALLOC_SIZE fails if a source tensor is invalid - a client-sized allocation that fails closes the connection instead of terminating the server
rgerganov
reviewed
Nov 20, 2026
rgerganov
left a comment
Member
There was a problem hiding this comment.
still going through this, some initial comments
rgerganov
approved these changes
Nov 23, 2026
rgerganov
left a comment
Member
There was a problem hiding this comment.
LGTM, nice overall improvement, thanks. I also did some tests and I haven't found regressions so far. FYI, I am also planning to add a CI job for the RPC backend soon.
am17an
commented
Nov 23, 2026
ggerganov
approved these changes
Nov 23, 2026
ggerganov
left a comment
Member
There was a problem hiding this comment.
Did some tests with 2x DGX Sparks + RDMA - looks OK
Cinderella-Man
added a commit
to Cinderella-Man/miner-llama
that referenced
this pull request
Nov 24, 2026
Upstream's newest tag, 191 commits past b12483, merged on pascal-p106-v5 af00bb1 (the 14 landed branches). 26 files conflicted. Each kept both sides' intent; the list with reasons is the public data folder docs/data/2026-11-24_c912_upstream_b12674/conflicts.tsv. The ones that change code: - ggml.h, ggml.c, ggml-rpc.h: upstream's GGML_OP_SLEEP and GGML_OP_SIGMOID_BACK go after the fork's three ops after GLU, so the fork's op numbers stay; GGML_OP_COUNT 105, RPC patch version 6 (fork 4 + upstream 2). - ggml-rpc.cpp: upstream's single validation step (ggml-org#32651) already rejects unknown ops, so the fork's own check goes; the client's FREE_BUFFER that forgets dropped graphs (C929) sends with upstream's typed call<>. - mmid.cu: upstream's helper with duplicate expert ids (ggml-org#32505) dumps its store in pieces; the legacy tile layout (GGML_CUDA_MMQ_MOE_LEGACY) reads the expert's column count from n_dumped. - mmq.cuh: the kernel takes kq_fp32 (C861) before upstream's force_tiling (GCN only); the force_tiling launch passes kq_fp32 through. - ggml-cuda.cu: ggml-org#32239 (no matrix-vector fusion on any Pascal card) merged without a conflict; the fork keeps the fusion on compute 6.1 as v5 measured it per file, and GGML_CUDA_MMID_GLU_UNFUSE=2 gives upstream's rule (C893). - llama-graph.cpp: upstream's automatic "<name>.scale" lookup (ggml-org#32669) replaces the explicit scale arguments, the cold tier's included (its scales carry their tensors' names); the down projection's rescale is upstream's use_amax rule (ggml-org#32677) and the fork's LLAMA_NO_MOE_DOWN_RESCALE condition; route-once's histogram before upstream's random routing (ggml-org#29539); the device-built KQ mask (LLAMA_GPU_KQ_MASK) moves into upstream's build_attn_iswa_impl (ggml-org#32429) and replaces only the default mask. - llama-memory-hybrid-idx.cpp: ggml-org#32519 scores only the ubatch's sequences' k-pools; with the k-pool tables on the devices (LLAMA_QSA_KPOOL_DEV) the list keeps every sequence's pools, as the tables hold them (get_n_kpool); the pads avoid every pool's rep in both layouts (LLAMA_QSA_PAD_LINEAR's bound kept). - llama-quant.cpp: N2P and N3P's fallbacks go into upstream's fallback_type_for (ggml-org#15550), with the row width; Q4_1_64 in upstream's moved llama_ftype_get_default_type. - glm5-next.cpp, qwen4exp.cpp: the fused lightning indexer is always on (ggml-org#32650): the in-place row variant (LLAMA_QSA_INDEXER_ROWS) without the removed switch. - flint.cpp, qwen4exp.cpp, gemma4.cpp, test-llama-archs.cpp, test-backend-ops.cpp, server-context.cpp: the fork's code with upstream's signature changes, model-name helper, decision groups and label outputs (ggml-org#32553), gemma4's multi-sequence prune (ggml-org#32342) without device-built masks. Carried upstream fixes now merged upstream: ggml-org#32434 (6026911: upstream's version taken, the fork's change kept is only --ctx-checkpoints-share's copy and get_reuse's two trim arguments) and ggml-org#31913 (2b2da8a: upstream's fill, the same change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
ggml-rpc builds every message by hand from packed structs, and the server validates client data separately in each handler. This PR keeps the wire format and the protocol version, and changes how the code builds and checks messages.
Typed messages. One table,
rpc_msg_types<cmd>, maps each fixed-size command to its request and response structs. The client sends them withdispatcher->call<CMD>()/call_async<CMD>()and the server serves them withrpc_serve<CMD>(), so each case inrpc_serve_clientis one line and passing the wrong struct for a command does not compile. SET_TENSOR, SET_TENSOR_2D and GRAPH_COMPUTE get header structs, written withrpc_writerand parsed with a bounds-checkedrpc_reader.One validation step.
deserialize_tensorrejects whatggml_new_tensorwould assert on (op range,ne[0]not a multiple of the block size, element count overflow) and computes the tensor size without overflow before the buffer check.rpc_check_regionreplaces the per-handler bounds checks. It checks the request against the tensor size, whichggml_backend_tensor_set/get/memsetassert on. Master checks against the buffer, so a request inside the buffer but past the end of the tensor aborts the server.graph_computebuilds the graph in one pass, because the client already sends tensors in topological order (add_tensoris post-order). There is no recursion. Unknown or duplicate ids, duplicate nodes, sources sent after their users, compute nodes with unallocated operands, and views outside theirview_srcbuffer are rejected. A tensor may still be its own source, whichggml_castrelies on.The file goes from 3432 to 3212 lines.
Additional information
This overlaps with several open hardening PRs that add the same checks in place: #31018, #31190, #31843, #30474, #25670 and #31322. #31217 changes
ggml_nbytesinstead; here the size is checked on the wire values before the tensor is created.Tested with CPU rpc-servers, against master built from the same base:
test-backend-opswith an RPC device (local hook, not part of this PR): 24801/24801 pass, the same set as master-sm tensorover two servers andrpc-server -c(cache save and load) match mastertest-rpc-multi-serverandtest-rpc-unreachablepassNot tested yet: GPU servers, RDMA.
Requirements