Skip to content

RPC: Improve loading times - #29413

Merged
ggerganov merged 5 commits into
masterfrom
rpc_tensor_loading
Nov 9, 2026
Merged

ggerganov merged 5 commits into
masterfrom
rpc_tensor_loading

Conversation

@am17an

@am17an am17an commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Improves loading time for me by 5x on 2 sparks.

DeepSeek-V4-Flash (145.6 GiB), 2x DGX Spark, both devices over RPC (RDMA), cold page cache, load_tensors time:

Config master (s) PR (s) Speedup
-sm layer -lm dio 450 57 7.9x
-sm tensor -lm dio 1484 166 8.9x
-sm layer, default (mmap) 495 326 1.5x
-sm tensor, default (mmap) 1589 487 3.3x

Changes:

  • Skip hashing when the server has no cache: the hello response's padding byte becomes a server-flags byte (RPC_SERVER_FLAG_CACHE, set by rpc-server -c). The client hashes tensors for SET_TENSOR_HASH only when the server has a cache.
  • No copy on the client: SET_TENSOR sends the tensor data straight from the caller's pointer after the header, instead of first copying it into a zero-filled message buffer.
  • Chunked receive on the server: SET_TENSOR data is read in chunks through a reused 16 MiB buffer, instead of a new full-size vector for every tensor. The -c cache-save path still reads the whole tensor so it can hash it.
  • RDMA: rdma_recv can read part of a receive slot, so receive sizes no longer have to match send sizes. The chunked receive above needs this.
  • RPC protocol 9.0.0: a major bump, because the hello response format changed. Older clients and servers are rejected instead of silently skipping the cache.

This also lowers peak memory during loading: the client keeps one fewer copy of each tensor, and the server's receive buffer is 16 MiB instead of the size of the tensor. Uploads that go through SET_TENSOR_2D (-sm tensor split weights) are not changed.

Additional information

Requirements

@am17an
am17an added this pull request to stack #29414 September 25, 2026 05:19
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 25, 2026
@am17an am17an changed the title Rpc tensor loading RPC: Improve loading times Sep 25, 2026
Base automatically changed from rpc_tensor to master October 6, 2026 15:25
@am17an
am17an force-pushed the rpc_tensor_loading branch from 7d8a964 to 3428627 Compare October 27, 2026 16:20
@am17an
am17an marked this pull request as ready for review October 27, 2026 16:27
@am17an
am17an requested review from a team and ggerganov as code owners October 27, 2026 16:27
@am17an
am17an force-pushed the rpc_tensor_loading branch from 3a95ed3 to d88ec8c Compare October 28, 2026 04:43

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally, it would help reviewing changes if there is some detailed description in the PR about what is the thought process and what generally the changes achieve.

For example, I've looked at this PR for ~1h and now I understand most of the things, but it definitely took me a while to get there. The dispatcher now has flags with "remote capabilities" called "sever_flags". It also has a new call that allows to do sync send with extra buffer (called "payload") that is not copied into the rpc message structure. It is used for the SET_TENSOR command and it is an exception to how all other RPC messages are handled. There is also some buffer chunking that allegedly speeds up host -> device transfers.

The changes in transport.cpp are not clear to me yet - I don't know what they do and why they are needed.

Comment thread src/llama-model-loader.cpp Resolved
@am17an

am17an commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Yeah agreed. The transport changes are for receiving partial messages. The model loader changes are for avoiding a bounce buffer when async uploads are not possible.

@mahounairo

Copy link
Copy Markdown

Beyond making uploads a bit faster, this also significantly reduces peak memory usage with large models. Uploading Qwen3.8-Flash-Next's 27GB per_layer_token_embd on my setup couldn't be done due to hitting OOM.

With my own, shallower implementation:

4GiB tensor over ggml-rpc-server, loopback:
MEM SERVER: 8196 -> 4357MiB
MEM CLIENT: 8197 -> 4357MiB
UPLOAD: 7.9-8.1s -> 6.0-6.2s

@am17an
am17an force-pushed the rpc_tensor_loading branch from e31caf2 to 33bc861 Compare November 9, 2026 05:57
@am17an

am17an commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@ggerganov I've added a summary of changes to this PR. I think it's a big improvement over how we're currently doing RPC and it will make non-cached loads (the default) very usable (apart from lowering peak mem usage)

Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved
Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Resolved

@ggerganov ggerganov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be worth trying to do a from-scratch implementation of ggml-rpc.cpp with an LLM (guided with the existing implementation). Some areas worth improving:

  • message serialization
  • improve type safety
  • better logs and tests

Think such a refactor/reimplementation can improve the development flow in general of this sub-system.

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 9, 2026
@ggerganov
ggerganov merged commit cf92c13 into master Nov 9, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants