From 3bd898b6ce94f34bcc7685672f0e4318d2d86b33 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sat, 21 Jan 2023 23:14:59 +0300 Subject: First test of different sampler for hi-res fix --- modules/processing.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 6e6371a1..b3206f80 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -710,7 +710,7 @@ def old_hires_fix_first_pass_dimensions(width, height): class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): sampler = None - def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, **kwargs): + def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: int = 0, **kwargs): super().__init__(**kwargs) self.enable_hr = enable_hr self.denoising_strength = denoising_strength @@ -721,6 +721,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_resize_y = hr_resize_y self.hr_upscale_to_x = hr_resize_x self.hr_upscale_to_y = hr_resize_y + self.hr_sampler = hr_sampler if firstphase_width != 0 or firstphase_height != 0: self.hr_upscale_to_x = self.width @@ -862,6 +863,10 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): shared.state.nextjob() img2img_sampler_name = self.sampler_name if self.sampler_name != 'PLMS' else 'DDIM' # PLMS does not support img2img so we just silently switch ot DDIM + + if self.hr_sampler != 0 and sd_samplers.samplers[self.hr_sampler].name != 'PLMS': + img2img_sampler_name = sd_samplers.samplers[self.hr_sampler].name + self.sampler = sd_samplers.create_sampler(img2img_sampler_name, self.sd_model) samples = samples[:, :, self.truncate_y//2:samples.shape[2]-(self.truncate_y+1)//2, self.truncate_x//2:samples.shape[3]-(self.truncate_x+1)//2] -- cgit v1.2.3 From 6c0566f937ba212e3faf1d30c337850543e85a12 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sat, 21 Jan 2023 23:25:36 +0300 Subject: Type mismatch fix --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index b3206f80..65673a9d 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -864,8 +864,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): img2img_sampler_name = self.sampler_name if self.sampler_name != 'PLMS' else 'DDIM' # PLMS does not support img2img so we just silently switch ot DDIM - if self.hr_sampler != 0 and sd_samplers.samplers[self.hr_sampler].name != 'PLMS': - img2img_sampler_name = sd_samplers.samplers[self.hr_sampler].name + if self.hr_sampler != 0 and self.hr_sampler != 'PLMS': + img2img_sampler_name = self.hr_sampler self.sampler = sd_samplers.create_sampler(img2img_sampler_name, self.sd_model) -- cgit v1.2.3 From 9e1f49c4e5b169eecbf075c49a304774dfdc6035 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 00:03:16 +0300 Subject: PLMS edge-case handling fix --- modules/processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 65673a9d..6e04b064 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -864,7 +864,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): img2img_sampler_name = self.sampler_name if self.sampler_name != 'PLMS' else 'DDIM' # PLMS does not support img2img so we just silently switch ot DDIM - if self.hr_sampler != 0 and self.hr_sampler != 'PLMS': + if self.hr_sampler != 0 and sd_samplers.samplers[self.hr_sampler].name != 'PLMS': img2img_sampler_name = self.hr_sampler self.sampler = sd_samplers.create_sampler(img2img_sampler_name, self.sd_model) -- cgit v1.2.3 From 3ffe2e768b542c837927cfdf0310a2e0fdd48683 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 00:07:46 +0300 Subject: PLMS edge-case handling fix 2 --- modules/processing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 6e04b064..83c65948 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -710,7 +710,7 @@ def old_hires_fix_first_pass_dimensions(width, height): class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): sampler = None - def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: int = 0, **kwargs): + def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: int | str = 0, **kwargs): super().__init__(**kwargs) self.enable_hr = enable_hr self.denoising_strength = denoising_strength @@ -864,7 +864,11 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): img2img_sampler_name = self.sampler_name if self.sampler_name != 'PLMS' else 'DDIM' # PLMS does not support img2img so we just silently switch ot DDIM - if self.hr_sampler != 0 and sd_samplers.samplers[self.hr_sampler].name != 'PLMS': + if self.hr_sampler == 0: + pass + elif self.hr_sampler == 'PLMS': + img2img_sampler_name = 'DDIM' + else: img2img_sampler_name = self.hr_sampler self.sampler = sd_samplers.create_sampler(img2img_sampler_name, self.sd_model) -- cgit v1.2.3 From 6cd7bf9f860dff3b61a50ec2d41915536cbcf448 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 00:08:58 +0300 Subject: PLMS edge-case handling fix 3 --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 83c65948..6f6efe06 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -710,7 +710,7 @@ def old_hires_fix_first_pass_dimensions(width, height): class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): sampler = None - def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: int | str = 0, **kwargs): + def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: str = '---', **kwargs): super().__init__(**kwargs) self.enable_hr = enable_hr self.denoising_strength = denoising_strength @@ -864,7 +864,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): img2img_sampler_name = self.sampler_name if self.sampler_name != 'PLMS' else 'DDIM' # PLMS does not support img2img so we just silently switch ot DDIM - if self.hr_sampler == 0: + if self.hr_sampler == '---': pass elif self.hr_sampler == 'PLMS': img2img_sampler_name = 'DDIM' -- cgit v1.2.3 From 0f6862ef3041f3ee18e8236765b1c1958c84385b Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 00:11:05 +0300 Subject: PLMS edge-case handling fix 5 --- modules/processing.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 6f6efe06..a873498b 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -866,8 +866,6 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_sampler == '---': pass - elif self.hr_sampler == 'PLMS': - img2img_sampler_name = 'DDIM' else: img2img_sampler_name = self.hr_sampler -- cgit v1.2.3 From 8114959e7e937361b719cd85bec246ffd258dca6 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 14:28:53 +0300 Subject: Hr separate prompt test --- modules/processing.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index a873498b..f407e175 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -516,6 +516,23 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: else: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] + if type(p) == StableDiffusionProcessingTxt2Img: + if p.hr_enabled and p.is_hr_pass: + if p.hr_prompt: + if type(p.prompt) == list: + p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] + else: + p.all_prompts = p.batch_size * p.n_iter * [ + shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] + + if p.hr_negative_prompt: + if type(p.negative_prompt) == list: + p.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in + p.hr_negative_prompt] + else: + p.all_negative_prompts = p.batch_size * p.n_iter * [ + shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] + if type(seed) == list: p.all_seeds = seed else: @@ -710,7 +727,7 @@ def old_hires_fix_first_pass_dimensions(width, height): class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): sampler = None - def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: str = '---', **kwargs): + def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_sampler: str = '---', hr_prompt: str = '', hr_negative_prompt: str = '', **kwargs): super().__init__(**kwargs) self.enable_hr = enable_hr self.denoising_strength = denoising_strength @@ -722,6 +739,9 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_upscale_to_x = hr_resize_x self.hr_upscale_to_y = hr_resize_y self.hr_sampler = hr_sampler + self.hr_prompt = hr_prompt if hr_prompt != '' else self.prompt + self.hr_negative_prompt = hr_negative_prompt if hr_negative_prompt != '' else self.negative_prompt + self.is_hr_pass = False if firstphase_width != 0 or firstphase_height != 0: self.hr_upscale_to_x = self.width @@ -808,6 +828,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if not self.enable_hr: return samples + self.is_hr_pass = True target_width = self.hr_upscale_to_x target_height = self.hr_upscale_to_y -- cgit v1.2.3 From b331ca784ad831de088ad3915b45da39c2a76fa8 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 14:35:34 +0300 Subject: Fix --- modules/processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index f407e175..161999d5 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -517,7 +517,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] if type(p) == StableDiffusionProcessingTxt2Img: - if p.hr_enabled and p.is_hr_pass: + if p.enable_hr and p.is_hr_pass: if p.hr_prompt: if type(p.prompt) == list: p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] -- cgit v1.2.3 From 81e0723d6559729f5b207ae04bc615318af5a11e Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 14:41:41 +0300 Subject: Logging for debugging --- modules/processing.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 161999d5..eeab4b0c 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -518,12 +518,14 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr and p.is_hr_pass: + logging.info("Running hr pass with custom prompt") if p.hr_prompt: if type(p.prompt) == list: p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] else: p.all_prompts = p.batch_size * p.n_iter * [ shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] + logging.info(p.all_prompts) if p.hr_negative_prompt: if type(p.negative_prompt) == list: @@ -532,6 +534,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: else: p.all_negative_prompts = p.batch_size * p.n_iter * [ shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] + logging.info(p.all_negative_prompts) if type(seed) == list: p.all_seeds = seed -- cgit v1.2.3 From f774a8d24ec57cf0b795fedb0c54f0304b43b4d9 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 14:52:01 +0300 Subject: Hr-fix separate prompt experimentation --- modules/processing.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index eeab4b0c..1133619f 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -516,25 +516,25 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: else: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] - if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.is_hr_pass: - logging.info("Running hr pass with custom prompt") - if p.hr_prompt: - if type(p.prompt) == list: - p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] - else: - p.all_prompts = p.batch_size * p.n_iter * [ - shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] - logging.info(p.all_prompts) - - if p.hr_negative_prompt: - if type(p.negative_prompt) == list: - p.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in - p.hr_negative_prompt] - else: - p.all_negative_prompts = p.batch_size * p.n_iter * [ - shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] - logging.info(p.all_negative_prompts) + # if type(p) == StableDiffusionProcessingTxt2Img: + # if p.enable_hr and p.is_hr_pass: + # logging.info("Running hr pass with custom prompt") + # if p.hr_prompt: + # if type(p.prompt) == list: + # p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] + # else: + # p.all_prompts = p.batch_size * p.n_iter * [ + # shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] + # logging.info(p.all_prompts) + # + # if p.hr_negative_prompt: + # if type(p.negative_prompt) == list: + # p.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in + # p.hr_negative_prompt] + # else: + # p.all_negative_prompts = p.batch_size * p.n_iter * [ + # shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] + # logging.info(p.all_negative_prompts) if type(seed) == list: p.all_seeds = seed @@ -744,7 +744,6 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_sampler = hr_sampler self.hr_prompt = hr_prompt if hr_prompt != '' else self.prompt self.hr_negative_prompt = hr_negative_prompt if hr_negative_prompt != '' else self.negative_prompt - self.is_hr_pass = False if firstphase_width != 0 or firstphase_height != 0: self.hr_upscale_to_x = self.width @@ -831,7 +830,9 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if not self.enable_hr: return samples - self.is_hr_pass = True + self.prompt = self.hr_prompt + self.negative_prompt = self.hr_negative_prompt + target_width = self.hr_upscale_to_x target_height = self.hr_upscale_to_y -- cgit v1.2.3 From a9f0e7d53611cf11331e2befd34f0351b47795ee Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:12:00 +0300 Subject: hr conditioning --- modules/processing.py | 72 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 1133619f..21886bb5 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -235,7 +235,7 @@ class StableDiffusionProcessing: def init(self, all_prompts, all_seeds, all_subseeds): pass - def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_uconditional_conditioning, seeds, subseeds, subseed_strength, prompts): raise NotImplementedError() def close(self): @@ -516,25 +516,25 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: else: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] - # if type(p) == StableDiffusionProcessingTxt2Img: - # if p.enable_hr and p.is_hr_pass: - # logging.info("Running hr pass with custom prompt") - # if p.hr_prompt: - # if type(p.prompt) == list: - # p.all_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] - # else: - # p.all_prompts = p.batch_size * p.n_iter * [ - # shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] - # logging.info(p.all_prompts) - # - # if p.hr_negative_prompt: - # if type(p.negative_prompt) == list: - # p.all_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in - # p.hr_negative_prompt] - # else: - # p.all_negative_prompts = p.batch_size * p.n_iter * [ - # shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] - # logging.info(p.all_negative_prompts) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr and p.is_hr_pass: + logging.info("Running hr pass with custom prompt") + if p.hr_prompt: + if type(p.prompt) == list: + p.all_hr_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] + else: + p.all_hr_prompts = p.batch_size * p.n_iter * [ + shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] + logging.info(p.all_prompts) + + if p.hr_negative_prompt: + if type(p.negative_prompt) == list: + p.all_hr_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in + p.hr_negative_prompt] + else: + p.all_hr_negative_prompts = p.batch_size * p.n_iter * [ + shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] + logging.info(p.all_negative_prompts) if type(seed) == list: p.all_seeds = seed @@ -607,6 +607,12 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: prompts = p.all_prompts[n * p.batch_size:(n + 1) * p.batch_size] negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] + + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr: + hr_prompts = p.all_hr_prompts[n * p.batch_size:(n + 1) * p.batch_size] + hr_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] + seeds = p.all_seeds[n * p.batch_size:(n + 1) * p.batch_size] subseeds = p.all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] @@ -620,6 +626,12 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps, cached_uc) c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, cached_c) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr: + hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps, + cached_uc) + hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, + cached_c) if len(model_hijack.comments) > 0: for comment in model_hijack.comments: @@ -629,7 +641,16 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: shared.state.job = f"Batch {n+1} out of {p.n_iter}" with devices.autocast(): - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr: + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_uconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, + subseeds=subseeds, + subseed_strength=p.subseed_strength, prompts=prompts) + else: + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, + subseeds=subseeds, + subseed_strength=p.subseed_strength, prompts=prompts) x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))] for x in x_samples_ddim: @@ -744,6 +765,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_sampler = hr_sampler self.hr_prompt = hr_prompt if hr_prompt != '' else self.prompt self.hr_negative_prompt = hr_negative_prompt if hr_negative_prompt != '' else self.negative_prompt + self.all_hr_prompts = None + self.all_hr_negative_prompts = None if firstphase_width != 0 or firstphase_height != 0: self.hr_upscale_to_x = self.width @@ -817,7 +840,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_upscaler is not None: self.extra_generation_params["Hires upscaler"] = self.hr_upscaler - def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_uconditional_conditioning, seeds, subseeds, subseed_strength, prompts): self.sampler = sd_samplers.create_sampler(self.sampler_name, self.sd_model) latent_scale_mode = shared.latent_upscale_modes.get(self.hr_upscaler, None) if self.hr_upscaler is not None else shared.latent_upscale_modes.get(shared.latent_upscale_default_mode, "nearest") @@ -830,9 +853,6 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if not self.enable_hr: return samples - self.prompt = self.hr_prompt - self.negative_prompt = self.hr_negative_prompt - target_width = self.hr_upscale_to_x target_height = self.hr_upscale_to_y @@ -904,7 +924,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): x = None devices.torch_gc() - samples = self.sampler.sample_img2img(self, samples, noise, conditioning, unconditional_conditioning, steps=self.hr_second_pass_steps or self.steps, image_conditioning=image_conditioning) + samples = self.sampler.sample_img2img(self, samples, noise, hr_conditioning, hr_unconditional_conditioning, steps=self.hr_second_pass_steps or self.steps, image_conditioning=image_conditioning) return samples -- cgit v1.2.3 From 4e0cf7d4eda3d590df3e4b28654037d2dfb7ab94 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:15:08 +0300 Subject: hr conditioning --- modules/processing.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 21886bb5..6b49b4e3 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -517,24 +517,16 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.is_hr_pass: - logging.info("Running hr pass with custom prompt") - if p.hr_prompt: - if type(p.prompt) == list: - p.all_hr_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] - else: - p.all_hr_prompts = p.batch_size * p.n_iter * [ - shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] - logging.info(p.all_prompts) - - if p.hr_negative_prompt: - if type(p.negative_prompt) == list: - p.all_hr_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in - p.hr_negative_prompt] - else: - p.all_hr_negative_prompts = p.batch_size * p.n_iter * [ - shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] - logging.info(p.all_negative_prompts) + if p.enable_hr: + if type(p.prompt) == list: + p.all_hr_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] + else: + p.all_hr_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_styles_to_prompt(p.hr_prompt, p.styles)] + + if type(p.negative_prompt) == list: + p.all_hr_negative_prompts = [shared.prompt_styles.apply_negative_styles_to_prompt(x, p.styles) for x in p.hr_negative_prompt] + else: + p.all_hr_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.hr_negative_prompt, p.styles)] if type(seed) == list: p.all_seeds = seed @@ -628,9 +620,9 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, cached_c) if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr: - hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps, + hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, hr_negative_prompts, p.steps, cached_uc) - hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, + hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, hr_prompts, p.steps, cached_c) if len(model_hijack.comments) > 0: @@ -840,7 +832,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_upscaler is not None: self.extra_generation_params["Hires upscaler"] = self.hr_upscaler - def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_uconditional_conditioning, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_unconditional_conditioning, seeds, subseeds, subseed_strength, prompts): self.sampler = sd_samplers.create_sampler(self.sampler_name, self.sd_model) latent_scale_mode = shared.latent_upscale_modes.get(self.hr_upscaler, None) if self.hr_upscaler is not None else shared.latent_upscale_modes.get(shared.latent_upscale_default_mode, "nearest") -- cgit v1.2.3 From c5d4c87c02ce4c503de149db5ee3e87af4402cf0 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:17:43 +0300 Subject: hr conditioning --- modules/processing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 6b49b4e3..a81ace6f 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -635,10 +635,11 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: with devices.autocast(): if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr: - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_uconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, - subseeds=subseeds, - subseed_strength=p.subseed_strength, prompts=prompts) + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + else: + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, + subseed_strength=p.subseed_strength, prompts=prompts) + else: samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, -- cgit v1.2.3 From 2ab2bce74d7b7affb80b55da9d1ffb219129c1ef Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:28:38 +0300 Subject: hr conditioning --- modules/processing.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index a81ace6f..bab1c101 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -235,7 +235,7 @@ class StableDiffusionProcessing: def init(self, all_prompts, all_seeds, all_subseeds): pass - def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_uconditional_conditioning, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, hr_conditioning=None, hr_unconditional_conditioning=None, seeds, subseeds, subseed_strength, prompts): raise NotImplementedError() def close(self): @@ -517,7 +517,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr: + if p.enable_hr and p.hr_prompt != '': if type(p.prompt) == list: p.all_hr_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] else: @@ -601,7 +601,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr: + if p.enable_hr and p.hr_prompt != '': hr_prompts = p.all_hr_prompts[n * p.batch_size:(n + 1) * p.batch_size] hr_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] @@ -619,7 +619,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps, cached_uc) c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, cached_c) if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr: + if p.enable_hr and p.hr_prompt != '': hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, hr_negative_prompts, p.steps, cached_uc) hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, hr_prompts, p.steps, @@ -635,7 +635,12 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: with devices.autocast(): if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr: - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + if p.hr_prompts != '': + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + else: + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=c, + hr_unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, + subseed_strength=p.subseed_strength, prompts=prompts) else: samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) @@ -756,8 +761,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_upscale_to_x = hr_resize_x self.hr_upscale_to_y = hr_resize_y self.hr_sampler = hr_sampler - self.hr_prompt = hr_prompt if hr_prompt != '' else self.prompt - self.hr_negative_prompt = hr_negative_prompt if hr_negative_prompt != '' else self.negative_prompt + self.hr_prompt = hr_prompt if hr_prompt != '' else '' + self.hr_negative_prompt = hr_negative_prompt if hr_negative_prompt != '' else '' self.all_hr_prompts = None self.all_hr_negative_prompts = None -- cgit v1.2.3 From 125d5c8d96eb374a7ba214dba51da9cf30da6564 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:31:11 +0300 Subject: hr conditioning --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index bab1c101..f0073d1a 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -235,7 +235,7 @@ class StableDiffusionProcessing: def init(self, all_prompts, all_seeds, all_subseeds): pass - def sample(self, conditioning, unconditional_conditioning, hr_conditioning=None, hr_unconditional_conditioning=None, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts, hr_conditioning=None, hr_unconditional_conditioning=None): raise NotImplementedError() def close(self): @@ -838,7 +838,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_upscaler is not None: self.extra_generation_params["Hires upscaler"] = self.hr_upscaler - def sample(self, conditioning, unconditional_conditioning, hr_conditioning, hr_unconditional_conditioning, seeds, subseeds, subseed_strength, prompts): + def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts, hr_conditioning=None, hr_unconditional_conditioning=None): self.sampler = sd_samplers.create_sampler(self.sampler_name, self.sd_model) latent_scale_mode = shared.latent_upscale_modes.get(self.hr_upscaler, None) if self.hr_upscaler is not None else shared.latent_upscale_modes.get(shared.latent_upscale_default_mode, "nearest") -- cgit v1.2.3 From 34f6d667429ec3d4e0f09c6148fd37e66c460cb7 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:32:47 +0300 Subject: hr conditioning --- modules/processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index f0073d1a..b2de8f92 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -635,7 +635,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: with devices.autocast(): if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr: - if p.hr_prompts != '': + if p.hr_prompt != '': samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) else: samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=c, -- cgit v1.2.3 From bbb1e35ea29f8cfc6a6db3b28b10bfbc99033c70 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:44:59 +0300 Subject: UI and PNG info improvements --- modules/processing.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index b2de8f92..0cf4771e 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -789,6 +789,9 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale + self.extra_generation_params["Hires sampler"] = self.hr_sampler + self.extra_generation_params["Hires prompt"] = self.hr_prompt + self.extra_generation_params["Hires negative prompt"] = self.hr_negative_prompt self.hr_upscale_to_x = int(self.width * self.hr_scale) self.hr_upscale_to_y = int(self.height * self.hr_scale) else: -- cgit v1.2.3 From a5c2b5ed8991e0e1ffea7b595ab13f93715dfa5c Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 15:50:20 +0300 Subject: UI and PNG info improvements --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 0cf4771e..8b4b2399 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -790,8 +790,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale self.extra_generation_params["Hires sampler"] = self.hr_sampler - self.extra_generation_params["Hires prompt"] = self.hr_prompt - self.extra_generation_params["Hires negative prompt"] = self.hr_negative_prompt + self.extra_generation_params["Hires prompt"] = f"({self.hr_prompt})" + self.extra_generation_params["Hires negative prompt"] = f"({self.hr_negative_prompt})" self.hr_upscale_to_x = int(self.width * self.hr_scale) self.hr_upscale_to_y = int(self.height * self.hr_scale) else: -- cgit v1.2.3 From 7f62300f7d496501a730d28f3aaaee885513998b Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 16:29:08 +0300 Subject: Gen params paste improvement --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 8b4b2399..c56717f6 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -790,8 +790,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale self.extra_generation_params["Hires sampler"] = self.hr_sampler - self.extra_generation_params["Hires prompt"] = f"({self.hr_prompt})" - self.extra_generation_params["Hires negative prompt"] = f"({self.hr_negative_prompt})" + self.extra_generation_params["Hires prompt"] = f'"{self.hr_prompt}"' + self.extra_generation_params["Hires negative prompt"] = f'"{self.hr_negative_prompt}"' self.hr_upscale_to_x = int(self.width * self.hr_scale) self.hr_upscale_to_y = int(self.height * self.hr_scale) else: -- cgit v1.2.3 From 3bc8ee998db5f461b8011a72e6f167012ccb8bc1 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 22 Jan 2023 16:35:42 +0300 Subject: Gen params paste improvement --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index c56717f6..01c1b53c 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -790,8 +790,8 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale self.extra_generation_params["Hires sampler"] = self.hr_sampler - self.extra_generation_params["Hires prompt"] = f'"{self.hr_prompt}"' - self.extra_generation_params["Hires negative prompt"] = f'"{self.hr_negative_prompt}"' + self.extra_generation_params["Hires prompt"] = f'({self.hr_prompt.replace(",", ";")})' + self.extra_generation_params["Hires negative prompt"] = f'({self.hr_negative_prompt.replace(",", ";")})' self.hr_upscale_to_x = int(self.width * self.hr_scale) self.hr_upscale_to_y = int(self.height * self.hr_scale) else: -- cgit v1.2.3 From c92ec3a9255a8364f4212d5e7434da1785752737 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 29 Jan 2023 19:07:00 +0300 Subject: Extra networks loading fix --- modules/processing.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 605c541e..da890fb3 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -555,6 +555,10 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: model_hijack.embedding_db.load_textual_inversion_embeddings() _, extra_network_data = extra_networks.parse_prompts(p.all_prompts[0:1]) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr and p.hr_prompt != '': + _, hr_extra_network_data = extra_networks.parse_prompts(p.all_hr_prompts[0:1]) + if p.scripts is not None: p.scripts.process(p) @@ -594,7 +598,11 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: sd_vae_approx.model() if not p.disable_extra_networks: - extra_networks.activate(p, extra_network_data) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr and p.hr_prompt != '': + extra_networks.activate(p, extra_network_data + hr_extra_network_data) + else: + extra_networks.activate(p, extra_network_data) with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: processed = Processed(p, [], p.seed, "") @@ -745,7 +753,11 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: images.save_image(grid, p.outpath_grids, "grid", p.all_seeds[0], p.all_prompts[0], opts.grid_format, info=infotext(), short_filename=not opts.grid_extended_filename, p=p, grid=True) if not p.disable_extra_networks: - extra_networks.deactivate(p, extra_network_data) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr and p.hr_prompt != '': + extra_networks.deactivate(p, extra_network_data + hr_extra_network_data) + else: + extra_networks.deactivate(p, extra_network_data) devices.torch_gc() -- cgit v1.2.3 From 6127d2ff1bc5c3bc81d876e6dbc9a60f79aec898 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 29 Jan 2023 19:13:27 +0300 Subject: Extra networks loading fix --- modules/processing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index da890fb3..a56915c5 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -600,7 +600,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if not p.disable_extra_networks: if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr and p.hr_prompt != '': - extra_networks.activate(p, extra_network_data + hr_extra_network_data) + extra_networks.activate(p, extra_network_data | hr_extra_network_data) else: extra_networks.activate(p, extra_network_data) @@ -755,7 +755,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if not p.disable_extra_networks: if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr and p.hr_prompt != '': - extra_networks.deactivate(p, extra_network_data + hr_extra_network_data) + extra_networks.deactivate(p, extra_network_data | hr_extra_network_data) else: extra_networks.deactivate(p, extra_network_data) -- cgit v1.2.3 From 9beeef6267ecbcb16f8b24e0092194f0f00142a6 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 29 Jan 2023 19:16:17 +0300 Subject: Extra networks loading fix --- modules/processing.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index a56915c5..98e83c69 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -558,6 +558,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr and p.hr_prompt != '': _, hr_extra_network_data = extra_networks.parse_prompts(p.all_hr_prompts[0:1]) + extra_network_data.update(hr_extra_network_data) if p.scripts is not None: @@ -598,11 +599,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: sd_vae_approx.model() if not p.disable_extra_networks: - if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': - extra_networks.activate(p, extra_network_data | hr_extra_network_data) - else: - extra_networks.activate(p, extra_network_data) + extra_networks.activate(p, extra_network_data) with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: processed = Processed(p, [], p.seed, "") @@ -753,11 +750,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: images.save_image(grid, p.outpath_grids, "grid", p.all_seeds[0], p.all_prompts[0], opts.grid_format, info=infotext(), short_filename=not opts.grid_extended_filename, p=p, grid=True) if not p.disable_extra_networks: - if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': - extra_networks.deactivate(p, extra_network_data | hr_extra_network_data) - else: - extra_networks.deactivate(p, extra_network_data) + extra_networks.deactivate(p, extra_network_data) devices.torch_gc() -- cgit v1.2.3 From 425eab34641e8e378db610d6a2b23f3ababe1058 Mon Sep 17 00:00:00 2001 From: invincibledude <> Date: Sun, 29 Jan 2023 19:26:31 +0300 Subject: Extra network in hr abomination fix --- modules/processing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 98e83c69..a2a91a5b 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -558,7 +558,8 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr and p.hr_prompt != '': _, hr_extra_network_data = extra_networks.parse_prompts(p.all_hr_prompts[0:1]) - extra_network_data.update(hr_extra_network_data) + if p.all_hr_prompts != p.all_prompts: + extra_network_data.update(hr_extra_network_data) if p.scripts is not None: -- cgit v1.2.3 From c3bd113a0b969732a324aff415c49ea9ad434707 Mon Sep 17 00:00:00 2001 From: InvincibleDude <81354513+InvincibleDude@users.noreply.github.com> Date: Sun, 5 Feb 2023 15:24:41 +0000 Subject: Image info fix --- modules/processing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 61e6dfcd..43fac21c 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -808,6 +808,13 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): def init(self, all_prompts, all_seeds, all_subseeds): if self.enable_hr: + if self.hr_sampler != '---': + self.extra_generation_params["Hires sampler"] = self.hr_sampler + + if self.hr_prompt != '': + self.extra_generation_params["Hires prompt"] = f'({self.hr_prompt.replace(",", ";")})' + self.extra_generation_params["Hires negative prompt"] = f'({self.hr_negative_prompt.replace(",", ";")})' + if opts.use_old_hires_fix_width_height and self.applied_old_hires_behavior_to != (self.width, self.height): self.hr_resize_x = self.width self.hr_resize_y = self.height @@ -819,9 +826,6 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if self.hr_resize_x == 0 and self.hr_resize_y == 0: self.extra_generation_params["Hires upscale"] = self.hr_scale - self.extra_generation_params["Hires sampler"] = self.hr_sampler - self.extra_generation_params["Hires prompt"] = f'({self.hr_prompt.replace(",", ";")})' - self.extra_generation_params["Hires negative prompt"] = f'({self.hr_negative_prompt.replace(",", ";")})' self.hr_upscale_to_x = int(self.width * self.hr_scale) self.hr_upscale_to_y = int(self.height * self.hr_scale) else: -- cgit v1.2.3 From 51f81efb02876d24c9e6d844e8c0cbd2384f6514 Mon Sep 17 00:00:00 2001 From: InvincibleDude <81354513+InvincibleDude@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:30:20 +0300 Subject: Image processing changes Image processing changes --- modules/processing.py | 76 +++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'modules/processing.py') diff --git a/modules/processing.py b/modules/processing.py index 43fac21c..72dd3f6f 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -528,7 +528,9 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: p.all_negative_prompts = p.batch_size * p.n_iter * [shared.prompt_styles.apply_negative_styles_to_prompt(p.negative_prompt, p.styles)] if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': + if p.enable_hr and p.hr_prompt == '': + p.all_hr_prompts, p.all_hr_negative_prompts = p.all_prompts, p.all_negative_prompts + elif p.enable_hr and p.hr_prompt != '': if type(p.prompt) == list: p.all_hr_prompts = [shared.prompt_styles.apply_styles_to_prompt(x, p.styles) for x in p.hr_prompt] else: @@ -555,14 +557,6 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if os.path.exists(cmd_opts.embeddings_dir) and not p.do_not_reload_embeddings: model_hijack.embedding_db.load_textual_inversion_embeddings() - _, extra_network_data = extra_networks.parse_prompts(p.all_prompts[0:1]) - if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': - _, hr_extra_network_data = extra_networks.parse_prompts(p.all_hr_prompts[0:1]) - if p.all_hr_prompts != p.all_prompts: - extra_network_data.update(hr_extra_network_data) - - if p.scripts is not None: p.scripts.process(p) @@ -600,13 +594,6 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if shared.opts.live_previews_enable and opts.show_progress_type == "Approx NN": sd_vae_approx.model() - if not p.disable_extra_networks: - extra_networks.activate(p, extra_network_data) - - with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: - processed = Processed(p, [], p.seed, "") - file.write(processed.infotext(p, 0)) - if state.job_count == -1: state.job_count = p.n_iter @@ -623,9 +610,12 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': - hr_prompts = p.all_hr_prompts[n * p.batch_size:(n + 1) * p.batch_size] - hr_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] + if p.enable_hr: + if p.hr_prompt == '': + hr_prompts, hr_negative_prompts = prompts, negative_prompts + else: + hr_prompts = p.all_hr_prompts[n * p.batch_size:(n + 1) * p.batch_size] + hr_negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] seeds = p.all_seeds[n * p.batch_size:(n + 1) * p.batch_size] subseeds = p.all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] @@ -633,19 +623,40 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if len(prompts) == 0: break - prompts, _ = extra_networks.parse_prompts(prompts) + prompts, extra_network_data = extra_networks.parse_prompts(prompts) + if type(p) == StableDiffusionProcessingTxt2Img: + if p.enable_hr and hr_prompts != prompts: + _, hr_extra_network_data = extra_networks.parse_prompts(hr_prompts) + extra_network_data.update(hr_extra_network_data) + + + + if not p.disable_extra_networks: + with devices.autocast(): + extra_networks.activate(p, extra_network_data) if p.scripts is not None: p.scripts.process_batch(p, batch_number=n, prompts=prompts, seeds=seeds, subseeds=subseeds) + # params.txt should be saved after scripts.process_batch, since the + # infotext could be modified by that callback + # Example: a wildcard processed by process_batch sets an extra model + # strength, which is saved as "Model Strength: 1.0" in the infotext + if n == 0: + with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: + processed = Processed(p, [], p.seed, "") + file.write(processed.infotext(p, 0)) + uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps, cached_uc) c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps, cached_c) + if type(p) == StableDiffusionProcessingTxt2Img: - if p.enable_hr and p.hr_prompt != '': - hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, hr_negative_prompts, p.steps, - cached_uc) - hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, hr_prompts, p.steps, - cached_c) + if p.enable_hr: + if prompts != hr_prompts: + hr_uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, hr_negative_prompts, p.steps, cached_uc) + hr_c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, hr_prompts, p.steps, cached_c) + else: + hr_uc, hr_c = uc, c if len(model_hijack.comments) > 0: for comment in model_hijack.comments: @@ -658,20 +669,9 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: with devices.without_autocast() if devices.unet_needs_upcast else devices.autocast(): if type(p) == StableDiffusionProcessingTxt2Img: if p.enable_hr: - if p.hr_prompt != '': - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) - else: - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=c, - hr_unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, - subseed_strength=p.subseed_strength, prompts=prompts) - else: - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, - subseed_strength=p.subseed_strength, prompts=prompts) - + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, hr_conditioning=hr_c, hr_unconditional_conditioning=hr_uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) else: - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, - subseeds=subseeds, - subseed_strength=p.subseed_strength, prompts=prompts) + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))] for x in x_samples_ddim: