You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/backend.md
+61-20Lines changed: 61 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,32 +126,70 @@ Direct ("immediately") LoRA application cannot patch row-split tensors; with
126
126
explicit `--lora-apply-mode immediately` skips the split tensors with a
127
127
warning.
128
128
129
-
## Automatic placement (`--auto-fit`)
129
+
## Automatic placement (`--auto-fit on|off`)
130
130
131
-
`--auto-fit` derives the `diffusion` / `te` / `vae` placements from the model
132
-
metadata and the per-device memory budgets, then feeds them into the same
133
-
backend assignment mechanism described above (the chosen specs are printed).
134
-
`--backend` and `--params-backend` are ignored while auto-fit is enabled.
131
+
`--auto-fit` requires `on` or `off` and defaults to `on` when omitted.
132
+
Explicit `--backend` or `--params-backend` assignments disable auto-fit,
133
+
regardless of argument order, even with `--auto-fit on`.
134
+
135
+
When enabled, auto-fit uses one GPU for `diffusion` / `te` / `vae` computation. It chooses
136
+
the GPU with the largest available memory budget (the first device on a tie),
137
+
then derives parameter placements from the model metadata and the remaining
138
+
memory budgets. The chosen backend specifications are printed.
135
139
136
140
```shell
137
-
sd-cli -m model.safetensors -p "a cat" --auto-fit
138
-
sd-cli -m model.safetensors -p "a cat" --auto-fit --max-vram cuda0=8,cuda1=14
139
-
sd-cli -m model.safetensors -p "a cat" --auto-fit --split-mode row
141
+
sd-cli -m model.safetensors -p "a cat" --auto-fit on
142
+
sd-cli -m model.safetensors -p "a cat" --auto-fit on --max-vram cuda0=8,cuda1=14
143
+
sd-cli -m model.safetensors -p "a cat" --auto-fit off
140
144
```
141
145
142
146
Budgets reuse `--max-vram`: a positive per-device value caps what auto-fit
143
147
plans with on that device, a negative value means "free memory minus that many
144
148
GiB", and with no budget set each device's free memory minus a 512 MiB margin
145
-
is used. (The same values still drive graph-cut segmented execution for
146
-
modules that end up on a single device.)
147
-
148
-
When everything fits resident, components are simply spread across the
149
-
available GPUs. When it does not, auto-fit switches to time-share mode: the
150
-
heavy components get `disk` params residency (loaded for their phase, freed
151
-
after), and a component too large for any single device is split across all
152
-
GPUs with the layer/row split mechanism (`--split-mode` selects which, layer
153
-
by default). Components that fit nowhere fall back to the CPU. If a VAE decode
154
-
still runs out of memory, tiling is enabled and the decode retried once.
149
+
is used. These resolved GPU budgets, including the safety margin, also drive
150
+
the runner's graph-cut capacity checks.
151
+
152
+
Components are considered in `diffusion`, `te`, `vae` order so that repeatedly
153
+
used diffusion weights have priority. Each component's weights use the first
154
+
storage location with enough remaining budget:
155
+
156
+
1. The main GPU, leaving estimated space for computation and weight staging.
157
+
2. CPU RAM, reserving the larger of 2 GiB or 10% of available RAM for other work.
158
+
3. Another GPU, choosing the one with the largest remaining budget that fits.
159
+
4. Disk, reloading weights on demand.
160
+
161
+
GPU cache space follows the same component priority. Before a lower-priority
162
+
component can become permanently resident, the planner leaves room for the full
163
+
weights and estimated compute space of higher-priority offloaded components.
164
+
If offloaded diffusion already needs the entire main GPU budget, TE and VAE also
165
+
use offloaded parameters. Their GPU copies can then be released after their
166
+
phases, leaving more room to reuse diffusion weights across sampling steps.
167
+
CPU parameter residency allows GPU weight caching; it does not force every
168
+
weight to be copied again at every step.
169
+
170
+
RAM and GPU budgets are shared across components. Each component uses a single
171
+
parameter backend; several other GPUs' capacities are not combined to store
172
+
one component. If available RAM cannot be queried, RAM residency is skipped.
173
+
Other GPUs store weights only: weights are copied to the main GPU for execution.
174
+
Auto-fit does not select multi-GPU layer/row computation, so `--split-mode` does
175
+
not change its placements. Use explicit backend assignments for multi-GPU
176
+
computation.
177
+
178
+
For example, a diffusion model whose full weights exceed the main GPU's budget
179
+
can use `--backend diffusion=cuda0 --params-backend diffusion=cpu` when RAM is
180
+
sufficient. Automatic graph segmentation can then load the required weights
181
+
for each segment and reclaim idle GPU copies. `--disable-segmented-compute`
182
+
still disables segmentation.
183
+
184
+
Initial compute reserves are estimates (2 GiB for diffusion and text encoders,
185
+
1 GiB for VAE); higher-priority placements also leave staging space for the
186
+
largest weight tensor of each lower-priority offloaded component. Actual segment
187
+
weights, compute buffers and caches must
188
+
still fit the runner's capacity checks. Offloading weights does not guarantee
189
+
that every resolution or frame count will fit, and auto-fit does not change a
190
+
component to CPU computation solely because its full weights exceed VRAM.
191
+
If a VAE decode fails, auto-fit retries with spatial tiling; supported video
192
+
decoders try temporal tiling first and can then add spatial tiling.
155
193
156
194
## Modules
157
195
@@ -203,7 +241,7 @@ sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend disk
203
241
204
242
This runs all modules on `cuda0`, reloads parameters from the model file as needed, and releases those parameter buffers after use.
205
243
206
-
`disk` is never selected implicitly. If `--params-backend` is not set, parameters use the runtime backend.
244
+
Outside `--auto-fit`, `disk` is never selected implicitly. If `--params-backend` is not set, parameters use the runtime backend.
207
245
208
246
Per-module assignments can be mixed:
209
247
@@ -252,4 +290,7 @@ The example CLI/server still accepts these older CPU placement flags as compatib
252
290
253
291
Because this default is inserted first, later explicit `--params-backend` entries can still override it, for example `--offload-to-cpu --params-backend te=disk` keeps non-TE parameters on CPU and reloads TE parameters from disk.
254
292
255
-
Library callers should set `backend` and `params_backend` directly. The old CPU/offload fields are no longer part of the C API. Explicit `--backend` and `--params-backend` assignments are preferred for new commands.
293
+
Library callers should set `backend` and `params_backend` directly. `sd_ctx_params_init()`
294
+
enables `auto_fit` by default; nonempty `backend` or `params_backend` assignments disable it.
295
+
The old CPU/offload fields are no longer part of the C API. Explicit `--backend` and
296
+
`--params-backend` assignments are preferred for new commands.
0 commit comments