mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-04 05:45:05 +08:00
Encode batches separately
Significantly reduces VRAM. This makes encoding more inline with how decoding currently functions.
This commit is contained in:
parent
da80d649fd
commit
822597db49
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user