From a4b26e7ddbada41bb521a3c1aecf4707a50497b7 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 16 Mar 2025 13:25:26 -0400 Subject: [PATCH] fix hires with latent upscale Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + modules/processing_args.py | 2 ++ modules/processing_helpers.py | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 367a70c75..5386b3565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - fix `insightface` loader - fix remove vae for flux.1 - guard against git returining invalid timestamp + - fix hires with latent upscale - **IPEX** - add `--upgrade` to torch_command when using `--use-nightly` for *ipex* and *rocm* - add xpu to profiler diff --git a/modules/processing_args.py b/modules/processing_args.py index c0e201f77..261a996b0 100644 --- a/modules/processing_args.py +++ b/modules/processing_args.py @@ -298,6 +298,8 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:t p.init_images = kwargs['image'] if isinstance(kwargs['image'], Image.Image): p.init_images = [kwargs['image']] + if isinstance(kwargs['image'], torch.Tensor): + p.init_images = kwargs['image'] # handle remaining args for arg in kwargs: diff --git a/modules/processing_helpers.py b/modules/processing_helpers.py index a5abba6a2..8fffa8313 100644 --- a/modules/processing_helpers.py +++ b/modules/processing_helpers.py @@ -401,24 +401,24 @@ def resize_init_images(p): def resize_hires(p, latents): # input=latents output=pil if not latent_upscaler else latent if not torch.is_tensor(latents): shared.log.warning('Hires: input is not tensor') - first_pass_images = processing_vae.vae_decode(latents=latents, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.width, height=p.height) - return first_pass_images + decoded = processing_vae.vae_decode(latents=latents, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.width, height=p.height) + return decoded if (p.hr_upscale_to_x == 0 or p.hr_upscale_to_y == 0) and hasattr(p, 'init_hr'): shared.log.error('Hires: missing upscaling dimensions') - return first_pass_images + return decoded if p.hr_upscaler.lower().startswith('latent'): - resized_image = images.resize_image(p.hr_resize_mode, latents, p.hr_upscale_to_x, p.hr_upscale_to_y, upscaler_name=p.hr_upscaler, context=p.hr_resize_context) - return resized_image + resized = images.resize_image(p.hr_resize_mode, latents, p.hr_upscale_to_x, p.hr_upscale_to_y, upscaler_name=p.hr_upscaler, context=p.hr_resize_context) + return resized - first_pass_images = processing_vae.vae_decode(latents=latents, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.width, height=p.height) - resized_images = [] - for img in first_pass_images: - resized_image = images.resize_image(p.hr_resize_mode, img, p.hr_upscale_to_x, p.hr_upscale_to_y, upscaler_name=p.hr_upscaler, context=p.hr_resize_context) - resized_images.append(resized_image) + decoded = processing_vae.vae_decode(latents=latents, model=shared.sd_model, vae_type=p.vae_type, output_type='pil', width=p.width, height=p.height) + resized = [] + for image in decoded: + resize = images.resize_image(p.hr_resize_mode, image, p.hr_upscale_to_x, p.hr_upscale_to_y, upscaler_name=p.hr_upscaler, context=p.hr_resize_context) + resized.append(resize) devices.torch_gc() - return resized_images + return resized def fix_prompts(p, prompts, negative_prompts, prompts_2, negative_prompts_2):