From fa1e77cc6d9b82eeb9a0144a4cec8eccfe603aa4 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Sun, 28 Jul 2024 02:03:53 +0300 Subject: [PATCH] Fix Full VAE previews --- modules/processing_helpers.py | 6 +++--- modules/sd_samplers_common.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/processing_helpers.py b/modules/processing_helpers.py index 110b32b93..2ffdc7b7a 100644 --- a/modules/processing_helpers.py +++ b/modules/processing_helpers.py @@ -196,9 +196,9 @@ def decode_first_stage(model, x, full_quality=True): try: if full_quality: if hasattr(model, 'decode_first_stage'): - x_sample = model.decode_first_stage(x) + x_sample = model.decode_first_stage(x) * 0.5 + 0.5 elif hasattr(model, 'vae'): - x_sample = model.vae(x) + x_sample = processing_vae.vae_decode(latents=x, model=model, output_type='np', full_quality=full_quality) else: x_sample = x shared.log.error('Decode VAE unknown model') @@ -206,7 +206,7 @@ def decode_first_stage(model, x, full_quality=True): from modules import sd_vae_taesd x_sample = torch.zeros((len(x), 3, x.shape[2] * 8, x.shape[3] * 8), dtype=devices.dtype_vae, device=devices.device) for i in range(len(x_sample)): - x_sample[i] = sd_vae_taesd.decode(x[i]) + x_sample[i] = sd_vae_taesd.decode(x[i]) * 0.5 + 0.5 except Exception as e: x_sample = x shared.log.error(f'Decode VAE: {e}') diff --git a/modules/sd_samplers_common.py b/modules/sd_samplers_common.py index 54a38cf55..b49e981f1 100644 --- a/modules/sd_samplers_common.py +++ b/modules/sd_samplers_common.py @@ -61,7 +61,7 @@ def single_sample_to_image(sample, approximation=None): if approximation == 2: # TAESD x_sample = sd_vae_taesd.decode(sample) x_sample = (1.0 + x_sample) / 2.0 # preview requires smaller range - elif sd_cascade: + elif sd_cascade and not approximation == 3: x_sample = sd_vae_stablecascade.decode(sample) elif approximation == 0: # Simple x_sample = sd_vae_approx.cheap_approximation(sample) * 0.5 + 0.5 @@ -70,7 +70,7 @@ def single_sample_to_image(sample, approximation=None): if shared.sd_model_type == "sdxl": x_sample = x_sample[[2,1,0], :, :] # BGR to RGB elif approximation == 3: # Full VAE - x_sample = processing.decode_first_stage(shared.sd_model, sample.unsqueeze(0))[0] * 0.5 + 0.5 + x_sample = processing.decode_first_stage(shared.sd_model, sample.unsqueeze(0))[0] else: warn_once(f"Unknown latent decode type: {approximation}") return Image.new(mode="RGB", size=(512, 512))