Unverified Commit 127ab911 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub
Browse files

Merge pull request #12514 from catboxanon/feat/batch-encode

Encode batch items individually to significantly reduce VRAM
parents d53f3b55 822597db
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -92,6 +92,14 @@ def images_tensor_to_samples(image, approximation=None, model=None):
            model = shared.sd_model
            model = shared.sd_model
        image = image.to(shared.device, dtype=devices.dtype_vae)
        image = image.to(shared.device, dtype=devices.dtype_vae)
        image = image * 2 - 1
        image = image * 2 - 1
        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))
            x_latent = model.get_first_stage_encoding(model.encode_first_stage(image))


    return x_latent
    return x_latent