KBaba7/llama.cpp
0
1## Overview2 3> [!IMPORTANT]4> This example and the RPC backend are currently in a proof-of-concept development stage. As such, the functionality is fragile and5> insecure. **Never run the RPC server on an open network or in a sensitive environment!**6 7The `rpc-server` allows running `ggml` backend on a remote host.8The RPC backend communicates with one or several instances of `rpc-server` and offloads computations to them.9This can be used for distributed LLM inference with `llama.cpp` in the following way:10 11```mermaid12flowchart TD13 rpcb<-->|TCP|srva14 rpcb<-->|TCP|srvb15 rpcb<-.->|TCP|srvn16 subgraph hostn[Host N]17 srvn[rpc-server]<-.->backend3["Backend (CUDA,Metal,etc.)"]18 end19 subgraph hostb[Host B]20 srvb[rpc-server]<-->backend2["Backend (CUDA,Metal,etc.)"]21 end22 subgraph hosta[Host A]23 srva[rpc-server]<-->backend["Backend (CUDA,Metal,etc.)"]24 end25 subgraph host[Main Host]26 local["Backend (CUDA,Metal,etc.)"]<-->ggml[llama-cli]27 ggml[llama-cli]<-->rpcb[RPC backend]28 end29 style hostn stroke:#66,stroke-width:2px,stroke-dasharray: 5 530```31 32Each host can run a different backend, e.g. one with CUDA and another with Metal.33You can also run multiple `rpc-server` instances on the same host, each with a different backend.34 35## Usage36 37On each host, build the corresponding backend with `cmake` and add `-DGGML_RPC=ON` to the build options.38For example, to build the CUDA backend with RPC support:39 40```bash41mkdir build-rpc-cuda42cd build-rpc-cuda43cmake .. -DGGML_CUDA=ON -DGGML_RPC=ON44cmake --build . --config Release45```46 47Then, start the `rpc-server` with the backend:48 49```bash50$ bin/rpc-server -p 5005251create_backend: using CUDA backend52ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no53ggml_cuda_init: CUDA_USE_TENSOR_CORES: yes54ggml_cuda_init: found 1 CUDA devices:55 Device 0: NVIDIA T1200 Laptop GPU, compute capability 7.5, VMM: yes56Starting RPC server on 0.0.0.0:5005257```58 59When using the CUDA backend, you can specify the device with the `CUDA_VISIBLE_DEVICES` environment variable, e.g.:60```bash61$ CUDA_VISIBLE_DEVICES=0 bin/rpc-server -p 5005262```63This way you can run multiple `rpc-server` instances on the same host, each with a different CUDA device.64 65 66On the main host build `llama.cpp` for the local backend and add `-DGGML_RPC=ON` to the build options.67Finally, when running `llama-cli`, use the `--rpc` option to specify the host and port of each `rpc-server`:68 69```bash70$ bin/llama-cli -m ../models/tinyllama-1b/ggml-model-f16.gguf -p "Hello, my name is" --repeat-penalty 1.0 -n 64 --rpc 192.168.88.10:50052,192.168.88.11:50052 -ngl 9971```72 73This way you can offload model layers to both local and remote devices.74 75 