CFG and Distilled CFG for hiresfix (#1810)

This commit is contained in:
DenOfEquity
2024-09-13 15:01:40 +01:00
committed by GitHub
parent e55cde9b33
commit cb412b290b
5 changed files with 43 additions and 16 deletions

View File

@@ -420,6 +420,7 @@ class StableDiffusionProcessing:
return (
required_prompts,
self.distilled_cfg_scale,
self.hr_distilled_cfg,
steps,
hires_steps,
use_old_scheduling,
@@ -1156,6 +1157,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
hr_scheduler: str = None
hr_prompt: str = ''
hr_negative_prompt: str = ''
hr_cfg: float = 1.0
hr_distilled_cfg: float = 3.5
force_task_id: str = None
cached_hr_uc = [None, None, None]
@@ -1253,6 +1256,10 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
self.extra_generation_params["Hires prompt"] = get_hr_prompt
self.extra_generation_params["Hires negative prompt"] = get_hr_negative_prompt
self.extra_generation_params["Hires CFG Scale"] = self.hr_cfg
if shared.sd_model.use_distilled_cfg_scale:
self.extra_generation_params['Hires Distilled CFG Scale'] = self.hr_distilled_cfg
self.extra_generation_params["Hires schedule type"] = None # to be set in sd_samplers_kdiffusion.py
if self.hr_scheduler is None:
@@ -1494,8 +1501,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
if self.hr_c is not None:
return
hr_prompts = prompt_parser.SdConditioning(self.hr_prompts, width=self.hr_upscale_to_x, height=self.hr_upscale_to_y, distilled_cfg_scale=self.distilled_cfg_scale)
hr_negative_prompts = prompt_parser.SdConditioning(self.hr_negative_prompts, width=self.hr_upscale_to_x, height=self.hr_upscale_to_y, is_negative_prompt=True, distilled_cfg_scale=self.distilled_cfg_scale)
hr_prompts = prompt_parser.SdConditioning(self.hr_prompts, width=self.hr_upscale_to_x, height=self.hr_upscale_to_y, distilled_cfg_scale=self.hr_distilled_cfg)
hr_negative_prompts = prompt_parser.SdConditioning(self.hr_negative_prompts, width=self.hr_upscale_to_x, height=self.hr_upscale_to_y, is_negative_prompt=True, distilled_cfg_scale=self.hr_distilled_cfg)
sampler_config = sd_samplers.find_sampler_config(self.hr_sampler_name or self.sampler_name)
steps = self.hr_second_pass_steps or self.steps
@@ -1570,6 +1577,8 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
latent_mask: Image = None
force_task_id: str = None
hr_distilled_cfg: float = 3.5 # needed here for cached_params
image_mask: Any = field(default=None, init=False)
nmask: torch.Tensor = field(default=None, init=False)