Skip to content

Commit 3cf8b3b

Browse files
committed
feat(stablediffusion-ggml): distributed RPC across ggml workers
Enable the ggml RPC backend (-DSD_RPC=ON) so image generation can be sharded across remote rpc-server workers. The ggml rpc-server is backend-agnostic, so this reuses the exact same worker pool as the llama.cpp backend - one set of `local-ai worker llama-cpp-rpc` / `p2p-llama-cpp-rpc` workers accelerates both text and image generation. RPC servers are selected by precedence: - the explicit `rpc_servers` option, else - the LLAMACPP_GRPC_SERVERS env var, which LocalAI's p2p worker mode populates automatically with discovered workers (the backend inherits it from the parent process env), so distributed image generation needs no per-model configuration. Documented manual and p2p setup in the image-generation guide. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-8 [Claude Code]
1 parent bd083a2 commit 3cf8b3b

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

backend/go/stablediffusion-ggml/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ STABLEDIFFUSION_GGML_VERSION?=5a34bc7f6e0621dd2f899daa64476eac667d7ed3
1212

1313
CMAKE_ARGS+=-DGGML_MAX_NAME=128
1414

15+
# Enable the ggml RPC backend so generation can be sharded across remote
16+
# rpc-server workers (the same backend-agnostic ggml rpc-server used by the
17+
# llama.cpp backend). Servers are selected via the `rpc_servers` option or the
18+
# LLAMACPP_GRPC_SERVERS env var (populated automatically in p2p worker mode).
19+
CMAKE_ARGS+=-DSD_RPC=ON
20+
1521
ifeq ($(NATIVE),false)
1622
CMAKE_ARGS+=-DGGML_NATIVE=OFF
1723
endif

backend/go/stablediffusion-ggml/cpp/gosd.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,18 @@ int load_model(const char *model, char *model_path, char* options[], int threads
638638
if (keep_control_net_on_cpu) prepend_spec(backend_spec, "controlnet=cpu");
639639
if (!backend_spec.empty()) ctx_params.backend = backend_spec.c_str();
640640
if (!params_backend_spec.empty()) ctx_params.params_backend = params_backend_spec.c_str();
641-
if (strlen(rpc_servers_arg) > 0) ctx_params.rpc_servers = rpc_servers_arg;
641+
// RPC servers: prefer the explicit option, otherwise fall back to the
642+
// LLAMACPP_GRPC_SERVERS env var. LocalAI's p2p worker mode populates that
643+
// var with discovered ggml rpc-server workers (shared with the llama.cpp
644+
// backend), so distributed image generation works with no extra config.
645+
if (strlen(rpc_servers_arg) > 0) {
646+
ctx_params.rpc_servers = rpc_servers_arg;
647+
} else {
648+
const char* env_rpc_servers = std::getenv("LLAMACPP_GRPC_SERVERS");
649+
if (env_rpc_servers != NULL && strlen(env_rpc_servers) > 0) {
650+
ctx_params.rpc_servers = env_rpc_servers;
651+
}
652+
}
642653
// max_vram: GiB budget or per-backend spec for graph-cut segmented param
643654
// offload ("0" = disabled, "-1" = auto). stream_layers only has effect when
644655
// max_vram is set.

docs/content/features/image-generation.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ options:
107107
`vae_decode_only` is still accepted for backwards compatibility but is now a no-op: upstream removed the flag and the model decides automatically.
108108
{{% /alert %}}
109109

110+
#### Distributed inference (RPC workers)
111+
112+
The `stablediffusion-ggml` backend can offload computation to remote `ggml` RPC workers, sharding a model that does not fit on a single machine. It reuses the **same backend-agnostic `rpc-server` workers as the llama.cpp backend**, so one worker pool can serve both.
113+
114+
**Manual:** point the model at running workers with the `rpc_servers` option:
115+
116+
```yaml
117+
options:
118+
- "rpc_servers:192.168.1.10:50052,192.168.1.11:50052"
119+
```
120+
121+
Start a worker on each remote machine the same way you would for llama.cpp:
122+
123+
```bash
124+
local-ai worker llama-cpp-rpc --llama-cpp-args="--host 0.0.0.0 --port 50052"
125+
```
126+
127+
**Automatic (peer-to-peer):** when LocalAI runs in [p2p worker mode]({{%relref "features/distributed_inferencing" %}}), discovered workers are published in the `LLAMACPP_GRPC_SERVERS` environment variable. The image-generation backend reads that variable automatically (when `rpc_servers` is not set), so the same `local-ai worker p2p-llama-cpp-rpc` workers used for text generation also accelerate image generation - no per-model configuration needed.
128+
129+
By default the RPC devices join the pool and participate in placement; combine with the `backend` / `params_backend` options above to pin specific components to them (e.g. `backend:diffusion=rpc0`).
130+
110131

111132
### Diffusers
112133

0 commit comments

Comments
 (0)