# Pool GPUs across machines (Tier-1 Trusted-Circle)

When a model is too large for one machine's memory, LUCID's **Discrete Slice Quorum** splits it across machines you personally trust over Noise-encrypted libp2p tunnels—with no manual SSH port forwarding and no hand-tuned split ratios required.

> [!WARNING]
> **SSH-equivalent trust boundary:** Enabling `cluster_enabled = true` lets explicitly enrolled circle peers connect to a loopback `ggml-rpc-server` on your GPU over `/phase/shard-rpc/1.0.0`. Only enable Tier-1 GPU pooling among machines you own or trust at the OS level. Tier-2 `UntrustedSpotChecked` sharding is **not implemented** and fails closed (`403 Forbidden`).

## Discrete Slice Quorum (how pooling works)

Instead of making you guess comma-separated layer ratios for every model and machine, LUCID treats each local `llama.cpp` model as a set of uniform **~3 GiB slices**:

1. **Uniform ~3 GiB slices (weights + KV cache):** LUCID inspects the GGUF header for layer weights and KV-cache geometry at your active context window (`--llama-ctx-size` + whether **Quantized KV Cache (`q8_0`)** is enabled), divides total layer + KV memory by a `3 GiB` target (up to `128` slices, or your per-model `cluster_slice_overrides` of `2..=16`), and adds a 10% safety margin per slice plus coordinator fixed overhead (embeddings, output head, and `512 MiB` runtime headroom).
2. **Quorum-gated availability:** A sliced model stays **hidden from `/api/tags` and `/v1/models`**—and direct requests to `/api/chat`, `/api/generate`, or `/v1/chat/completions` return **`503 Service Unavailable`** with **`Retry-After: 5`** and a `cluster quorum not met` message—until **100% of its required slices are online**. In LUCID Desktop, **Cluster → Slice Quorum** shows live progress (for example, **`7 / 10 slices online — waiting for 3 more`**) and a progress bar; as soon as the missing helpers come online, the model transitions to **`10 / 10 slices ready`** and appears automatically.
3. **Local-first, fewest-helpers automatic packing:** Your coordinator always keeps as many slices as fit locally first (it must fit fixed overhead plus at least 1 slice so the output head stays on the coordinator), then fills only the remaining slices from the largest online helpers first. Models that fit entirely on your coordinator run **100% locally** with zero helpers—even while cluster mode is enabled.
4. **Live progress in Activity Monitor:** Open **Monitor** (`Metrics` or `Flow` view) to see live slice counts on every node (`Helper 1 · 2 slices`, `This Device · METAL`, and the quorum pill `10 / 10 slices`) plus encrypted TX/RX bandwidth—strictly metadata-only (never PeerIds, IPs, or prompts).

### Controlling helper memory budget (`Auto` vs explicit cap)

Every helper machine controls how much GPU or unified memory it offers to trusted coordinators:

- In LUCID Desktop, open **Cluster → Slice Quorum & Helper Budget → Share up to X GB as helper** (or **Allocation**) and pick **`Auto`**, a preset, or **`Custom (GB)…`** (`1–1024 GB`).
- **`Auto` (default):** Automatically offers the machine's conservative safe working set (`recommended_max_model_bytes`: 65% unified RAM on Metal, 80% VRAM on CUDA) minus **`1 GiB` headroom**.
- **Explicit cap (`cluster_helper_budget_bytes`):** Honored up to the machine's hardware safety ceiling (`max_memory_budget_bytes`: **75% unified RAM on Metal**, **90% VRAM on CUDA**, never exceeding `1 TiB`). Budget changes apply **live** without restarting `lucidd`.
- **Slice distribution & cellular roaming:** Choose **Local First** (keeps models local whenever they fit, spilling only oversized models to helpers) or **Spread Across GPUs** (distributes slices proportionally across all online GPUs). Toggle **Pause GPU slicing on cellular/relayed** to exclude helpers reachable only over relayed WAN circuits when roaming off LAN.
- **Automatic idle unload & macOS AC sleep guard:** Warm `llama-server` models automatically unload after **10 minutes** of inactivity (never interrupting active streams), releasing both local GPU RAM and remote `ggml-rpc-server` buffers. On macOS, `lucidd` holds an AC-power-only idle sleep assertion while sharing or clustering so plugged-in Mac helpers stay awake in the pool (display still sleeps; battery sleep is untouched).

### Idle-only repacking and manual Rebalance

