## 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: ```mermaid 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 ### Protocol compatibility UID-selected graph replay, transmitted use counts, and the optional full mesh use private protocol **128.4.0 / NDBOUND2** after integration with upstream RPC v10. Build and deploy matching binaries on every participant; upstream RPC and the archive's 128.3.3 / NDBOUND1 protocol are incompatible. Cached graphs are connection- and device-scoped, bounded by entry count and memory, and invalidated before referenced buffers are freed. UID zero is never retained. Worker use-count restoration is enabled by default; `GGML_RPC_USE_COUNTS=0` disables it for comparison. See the [fork guide](../../docs/windows-nd-usb4.md) for CPU/TCP validation and compatibility requirements. The transport can fall back to TCP. Neither successful startup nor an established TCP bootstrap socket proves ND activation. Require `NetworkDirect activated:` for each intended ND connection and reject fallback in ND measurements. RPC remains unauthenticated: bind only to intended interfaces on a trusted network. ### 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: ```bash mkdir build-rpc-cuda cd build-rpc-cuda cmake .. -DGGML_CUDA=ON -DGGML_RPC=ON cmake --build . --config Release ``` When started, the `ggml-rpc-server` will detect and expose all available `CUDA` devices: ```bash $ bin/ggml-rpc-server ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no ggml_cuda_init: found 1 CUDA devices: Device 0: NVIDIA GeForce RTX 5090, compute capability 12.0, VMM: yes Starting RPC server v3.0.0 endpoint : 127.0.0.1:50052 local cache : n/a Devices: 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: ```bash $ 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`: ```bash $ 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: ```bash $ 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 via `rdma_ctl enable`. See [TN3205](https://developer.apple.com/documentation/technotes/tn3205-low-latency-communication-with-rdma-over-thunderbolt). 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: ```bash $ GGML_RPC_NO_RDMA=1 bin/ggml-rpc-server ``` ### NetworkDirect transport On Windows, the equivalent role is served by NetworkDirect. It is off by default and needs a NetworkDirect SDK checkout providing `src/ndutil` plus a generated `ndstatus.h`: ```bash $ cmake -B build -DGGML_RPC=ON -DGGML_RPC_ND=ON -DGGML_RPC_ND_SDK=C:/path/to/NetworkDirect ``` Like RDMA, the transport is negotiated during the HELLO handshake and needs no command-line changes. If no NetworkDirect provider is installed, or the adapter cannot be opened, both peers silently stay on TCP. The TCP connection is also used to pick the local adapter. When RDMA and TCP run over different NICs, set `GGML_ND_ADDR` on both peers to the IPv4 address of the RDMA NIC. The application uses ND service port 23517. The tested USB4 provider maps its TCP connection-management listener to service port + 1, normally 23518. Provider installation, registration and network policy are separate from building this backend. ND uses page-aligned, fixed 32768-byte Send/Receive frames, including ACK and BYE, with at most 32752 logical payload bytes and zero-filled padding. The capability/message tags are NDR3 / NDM2; earlier NDR2 / NDM1 builds are not wire-compatible even if their RPC version matches. Deploy the same build to all peers. Received frame and logical payload lengths are checked before use. A canceled zero-byte receive is considered closure only when its receive context is valid and the TCP peer has independently closed; active-transfer failures remain errors. The tested Windows/USB4 pairing is Windows 29704.1002 with [NetworkDirect provider commit d93ad88](https://github.com/alex-bozhko/NetworkDirect/commit/d93ad88ed8e5ad4eac27c17e94f4b51923f07096). It requires `HKLM\SYSTEM\CurrentControlSet\Services\Usb4HostRouter\Parameters\EnableInterDomainRdma` as `REG_DWORD` value `1` and a compatible registered provider. Adapter discovery alone does not establish provider/kernel compatibility; verify memory registration and actual transfers after an OS upgrade. No driver or registry modification is performed by this backend. Set `GGML_RPC_DEBUG=1` on both peers to trace the NetworkDirect bring-up: adapter selection and capabilities, memory registration, completion queue and queue pair creation, and each stage of the connection handshake. Every step that can decline to TCP reports why. ### Windows HIP full-mesh quick start This is a source distribution, not a self-contained binary or driver installer. The archive's historical approximately 22 tok/s configuration uses three Radeon 8060S/gfx1151 hosts, HIP, full ND mesh, Qwen3-235B-A22B-Instruct-2507 Q4_K_M, and no speculation; that result must be revalidated after integration with newer upstream code. The HIP kernel and mesh optimizations are included as source; no external megakernel DLL is needed. Vulkan and the coordinator-centered options below remain available. Provision each host with a compatible GPU driver, the Windows/ND provider pairing described above, and a trusted IP link to both other hosts. The tested build stack is Visual Studio 18 with MSVC 14.51, Clang 24, and TheRock packages `rocm`, `rocm-sdk-core`, `rocm-sdk-libraries`, `rocm-sdk-devel`, and `rocm-sdk-device-gfx1151` at `10.1.0a20260910`. Obtain matching SDK/runtime packages from [TheRock](https://github.com/ROCm/TheRock); other versions require validation. The model requires sufficient GPU memory across the three hosts and adequate physical RAM and Windows commit headroom. Do not change security, firewall, power, or memory policies to bypass a failed prerequisite. Clone this branch and obtain a [NetworkDirect SDK source checkout](https://github.com/microsoft/NetworkDirect). CMake compiles `src/ndutil/{ndaddr,ndfrmwrk,ndprov}.cpp` directly. It also needs `ndstatus.h` generated from that checkout's message definitions; building the SDK normally generates it. Alternatively, in an initialized Visual Studio x64 developer PowerShell, generate only the header/resources needed by this build: ```powershell $nd = 'C:/sdk/NetworkDirect' $ndInclude = "$nd/out/Release-x64/include" New-Item -ItemType Directory -Force $ndInclude | Out-Null & mc.exe -h $ndInclude -r $ndInclude "$nd/src/ndutil/ndstatus.mc" if ($LASTEXITCODE) { throw 'NetworkDirect header generation failed' } ``` The SDK is a build dependency, not the hardware provider. Installing a DLL from an unrelated SDK/provider revision does not establish compatibility with the running Windows kernel. From the clone root, run the following in PowerShell 5.1. Paths are examples for installed dependencies; use a new build directory. For an installed HIP SDK whose compiler is under `bin`, change `$compiler` accordingly. ```powershell $ErrorActionPreference = 'Stop' $vs = 'C:/Program Files/Microsoft Visual Studio/18/Community' Import-Module "$vs/Common7/Tools/Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath $vs -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64 -vcvars_ver=14.51 -no_logo' $hip = 'C:/sdk/rocm/Lib/site-packages/_rocm_sdk_devel' $core = 'C:/sdk/rocm/Lib/site-packages/_rocm_sdk_core/bin' $libraries = 'C:/sdk/rocm/Lib/site-packages/_rocm_sdk_libraries' $compiler = "$hip/lib/llvm/bin" $bitcode = "$hip/lib/llvm/amdgcn/bitcode" $nd = 'C:/sdk/NetworkDirect' $env:HIP_PATH = $hip $env:ROCM_PATH = $hip $env:PATH = "$compiler;$hip/bin;$env:PATH" $cmake = "$vs/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" $ninja = "$vs/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" & $cmake -S . -B build-hip -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" ` '-DCMAKE_BUILD_TYPE=Release' "-DCMAKE_C_COMPILER=$compiler/clang.exe" ` "-DCMAKE_CXX_COMPILER=$compiler/clang++.exe" "-DCMAKE_PREFIX_PATH=$hip" ` "-DCMAKE_CXX_FLAGS=--rocm-path=$hip --rocm-device-lib-path=$bitcode" ` '-DGGML_HIP=ON' '-DGGML_VULKAN=OFF' '-DGPU_TARGETS=gfx1151' ` '-DGGML_HIP_GRAPHS=ON' '-DGGML_HIP_NO_VMM=ON' '-DGGML_HIP_ROCWMMA_FATTN=OFF' ` '-DGGML_RPC=ON' '-DGGML_RPC_ND=ON' "-DGGML_RPC_ND_SDK=$nd" ` '-DGGML_BACKEND_DL=OFF' '-DLLAMA_BUILD_TESTS=ON' '-DLLAMA_BUILD_EXAMPLES=OFF' ` '-DLLAMA_BUILD_APP=OFF' '-DLLAMA_BUILD_MTMD=OFF' '-DLLAMA_BUILD_UI=OFF' ` '-DLLAMA_USE_PREBUILT_UI=OFF' '-DLLAMA_OPENSSL=OFF' if ($LASTEXITCODE) { throw 'Configure failed' } & $cmake --build build-hip --target llama-cli llama-server ggml-rpc-server test-rpc-graph-cache test-backend-ops --parallel 8 if ($LASTEXITCODE) { throw 'Build failed' } Copy-Item "$core/amdhip64_7.dll","$core/amd_comgr.dll" build-hip/bin/ if (Test-Path "$core/rocm_kpack.dll") { Copy-Item "$core/rocm_kpack.dll" build-hip/bin/ } $omp = Get-ChildItem "$vs/VC/Redist/MSVC" -Recurse -Filter libomp140.x86_64.dll | Where-Object { $_.FullName -match '\\x64\\Microsoft\.VC14\d\.OpenMP\.LLVM\\' } | Select-Object -First 1 if (!$omp) { throw 'Matching x64 LLVM OpenMP runtime not found' } Copy-Item $omp.FullName build-hip/bin/ $env:PATH = "$libraries/bin;$env:PATH" & ./build-hip/bin/llama-server.exe --list-devices if ($LASTEXITCODE) { throw 'Device enumeration failed' } & ./build-hip/bin/test-rpc-graph-cache.exe if ($LASTEXITCODE) { throw 'RPC policy check failed' } ``` Require `ROCm0` and `GRAPH_CACHE_POLICY_PASS`. Copy the complete `build-hip/bin` directory to the same runtime directory on all three hosts, and verify every file's SHA256 after transfer. Keep the matching hipBLAS/rocBLAS library tree, including `.kpack` data, on every host; copying only its visible DLLs is insufficient. Core HIP/COMGR/OpenMP DLLs must remain app-local so another installed runtime is not selected accidentally. Follow the dependencies' redistribution terms. Download all three Q4_K_M shards of [Qwen3-235B-A22B-Instruct-2507](https://huggingface.co/unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF/tree/437d6915c5c512869e4cf8b16b840bbe3fb172bc), verify their publisher hashes, and keep them together on the coordinator. Pass the first shard to `-m`. Weights are not included in this repository. Example triangle: coordinator `192.168.10.1` reaches worker A at `192.168.10.2`; coordinator `192.168.30.2` reaches worker B at `192.168.30.1`; A and B communicate directly using `192.168.20.1` and `192.168.20.2`. Substitute your actual topology consistently. A is RPC0, B is RPC1, and the coordinator's GPU is rank 2. Run from a fresh PowerShell on each host to avoid inherited experimental settings. On all three hosts, set process-local runtime/profile values: ```powershell $runtime = 'C:/llama-runtime' $env:PATH = 'C:/sdk/rocm-libraries/bin;' + $env:PATH $env:PAL_DISABLE_SDMA = '1' $env:GGML_ND_POLL_SPIN = '2000000' $env:GGML_RPC_MESH = '1' $env:GGML_RPC_MESH_WIRE = 'f16' $env:GGML_RPC_GRAPH_CACHE = '1' $env:GGML_RPC_EARLY_CLOSE = '1' $env:GGML_RPC_PACK_2D = '1' ``` Start worker A; for B change the local address to `192.168.30.1`: ```powershell $env:GGML_ND_ADDR = '192.168.10.2' $env:GGML_RPC_USE_COUNTS = '1' $env:GGML_RPC_GRAPH_GET_FUSE = '1' & "$runtime/ggml-rpc-server.exe" -H $env:GGML_ND_ADDR -p 50052 -d ROCm0 -c ``` Once both workers are listening, start the coordinator. Do not enable mirrored attention, KV-repeat experiments, or speculative decoding for this reference profile: ```powershell $env:GGML_RPC_MESH_PEER = '192.168.20.1:50050' $model = 'D:/models/Qwen3-235B-A22B-Instruct-2507-Q4_K_M-00001-of-00003.gguf' & "$runtime/llama-server.exe" -m $model --rpc '192.168.10.2:50052,192.168.30.1:50052' ` --device 'RPC0,RPC1,ROCm0' --split-mode tensor --tensor-split '1,1,1' ` -ngl 999 -c 4096 -b 512 -ub 256 -fa on --cache-type-k f16 --cache-type-v f16 ` --load-mode none --fit off --spec-type none --parallel 1 --cache-ram 0 ` --no-cache-prompt --ctx-checkpoints 0 --no-context-shift --temp 0 --seed 42 ` --host 127.0.0.1 --port 50190 --log-verbosity 4 --perf ``` Require two ND activations per host, full GPU offload, and worker log messages identifying both coordinator and peer links as ND. A functioning HTTP endpoint alone is not sufficient. Treat framing errors, mesh fallback, device loss, memory exhaustion, and unexpected native exits as failures. Stop the processes you launched after testing; these direct commands are not an unattended resource supervisor. The mesh uses a star for small partials and a ring for larger ones. `f16`/`bf16` wire formats reduce traffic but may change numerical results; select the same format everywhere. The current transport reposts consumed receives immediately. No deferred-repost switch is needed. Historical throughput used 1655 input and 128 output tokens, with warmup excluded and no prompt-cache reuse; it is not an exact-2048-input result or a performance guarantee. ### Tensor-parallel execution options The following opt-ins retain the alternative coordinator-centered execution path with two RPC workers and one local GPU device, in that order. Disable `GGML_RPC_MESH` when evaluating that path independently. Queued uploads and the addressing specialization below are Vulkan-specific; they are not required for the HIP/full-mesh profile above. | Variable | Purpose | | --- | --- | | `GGML_META_LOCAL_REDUCE=1`, `GGML_META_HOST_REDUCE=1` | Reduce eligible f32 partials at the coordinator, preserving `(rank 0 + rank 2) + rank 1` rounding order. | | `GGML_META_OVERLAP_READS=1`, `GGML_META_OVERLAP_WRITES=1` | Use persistent transfer threads; join each transfer before reusing graph state or scratch storage. | | `GGML_META_QUEUED_UPLOAD=1` | Queue the local Vulkan upload from separately owned host storage, reused only after synchronization. | | `GGML_RPC_GRAPH_GET_FUSE=1` | On workers, defer eligible graph synchronization until the following full-result read; drain before other operations, eviction or teardown. | | `GGML_RPC_USE_COUNTS=1` | Restore transmitted consumer counts on workers so backend fusion remains valid across graph segments. | | `GGML_RPC_PACK_2D=1` | Pack contiguous destination rows into bounded RPC uploads rather than sending each row separately. | | `GGML_VK_Q4_ADDRESS=1` | Select power-of-two addressing only for checked Q4_K/Q6_K expert shard shapes; other shapes keep the normal pipeline. | | `LLAMA_Q4_MIRROR_ATTN=1` | Replicate attention weights/KV for the checked three-device Qwen3-235B tensor split; experts remain split. This uses additional memory. | `GGML_RPC_GRAPH_CACHE` defaults on; set it to `0` for an uncached control. `GGML_RPC_EARLY_CLOSE=1` releases unused connections before backend shutdown. Speculative decoding uses the existing implementation: an explicitly local draft device must not inherit the target's tensor-split placement. These options require workload-specific numerical and performance validation; they are not a throughput guarantee. ### Troubleshooting The `GGML_RPC_DEBUG` environment variable controls the verbosity of the logs emitted by the RPC backend. It can be set on the server, on the client (e.g. `llama-cli`), or both. Larger values produce more detailed output: - unset / `0` - disabled (only warnings and errors are printed) - `1` - high-level events: connections, handshake, buffer allocations, graph computes, cache evictions - `2` - per-command trace: every RPC message sent/received, tensor transfers, cache hits/misses - `3` - fine detail: per-command timings, graph node dumps, transport byte counts Non-numeric values are treated as `1`. ```bash $ GGML_RPC_DEBUG=1 bin/ggml-rpc-server ``` > [!NOTE] > The debug levels are emitted as `ggml` debug records, which `llama.cpp` applications drop unless the > global verbosity threshold is raised. On the client, pass `-lv 5` together with `GGML_RPC_DEBUG`: ```bash $ GGML_RPC_DEBUG=2 bin/llama-cli -hf ggml-org/gemma-3-1b-it-GGUF -ngl 99 --rpc 192.168.88.10:50052 -lv 5 ```