Skip to content

Commit

Permalink
Merge pull request #12514 from catboxanon/feat/batch-encode
Browse files Browse the repository at this point in the history
Encode batch items individually to significantly reduce VRAM
  • Loading branch information
AUTOMATIC1111 authored Aug 13, 2023
2 parents d53f3b5 + 822597d commit 127ab91
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/sd_samplers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 127ab91

Please sign in to comment.