From 4ae1515f14d338a347fdf8f647e062f5bc17d196 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Sun, 19 May 2024 17:42:35 -0400 Subject: [PATCH] Slightly faster latent2rgb previews. --- latent_preview.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/latent_preview.py b/latent_preview.py index 12927647..05d750e2 100644 --- a/latent_preview.py +++ b/latent_preview.py @@ -37,12 +37,13 @@ class Latent2RGBPreviewer(LatentPreviewer): self.latent_rgb_factors = torch.tensor(latent_rgb_factors, device="cpu") def decode_latent_to_preview(self, x0): - latent_image = x0[0].permute(1, 2, 0).cpu() @ self.latent_rgb_factors + self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device) + latent_image = x0[0].permute(1, 2, 0) @ self.latent_rgb_factors latents_ubyte = (((latent_image + 1) / 2) .clamp(0, 1) # change scale from -1..1 to 0..1 .mul(0xFF) # to 0..255 - .byte()).cpu() + ).to(device="cpu", dtype=torch.uint8, non_blocking=True) return Image.fromarray(latents_ubyte.numpy())