fix control final resize

This commit is contained in:
Vladimir Mandic
2024-03-10 13:58:21 -04:00
parent 1869ec8ad6
commit 8620ba5310
4 changed files with 13 additions and 7 deletions
+2 -2
View File
@@ -112,7 +112,7 @@ def control_run(units: List[unit.Unit], inputs, inits, mask, unit_type: str, is_
# hires/refine defined outside of main init
p.enable_hr = enable_hr
p.hr_sampler_name = processing.get_sampler_name(hr_sampler_index)
p.hr_denoising_strength = hr_denoising_strength # TODO
p.hr_denoising_strength = hr_denoising_strength
p.hr_upscaler = hr_upscaler
p.hr_force = hr_force
p.hr_second_pass_steps = hr_second_pass_steps
@@ -472,7 +472,7 @@ def control_run(units: List[unit.Unit], inputs, inits, mask, unit_type: str, is_
p.init_images = [processed_image]
shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.IMAGE_2_IMAGE)
else:
p.init_hr(p.scale_by, p.resize_name)
p.init_hr(p.scale_by, p.resize_name, force=True)
shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.TEXT_2_IMAGE)
elif has_models: # actual control
p.is_control = True
+2 -2
View File
@@ -492,13 +492,13 @@ class StableDiffusionProcessingControl(StableDiffusionProcessingImg2Img):
def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts): # abstract
pass
def init_hr(self, scale = None, upscaler = None):
def init_hr(self, scale = None, upscaler = None, force = False):
scale = scale or self.scale_by
upscaler = upscaler or self.resize_name
if upscaler == 'None' or scale == 1.0:
return
self.is_hr_pass = True
self.hr_force = True
self.hr_force = force
self.hr_upscaler = upscaler
self.hr_upscale_to_x, self.hr_upscale_to_y = 8 * int(self.width * scale / 8), 8 * int(self.height * scale / 8)
# hypertile_set(self, hr=True)
+8 -2
View File
@@ -187,7 +187,11 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
generator = p.generator
else:
generator_device = devices.cpu if shared.opts.diffusers_generator_device == "CPU" else shared.device
generator = [torch.Generator(generator_device).manual_seed(s) for s in p.seeds]
try:
generator = [torch.Generator(generator_device).manual_seed(s) for s in p.seeds]
except Exception as e:
shared.log.error(f'Torch generator: seeds={p.seeds} device={generator_device} {e}')
generator = None
prompts, negative_prompts, prompts_2, negative_prompts_2 = fix_prompts(prompts, negative_prompts, prompts_2, negative_prompts_2)
parser = 'Fixed attention'
clip_skip = kwargs.pop("clip_skip", 1)
@@ -457,7 +461,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
# optional second pass
if p.enable_hr:
p.is_hr_pass = True
p.init_hr(p.hr_scale, p.hr_upscaler)
p.init_hr(p.hr_scale, p.hr_upscaler, force=p.hr_force)
prev_job = shared.state.job
# hires runs on original pipeline
@@ -472,6 +476,8 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
save_intermediate(latents=output.images, suffix="-before-hires")
shared.state.job = 'upscale'
output.images = resize_hires(p, latents=output.images)
if hasattr(p, 'task_args') and p.task_args.get('image', None) is not None: # replace input with output so it can be used by hires/refine
p.task_args['image'] = output.images
sd_hijack_hypertile.hypertile_set(p, hr=True)
latent_upscale = shared.latent_upscale_modes.get(p.hr_upscaler, None)
+1 -1
View File
@@ -347,7 +347,7 @@ options_templates.update(options_section(('sd', "Execution & Models"), {
"comma_padding_backtrack": OptionInfo(20, "Prompt padding", gr.Slider, {"minimum": 0, "maximum": 74, "step": 1, "visible": backend == Backend.ORIGINAL }),
"sd_checkpoint_cache": OptionInfo(0, "Cached models", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1, "visible": backend == Backend.ORIGINAL }),
"sd_vae_checkpoint_cache": OptionInfo(0, "Cached VAEs", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1, "visible": False}),
"sd_disable_ckpt": OptionInfo(False, "Disallow models in ckpt format"),
"sd_disable_ckpt": OptionInfo(False, "Disallow models in ckpt format", gr.Checkbox, {"visible": False}),
}))
options_templates.update(options_section(('cuda', "Compute Settings"), {