char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
b114b4739
char/aliceai-t5-moe
Overview
[!IMPORTANT] This example and the RPC backend are currently in a proof-of-concept development stage. As such, the functionality is fragile and insecure. Never run the RPC server on an open network or in a sensitive environment!
The ggml-rpc-server allows exposing ggml devices on a remote host.
The RPC backend communicates with one or several instances of ggml-rpc-server and offloads computations to them.
This can be used for distributed LLM inference with llama.cpp in the following way:
flowchart TD
rpcb<-->|TCP|srva
rpcb<-->|TCP|srvb
rpcb<-.->|TCP|srvn
subgraph hostn[Host N]
srvn[ggml-rpc-server]<-.->dev4["CUDA0"]
srvn[ggml-rpc-server]<-.->dev5["CPU"]
end
subgraph hostb[Host B]
srvb[ggml-rpc-server]<-->dev3["Metal"]
end
subgraph hosta[Host A]
srva[ggml-rpc-server]<-->dev["CUDA0"]
srva[ggml-rpc-server]<-->dev2["CUDA1"]
end
subgraph host[Main Host]
local["Local devices"]<-->ggml[llama-cli]
ggml[llama-cli]<-->rpcb[RPC backend]
end
style hostn stroke:#66,stroke-width:2px,stroke-dasharray: 5 5
classDef devcls fill:#5B9BD5
class local,dev,dev2,dev3,dev4,dev5 devcls
By default, ggml-rpc-server exposes all available accelerator devices on the host.
If there are no accelerators, it exposes a single CPU device.
Usage
Remote hosts
On each remote host, build the backends for each accelerator by adding -DGGML_RPC=ON to the build options.
For example, to build the ggml-rpc-server with support for CUDA accelerators:
mkdir build-rpc-cudacd build-rpc-cudacmake ..-DGGML_CUDA=ON -DGGML_RPC=ON cmake --build .--config Release
When started, the ggml-rpc-server will detect and expose all available CUDA devices:
$ bin /ggml-rpc-server ggml_cuda_init: GGML_CUDA_FORCE_MMQ: noggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: noggml_cuda_init: found 1 CUDA devices:Device 0: NVIDIA GeForce RTX 5090, compute capability 12.0, VMM: yesStarting RPC server v3.0.0endpoint : 127.0.0.1:50052 localcache : n/aDevices: CUDA0: NVIDIA GeForce RTX 5090 (32109 MiB, 31588 MiB free)
You can control the set of exposed CUDA devices with the CUDA_VISIBLE_DEVICES environment variable or the --device command line option. The following two commands have the same effect:
$ CUDA_VISIBLE_DEVICES =0 bin/ggml-rpc-server-p 50052$ bin /ggml-rpc-server --device CUDA0-p 50052
Main host
On the main host build llama.cpp with the backends for the local devices and add -DGGML_RPC=ON to the build options.
Finally, when running llama-cli or llama-server, use the --rpc option to specify the host and port of each ggml-rpc-server:
$ llama -cli -hf ggml-org/gemma-3-1b-it-GGUF-ngl 99--rpc 192.168.88.10:50052,192.168.88.11:50052
By default, llama.cpp distributes model weights and the KV cache across all available devices -- both local and remote -- in proportion to each device's available memory.
You can override this behavior with the --tensor-split option and set custom proportions when splitting tensor data across devices.
Local cache
The RPC server can use a local cache to store large tensors and avoid transferring them over the network.
This can speed up model loading significantly, especially when using large models.
To enable the cache, use the -c option:
$ bin /ggml-rpc-server -c
By default, the cache is stored in the $HOME/.cache/llama.cpp/rpc directory and can be controlled via the LLAMA_CACHE environment variable.
RDMA transport
The RPC backend can use RDMA instead of TCP for lower latency and higher throughput. The transport is negotiated during the initial handshake -- no changes to command-line usage are required, and the connection falls back to TCP unless both peers can use RDMA.
Two providers are supported, each enabled by default when its library is found at build time:
- Linux: RoCEv2-capable NICs (e.g. Mellanox ConnectX), via
libibverbs. - macOS: RDMA over Thunderbolt on Apple silicon Macs with Thunderbolt 5, via
librdma. Requires macOS 26.2 or later, with RDMA enabled once from macOS Recovery viardma_ctl enable. See TN3205.
RDMA is point-to-point, so each side uses the local device whose GID matches the address the connection was made on. Connect over the RDMA-capable link -- with Thunderbolt, use the peer's Thunderbolt address in --rpc; a connection made over another interface stays on TCP.
To force plain TCP without rebuilding, set GGML_RPC_NO_RDMA on either peer:
$ GGML_RPC_NO_RDMA =1 bin/ggml-rpc-server
Troubleshooting
Use the GGML_RPC_DEBUG environment variable to enable debug messages from ggml-rpc-server:
$ GGML_RPC_DEBUG =1 bin/ggml-rpc-server
1## Overview 2 3> [!IMPORTANT] 4> This example and the RPC backend are currently in a proof-of-concept development stage. As such, the functionality is fragile and 5> insecure. **Never run the RPC server on an open network or in a sensitive environment!** 6 7The `ggml-rpc-server` allows exposing `ggml` devices on a remote host. 8The RPC backend communicates with one or several instances of `ggml-rpc-server` and offloads computations to them. 9This can be used for distributed LLM inference with `llama.cpp` in the following way: 10 11``` mermaid 12flowchart TD 13rpcb<-->|TCP|srva 14rpcb<-->|TCP|srvb 15rpcb<-.->|TCP|srvn 16subgraph hostn[Host N] 17srvn[ggml-rpc-server]<-.->dev4["CUDA0"] 18srvn[ggml-rpc-server]<-.->dev5["CPU"] 19end 20subgraph hostb[Host B] 21srvb[ggml-rpc-server]<-->dev3["Metal"] 22end 23subgraph hosta[Host A] 24srva[ggml-rpc-server]<-->dev["CUDA0"] 25srva[ggml-rpc-server]<-->dev2["CUDA1"] 26end 27subgraph host[Main Host] 28local["Local devices"]<-->ggml[llama-cli] 29ggml[llama-cli]<-->rpcb[RPC backend] 30end 31style hostn stroke:#66,stroke-width:2px,stroke-dasharray: 5 5 32classDef devcls fill:#5B9BD5 33class local,dev,dev2,dev3,dev4,dev5 devcls 34``` 35 36By default, `ggml-rpc-server` exposes all available accelerator devices on the host. 37If there are no accelerators, it exposes a single `CPU` device. 38 39## Usage 40 41### Remote hosts 42 43On each remote host, build the backends for each accelerator by adding `-DGGML_RPC=ON` to the build options. 44For example, to build the `ggml-rpc-server` with support for CUDA accelerators: 45 46``` bash 47mkdir build-rpc-cuda 48cd build-rpc-cuda 49cmake .. -DGGML_CUDA=ON -DGGML_RPC=ON 50cmake --build . --config Release 51``` 52 53When started, the `ggml-rpc-server` will detect and expose all available `CUDA` devices: 54 55``` bash 56$ bin /ggml-rpc-server 57ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no 58ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no 59ggml_cuda_init: found 1 CUDA devices: 60Device 0: NVIDIA GeForce RTX 5090, compute capability 12.0, VMM: yes 61Starting RPC server v3.0.0 62endpoint : 127.0.0.1:50052 63local cache : n/a 64Devices: 65CUDA0: NVIDIA GeForce RTX 5090 ( 32109 MiB, 31588 MiB free) 66``` 67 68You can control the set of exposed CUDA devices with the `CUDA_VISIBLE_DEVICES` environment variable or the `--device` command line option. The following two commands have the same effect: 69``` bash 70$ CUDA_VISIBLE_DEVICES =0 bin/ggml-rpc-server -p 50052 71$ bin /ggml-rpc-server --device CUDA0 -p 50052 72``` 73 74### Main host 75 76On the main host build `llama.cpp` with the backends for the local devices and add `-DGGML_RPC=ON` to the build options. 77Finally, when running `llama-cli` or `llama-server`, use the `--rpc` option to specify the host and port of each `ggml-rpc-server`: 78 79``` bash 80$ llama -cli -hf ggml-org/gemma-3-1b-it-GGUF -ngl 99 --rpc 192.168.88.10:50052,192.168.88.11:50052 81``` 82 83By default, llama.cpp distributes model weights and the KV cache across all available devices -- both local and remote -- in proportion to each device's available memory. 84You can override this behavior with the `--tensor-split` option and set custom proportions when splitting tensor data across devices. 85 86### Local cache 87 88The RPC server can use a local cache to store large tensors and avoid transferring them over the network. 89This can speed up model loading significantly, especially when using large models. 90To enable the cache, use the `-c` option: 91 92``` bash 93$ bin /ggml-rpc-server -c 94``` 95 96By default, the cache is stored in the `$HOME/.cache/llama.cpp/rpc` directory and can be controlled via the `LLAMA_CACHE` environment variable. 97 98### RDMA transport 99 100The RPC backend can use RDMA instead of TCP for lower latency and higher throughput. The transport is negotiated during the initial handshake -- no changes to command-line usage are required, and the connection falls back to TCP unless both peers can use RDMA. 101 102Two providers are supported, each enabled by default when its library is found at build time: 103 104- **Linux**: RoCEv2-capable NICs (e.g. Mellanox ConnectX), via `libibverbs`. 105- **macOS**: RDMA over Thunderbolt on Apple silicon Macs with Thunderbolt 5, via `librdma`. Requires macOS 26.2 or later, with RDMA enabled once from macOS Recovery via `rdma_ctl enable`. See [TN3205](https://developer.apple.com/documentation/technotes/tn3205-low-latency-communication-with-rdma-over-thunderbolt). 106 107RDMA is point-to-point, so each side uses the local device whose GID matches the address the connection was made on. Connect over the RDMA-capable link -- with Thunderbolt, use the peer's Thunderbolt address in `--rpc`; a connection made over another interface stays on TCP. 108 109To force plain TCP without rebuilding, set `GGML_RPC_NO_RDMA` on either peer: 110``` bash 111$ GGML_RPC_NO_RDMA =1 bin/ggml-rpc-server 112``` 113 114### Troubleshooting 115 116Use the `GGML_RPC_DEBUG` environment variable to enable debug messages from `ggml-rpc-server`: 117``` bash 118$ GGML_RPC_DEBUG =1 bin/ggml-rpc-server 119``` 120