- **No mid-session disruption:** If an extra helper joins while a model is already **ready**, LUCID does **not** interrupt active chats or reload weights mid-session.
- **Automatic idle repacking:** Once no generation is in flight on that model and it has been **idle for more than 10 minutes** (`IDLE_REPACK_AFTER = 600s`), LUCID automatically repacks it onto a new plan only if the new plan uses **fewer helpers**.
- **Manual Rebalance:** Click **Rebalance** in **Cluster → Slice Quorum** (or call [`POST /api/lucid/cluster/rebalance`](http-api.md#post-apilucidclusterrebalance)) to poll helpers immediately and repack every sliced model onto the best current plan right away.
- **Helper drop:** If a helper in an active plan disconnects or stops offering enough memory, LUCID immediately replans onto remaining helpers (or moves the model back to `waiting`) and unloads the stale plan.

### Fit more context per slice with Quantized KV Cache (`q8_0`)

Large context windows (`32K–256K`) inflate each slice's KV-cache footprint and increase the number of slices needed. Turn on **Settings & Safety → Quantized KV Cache (`q8_0`)** (off by default; CLI `--llama-kv-cache-q8`) to store `llama-server`'s KV cache in `q8_0` (`--cache-type-k q8_0 --cache-type-v q8_0`), cutting KV-cache RAM roughly in half so more context fits per slice. Desktop safely rolls back to your previous setting if the engine fails to restart.

## Technical protocol & safety guarantees

### Point-to-point capacity offers (`/phase/capacity-offer/1.0.0`)

Coordinators never broadcast what model they plan to run. Instead, the quorum engine polls each configured helper directly over Noise-encrypted **`/phase/capacity-offer/1.0.0`**:

- **Zero model leakage:** The coordinator sends only a schema version and a fresh 32-byte random nonce (`CapacityOfferRequest`, ≤ `512 B`)—no model ID, alias, or context size.
- **Signed, short-lived offers:** An enrolled helper whose `cluster_enabled = true` returns a `60s` Ed25519-signed `SignedCapacityOffer` bound to `helper_peer_id`, `coordinator_peer_id`, the echoed nonce, `usable_bytes`, `backend`, `devices`, `serving`, `lucid_version`, and `rpc_runtime_sha256`.
- **Stability hysteresis & runtime matching:** A helper counts toward quorum after **2 consecutive valid serving offers** (`6s` pending poll interval; `15s` steady poll interval; `5s` helper-side rate limit). It drops after **3 missed polls**, or immediately on refusal (`cluster_enabled = false`, paused, not enrolled), runtime/protocol version mismatch (`update_required`), or live tunnel loss. A helper that fails to attach during model load is excluded for **10 minutes** (`600s`); an unattributed load failure backs off for **30 seconds**.

### Single-GPU eligibility guard

Because `llama.cpp`'s `--tensor-split` assigns one weight per remote `--rpc` endpoint plus one weight for the coordinator, every participant of a sliced plan must expose **exactly one GPU** (`devices == 1`, non-CPU backend):

- CPU-only or multi-GPU helpers are refused for automatic slicing (`refused`) so layer boundaries never silently drift.
- A coordinator without exactly one GPU serves only models that fit locally; models needing helpers show as **`Blocked`** with an explicit reason.

### Honest labels and `X-Lucid-Local-Only` enforcement

- Every response from a model whose active plan offloads slices to helpers reports `X-Lucid-Routed-Via: trusted-circle-sharded` and `X-Lucid-Trust-Label: trusted-circle-sharded`.
- Requests carrying `X-Lucid-Local-Only: true` (or the Desktop **Local Only** toggle) are enforced **per model** when slice quorum is active: a model whose active plan uses helpers is refused (`503`) because activations leave your machine, while a smaller model whose active plan fits 100% locally still runs locally with `X-Lucid-Trust-Label: local`.

## Zero-CLI helper setup

If you installed `llama.cpp b12651` via LUCID Desktop (or placed the official `b12651` archive binaries in one folder), the helper node needs **no extra CLI flags**:

1. Enroll the coordinator's identity with the helper via a normal `lucid://join/...` invitation (or list the coordinator's 64-hex Ed25519 public key in `policy.toml`'s `authorized_submitters`).
2. Toggle **Participate in Tier 1** (`cluster_enabled = true`) in Desktop's **Trusted-Circle Cluster** modal or via `POST /api/lucid/settings`.
3. Optionally cap how much memory to contribute under **Share up to X GB as helper** (default **`Auto`**).

What `ManagedShardRpcProvider` enforces automatically on the helper:

- **SHA-256 pinning:** Verifies `ggml-rpc-server` against the 5 pinned `b12651` platform digests before arming and before every spawn, plus ownership and non-world/group-writable checks on the binary, parent directory, and `libggml*` libraries.
- **No orphan processes:** Wraps `ggml-rpc-server` in a stdin-EOF lifeline guard so even `SIGKILL` of `lucidd` immediately kills the RPC server.
- **Strict enrollment-only admission:** Drops non-enrolled peers *before reading a single byte* (`allow_unauthenticated_jobs` is **never** honored for `/phase/shard-rpc/1.0.0`).
- **Live revocation:** Re-checks `cluster_enabled`, `!manual_pause`, and enrollment every 250 ms. Turning `cluster_enabled` off immediately tears down live tunnels and kills `ggml-rpc-server`.

## Coordinator setup

### Desktop app (recommended — automatic Slice Quorum)

1. Open **Cluster** in the top bar of LUCID Desktop.
2. Turn on **Participate in Tier 1** (`cluster_enabled`) on both the coordinator and each enrolled helper machine.
3. Leave **Auto-Split (Slice Quorum)** **On** (`cluster_auto_split = true`, the default).
4. Under **GPU helpers for sliced chat**, check the enrolled helper machines you want to pool with and click **Save Helpers & Restart Service**. LUCID persists `cluster_rpc_peers` into `node.toml`, restarts its local sidecar cleanly (skipping GGUF re-hashing), starts polling helpers over `/phase/capacity-offer/1.0.0`, and displays live slice progress in **Cluster → Slice Quorum** and **Monitor → Flow**.

### Manual split override & command line

Automatic slice planning activates whenever `cluster_enabled = true`, `cluster_auto_split = true`, no manual `cluster_tensor_split` is set, and no CLI RPC offload flags override `node.toml`.

If you want fixed manual split weights instead, enter a comma-separated split in Desktop (setting `cluster_tensor_split` automatically turns off `cluster_auto_split`; toggling **Auto-Split** back on clears `cluster_tensor_split`), or start `lucidd` with explicit CLI flags:

```bash
lucidd \
  --mode worker \
  --worker llama-cpp \
  --model-dir ~/Models \
  --llama-server-binary /absolute/path/to/llama-server \
  --llama-rpc-peers 12D3KooWHelperPeerIdHere \
  --llama-tensor-split 10,90 \
  --llama-kv-cache-q8
```

> [!IMPORTANT]
> **`--llama-tensor-split` is RPC-first:** `llama-server` assigns weights to remote `--rpc` devices *first* (in the order listed), followed by local GPUs. In the manual example above, `10,90` puts 10% of layers on the remote helper peer and 90% on the coordinator's local GPU. Under automatic Slice Quorum, LUCID computes exact layer-boundary weights (accounting for `llama.cpp`'s extra output slot on the final coordinator device) automatically.

### Fail-fast helper verification & refusal of silent local fallback

Upstream `llama-server b12651` will silently drop an unreachable `--rpc` device and load all layers locally instead. `lucidd` verifies tunnel attachment on every planned helper, **fails fast** if any helper cannot attach (rather than hanging or falling back silently), excludes the failed helper for 10 minutes in Slice Quorum mode, and tracks attached tunnel generations across respawns—guaranteeing that a request labeled `trusted-circle-sharded` never silently ran locally or silently dropped a helper. Long-lived `/phase/shard-rpc/1.0.0` tunnels default to a `2h` idle ceiling while `15s` libp2p ping keepalives evict dead helpers promptly.

### Manual loopback bridge (advanced)

If you prefer to manage `ggml-rpc-server` yourself on the helper, pass `--shard-rpc-bridge-port <PORT>` on the helper (disabling auto-management) or `--llama-rpc-servers 127.0.0.1:<PORT>` on the coordinator for local loopback bridges.

## Inspecting GGUF layers and planning splits

Use the `lucidd cluster` subcommands to inspect any local GGUF file's layer count and generate a coordinator-signed `SignedShardPartitionPlan`:

```bash
# Inspect GGUF architecture, layer count, and size (read-only)
lucidd cluster inspect ~/Models/gemma-4-12B-it-QAT-Q4_0.gguf

# Check live daemon cluster status
lucidd cluster status

# Generate and verify a signed Tier-1 partition plan across >=2 peers
lucidd cluster plan \
  --model gemma-4-12b \
  --gguf ~/Models/gemma-4-12B-it-QAT-Q4_0.gguf \
  --peer mac-main:96:metal \
  --peer mac-helper:32:metal
```

For multi-stage pipeline execution with chained Ed25519 stage receipts (`/phase/shard-stage/1.0.0`), see `POST /api/lucid/cluster/execute` in the [HTTP API reference](http-api.md#post-apilucidclusterexecute) and [Phase network protocols](protocols.md#phaseshard-stage100).
