Skip to content

Commit

Permalink
add an option to choose how to combine hires fix and refiner
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Aug 30, 2023
1 parent 1ac11b3 commit 87cca02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
18 changes: 6 additions & 12 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,18 +1148,12 @@ def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subs
else:
decoded_samples = None

current = shared.sd_model.sd_checkpoint_info
try:
if self.hr_checkpoint_info is not None:
self.sampler = None
sd_models.reload_model_weights(info=self.hr_checkpoint_info)
devices.torch_gc()

return self.sample_hr_pass(samples, decoded_samples, seeds, subseeds, subseed_strength, prompts)
finally:
self.sampler = None
sd_models.reload_model_weights(info=current)
devices.torch_gc()
with sd_models.SkipWritingToConfig():
sd_models.reload_model_weights(info=self.hr_checkpoint_info)

devices.torch_gc()

return self.sample_hr_pass(samples, decoded_samples, seeds, subseeds, subseed_strength, prompts)

def sample_hr_pass(self, samples, decoded_samples, seeds, subseeds, subseed_strength, prompts):
if shared.state.interrupted:
Expand Down
13 changes: 11 additions & 2 deletions modules/sd_samplers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,17 @@ def apply_refiner(cfg_denoiser):
if refiner_checkpoint_info is None or shared.sd_model.sd_checkpoint_info == refiner_checkpoint_info:
return False

if getattr(cfg_denoiser.p, "enable_hr", False) and not cfg_denoiser.p.is_hr_pass:
return False
if getattr(cfg_denoiser.p, "enable_hr", False):
is_second_pass = cfg_denoiser.p.is_hr_pass

if opts.hires_fix_refiner_pass == "first pass" and is_second_pass:
return False

if opts.hires_fix_refiner_pass == "second pass" and not is_second_pass:
return False

if opts.hires_fix_refiner_pass != "second pass":
cfg_denoiser.p.extra_generation_params['Hires refiner'] = opts.hires_fix_refiner_pass

cfg_denoiser.p.extra_generation_params['Refiner'] = refiner_checkpoint_info.short_title
cfg_denoiser.p.extra_generation_params['Refiner switch at'] = refiner_switch_at
Expand Down
1 change: 1 addition & 0 deletions modules/shared_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"upcast_attn": OptionInfo(False, "Upcast cross attention layer to float32"),
"randn_source": OptionInfo("GPU", "Random number generator source.", gr.Radio, {"choices": ["GPU", "CPU", "NV"]}, infotext="RNG").info("changes seeds drastically; use CPU to produce the same picture across different videocard vendors; use NV to produce same picture as on NVidia videocards"),
"tiling": OptionInfo(False, "Tiling", infotext='Tiling').info("produce a tileable picture"),
"hires_fix_refiner_pass": OptionInfo("second pass", "Hires fix: which pass to enable refiner for", gr.Radio, {"choices": ["first pass", "second pass", "both passes"]}, infotext="Hires refiner"),
}))

options_templates.update(options_section(('sdxl', "Stable Diffusion XL"), {
Expand Down

0 comments on commit 87cca02

Please sign in to comment.