aboutsummaryrefslogtreecommitdiffstats
path: root/modules/sd_samplers_common.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-08-13 13:41:07 +0000
committerGitHub <noreply@github.com>2023-08-13 13:41:07 +0000
commit127ab9114f364b0af1f224a5eae7b43e8d4e2ddf (patch)
treead7e1151e24511bdad6735bda878bc6a690890e2 /modules/sd_samplers_common.py
parentd53f3b5596bed10127b7f63d52d09d7df774993a (diff)
parent822597db49218de17e105e62075096284dfcfd41 (diff)
downloadstable-diffusion-webui-gfx803-127ab9114f364b0af1f224a5eae7b43e8d4e2ddf.tar.gz
stable-diffusion-webui-gfx803-127ab9114f364b0af1f224a5eae7b43e8d4e2ddf.tar.bz2
stable-diffusion-webui-gfx803-127ab9114f364b0af1f224a5eae7b43e8d4e2ddf.zip
Merge pull request #12514 from catboxanon/feat/batch-encode
Encode batch items individually to significantly reduce VRAM
Diffstat (limited to 'modules/sd_samplers_common.py')
-rw-r--r--modules/sd_samplers_common.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/sd_samplers_common.py b/modules/sd_samplers_common.py
index d2fb21f4..07fc4434 100644
--- a/modules/sd_samplers_common.py
+++ b/modules/sd_samplers_common.py
@@ -92,7 +92,15 @@ def images_tensor_to_samples(image, approximation=None, model=None):
model = shared.sd_model
image = image.to(shared.device, dtype=devices.dtype_vae)
image = image * 2 - 1
- x_latent = model.get_first_stage_encoding(model.encode_first_stage(image))
+ if len(image) > 1:
+ x_latent = torch.stack([
+ model.get_first_stage_encoding(
+ model.encode_first_stage(torch.unsqueeze(img, 0))
+ )[0]
+ for img in image
+ ])
+ else:
+ x_latent = model.get_first_stage_encoding(model.encode_first_stage(image))
return x_latent