From d3f9156854b3d6b4c3d5d736f3b0454743203076 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 13:02:39 +0100 Subject: [PATCH 01/38] only make stop_button and skip_button interactive when rendering process starts fix inconsistency in behaviour of stop_button and skip_button as it was possible to skip or stop other users processes while still being in queue --- webui.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/webui.py b/webui.py index d1381d5e0..35ef06292 100644 --- a/webui.py +++ b/webui.py @@ -31,7 +31,9 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ gr.update(visible=True, value=None), \ gr.update(visible=False, value=None), \ - gr.update(visible=False) + gr.update(visible=False), \ + gr.update(visible=True, interactive=True), \ + gr.update(visible=True, interactive=True) worker.async_tasks.append(task) @@ -51,17 +53,23 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \ gr.update(visible=True, value=image) if image is not None else gr.update(), \ gr.update(), \ - gr.update(visible=False) + gr.update(visible=False), \ + gr.update(visible=True), \ + gr.update(visible=True) if flag == 'results': yield gr.update(visible=True), \ gr.update(visible=True), \ gr.update(visible=True, value=product), \ - gr.update(visible=False) + gr.update(visible=False), \ + gr.update(visible=True), \ + gr.update(visible=True) if flag == 'finish': yield gr.update(visible=False), \ gr.update(visible=False), \ gr.update(visible=False), \ - gr.update(visible=True, value=product) + gr.update(visible=True, value=product), \ + gr.update(visible=False), \ + gr.update(visible=False) finished = True execution_time = time.perf_counter() - execution_start_time @@ -437,10 +445,10 @@ def model_refresh_clicked(): ctrls += [outpaint_selections, inpaint_input_image] ctrls += ip_ctrls - generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ + generate_button.click(lambda: (gr.update(visible=True, interactive=False), gr.update(visible=True, interactive=False), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ - .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ + .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery, stop_button, skip_button]) \ .then(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)), outputs=[generate_button, stop_button, skip_button]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') From 617255d040a97b849d5ec698c0fb4ef0168a5e32 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 17:20:41 +0100 Subject: [PATCH 02/38] use AsyncTask for last_stop handling instead of shared --- modules/async_worker.py | 3 ++- shared.py | 3 +-- webui.py | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index b4207591e..0ca051d0a 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -6,6 +6,7 @@ def __init__(self, args): self.args = args self.yields = [] self.results = [] + self.last_stop = False async_tasks = [] @@ -722,7 +723,7 @@ def callback(step, x0, x, total_steps, y): yield_result(async_task, imgs, do_not_show_finished_images=len(tasks) == 1) except fcbh.model_management.InterruptProcessingException as e: - if shared.last_stop == 'skip': + if async_task.last_stop == 'skip': print('User skipped') continue else: diff --git a/shared.py b/shared.py index 269809e3f..21a2a864b 100644 --- a/shared.py +++ b/shared.py @@ -1,2 +1 @@ -gradio_root = None -last_stop = None +gradio_root = None \ No newline at end of file diff --git a/webui.py b/webui.py index 35ef06292..aa936d792 100644 --- a/webui.py +++ b/webui.py @@ -20,12 +20,13 @@ from modules.ui_gradio_extensions import reload_javascript from modules.auth import auth_enabled, check_auth +currentTask = gr.State() def generate_clicked(*args): # outputs=[progress_html, progress_window, progress_gallery, gallery] execution_start_time = time.perf_counter() - task = worker.AsyncTask(args=list(args)) + currentTask.value = task = worker.AsyncTask(args=list(args)) finished = False yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ @@ -117,13 +118,13 @@ def generate_clicked(*args): def stop_clicked(): import fcbh.model_management as model_management - shared.last_stop = 'stop' + currentTask.value.last_stop = 'stop' model_management.interrupt_current_processing() return [gr.update(interactive=False)] * 2 def skip_clicked(): import fcbh.model_management as model_management - shared.last_stop = 'skip' + currentTask.value.last_stop = 'skip' model_management.interrupt_current_processing() return From 83efbbd2fac52c34661fbaf0448d56722731b3da Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 17:23:37 +0100 Subject: [PATCH 03/38] Revert "only make stop_button and skip_button interactive when rendering process starts" This reverts commit d3f9156854b3d6b4c3d5d736f3b0454743203076. --- webui.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/webui.py b/webui.py index aa936d792..e43a6c966 100644 --- a/webui.py +++ b/webui.py @@ -32,9 +32,7 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ gr.update(visible=True, value=None), \ gr.update(visible=False, value=None), \ - gr.update(visible=False), \ - gr.update(visible=True, interactive=True), \ - gr.update(visible=True, interactive=True) + gr.update(visible=False) worker.async_tasks.append(task) @@ -54,23 +52,17 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \ gr.update(visible=True, value=image) if image is not None else gr.update(), \ gr.update(), \ - gr.update(visible=False), \ - gr.update(visible=True), \ - gr.update(visible=True) + gr.update(visible=False) if flag == 'results': yield gr.update(visible=True), \ gr.update(visible=True), \ gr.update(visible=True, value=product), \ - gr.update(visible=False), \ - gr.update(visible=True), \ - gr.update(visible=True) + gr.update(visible=False) if flag == 'finish': yield gr.update(visible=False), \ gr.update(visible=False), \ gr.update(visible=False), \ - gr.update(visible=True, value=product), \ - gr.update(visible=False), \ - gr.update(visible=False) + gr.update(visible=True, value=product) finished = True execution_time = time.perf_counter() - execution_start_time @@ -446,10 +438,10 @@ def model_refresh_clicked(): ctrls += [outpaint_selections, inpaint_input_image] ctrls += ip_ctrls - generate_button.click(lambda: (gr.update(visible=True, interactive=False), gr.update(visible=True, interactive=False), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ + generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ - .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery, stop_button, skip_button]) \ + .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ .then(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)), outputs=[generate_button, stop_button, skip_button]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') From ebad9ea9760cb45d822c3242524a10611c08f0ac Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 20:46:09 +0100 Subject: [PATCH 04/38] introduce state for task skipping/stopping --- modules/async_worker.py | 6 +++++- webui.py | 39 +++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 0ca051d0a..e6cc8a49f 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -7,6 +7,7 @@ def __init__(self, args): self.yields = [] self.results = [] self.last_stop = False + self.processing = False async_tasks = [] @@ -115,6 +116,7 @@ def build_image_wall(async_task): @torch.inference_mode() def handler(async_task): execution_start_time = time.perf_counter() + async_task.processing = True args = async_task.args args.reverse() @@ -660,6 +662,8 @@ def callback(step, x0, x, total_steps, y): execution_start_time = time.perf_counter() try: + if async_task.last_stop is not False: + fcbh.model_management.interrupt_current_processing() positive_cond, negative_cond = task['c'], task['uc'] if 'cn' in goals: @@ -732,7 +736,7 @@ def callback(step, x0, x, total_steps, y): execution_time = time.perf_counter() - execution_start_time print(f'Generating and saving time: {execution_time:.2f} seconds') - + async_task.processing = False return while True: diff --git a/webui.py b/webui.py index e43a6c966..3dde192c5 100644 --- a/webui.py +++ b/webui.py @@ -20,13 +20,15 @@ from modules.ui_gradio_extensions import reload_javascript from modules.auth import auth_enabled, check_auth -currentTask = gr.State() +def get_task(*args): + args = list(args) + currentTask = args.pop(0) + currentTask = worker.AsyncTask(args=args) + return currentTask -def generate_clicked(*args): +def generate_clicked(task): # outputs=[progress_html, progress_window, progress_gallery, gallery] - execution_start_time = time.perf_counter() - currentTask.value = task = worker.AsyncTask(args=list(args)) finished = False yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ @@ -82,6 +84,7 @@ def generate_clicked(*args): css=modules.html.css).queue() with shared.gradio_root: + currentTask = gr.State(worker.AsyncTask(args=[])) with gr.Row(): with gr.Column(scale=2): with gr.Row(): @@ -108,21 +111,24 @@ def generate_clicked(*args): skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False) stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False) - def stop_clicked(): + def stop_clicked(currentTask): import fcbh.model_management as model_management - currentTask.value.last_stop = 'stop' - model_management.interrupt_current_processing() - return [gr.update(interactive=False)] * 2 + currentTask.last_stop = 'stop' + if (currentTask.processing): + model_management.interrupt_current_processing() + return [gr.update(interactive=False)] * 2, currentTask - def skip_clicked(): + def skip_clicked(currentTask): import fcbh.model_management as model_management - currentTask.value.last_stop = 'skip' - model_management.interrupt_current_processing() - return + currentTask.last_stop = 'skip' + if (currentTask.processing): + model_management.interrupt_current_processing() + return currentTask - stop_button.click(stop_clicked, outputs=[skip_button, stop_button], + stop_button.click(stop_clicked, inputs=currentTask, outputs=[skip_button, stop_button, currentTask], queue=False, show_progress=False, _js='cancelGenerateForever') - skip_button.click(skip_clicked, queue=False, show_progress=False) + skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, + queue=False, show_progress=False) with gr.Row(elem_classes='advanced_check_row'): input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check') advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check') @@ -428,7 +434,7 @@ def model_refresh_clicked(): .then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False) ctrls = [ - prompt, negative_prompt, style_selections, + currentTask, prompt, negative_prompt, style_selections, performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale ] @@ -441,7 +447,8 @@ def model_refresh_clicked(): generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ - .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ + .then(fn=get_task, inputs=ctrls, outputs=currentTask) \ + .then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ .then(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)), outputs=[generate_button, stop_button, skip_button]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') From 8060e50a88adfac3d35235c8bbc1af68f80e50bc Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 21:00:35 +0100 Subject: [PATCH 05/38] fix return parameters of stop_clicked --- webui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 3dde192c5..be2e55f97 100644 --- a/webui.py +++ b/webui.py @@ -116,9 +116,10 @@ def stop_clicked(currentTask): currentTask.last_stop = 'stop' if (currentTask.processing): model_management.interrupt_current_processing() - return [gr.update(interactive=False)] * 2, currentTask + return gr.update(interactive=False), gr.update(interactive=False), currentTask def skip_clicked(currentTask): + print(currentTask.last_stop) import fcbh.model_management as model_management currentTask.last_stop = 'skip' if (currentTask.processing): From 4a576bf08be6bd6926d12240492db4406437decb Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sat, 18 Nov 2023 21:40:14 +0100 Subject: [PATCH 06/38] code cleanup, do not disable skip/stop on stop_clicked --- webui.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/webui.py b/webui.py index be2e55f97..a00eb7ed6 100644 --- a/webui.py +++ b/webui.py @@ -116,20 +116,17 @@ def stop_clicked(currentTask): currentTask.last_stop = 'stop' if (currentTask.processing): model_management.interrupt_current_processing() - return gr.update(interactive=False), gr.update(interactive=False), currentTask + return currentTask def skip_clicked(currentTask): - print(currentTask.last_stop) import fcbh.model_management as model_management currentTask.last_stop = 'skip' if (currentTask.processing): model_management.interrupt_current_processing() return currentTask - stop_button.click(stop_clicked, inputs=currentTask, outputs=[skip_button, stop_button, currentTask], - queue=False, show_progress=False, _js='cancelGenerateForever') - skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, - queue=False, show_progress=False) + stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever') + skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False) with gr.Row(elem_classes='advanced_check_row'): input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check') advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check') From d2cc9a4fc83def954c55b9444bccabe5a03a5a35 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 19 Nov 2023 23:30:18 +0100 Subject: [PATCH 07/38] reset last_stop when skipping for further processing --- modules/async_worker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/async_worker.py b/modules/async_worker.py index e6cc8a49f..deaafa5a1 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -729,6 +729,7 @@ def callback(step, x0, x, total_steps, y): except fcbh.model_management.InterruptProcessingException as e: if async_task.last_stop == 'skip': print('User skipped') + async_task.last_stop = False continue else: print('User stopped') From ee3d70ab87791ef3488d5c719cb79c0d96ea2067 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 4 Jan 2024 18:03:12 +0100 Subject: [PATCH 08/38] fix: replace fcbh with ldm_patched --- modules/async_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 03887f018..421098d39 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -726,7 +726,7 @@ def callback(step, x0, x, total_steps, y): try: if async_task.last_stop is not False: - fcbh.model_management.interrupt_current_processing() + ldm_patched.model_management.interrupt_current_processing() positive_cond, negative_cond = task['c'], task['uc'] if 'cn' in goals: From 04ba1604f448728424ba16c454ff4fe0f2a5d6a9 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 4 Jan 2024 18:12:11 +0100 Subject: [PATCH 09/38] fix: use currentTask instead of ctrls after merging upstream --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index fae88bbfe..86940981e 100644 --- a/webui.py +++ b/webui.py @@ -588,7 +588,7 @@ def parse_meta(raw_prompt_txt, is_generating): .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ .then(fn=get_task, inputs=ctrls, outputs=currentTask) \ - .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ + .then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False), outputs=[generate_button, stop_button, skip_button, state_is_generating]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') From 79a63491fe2e0ef0186302ad182fdd9edcc1e71f Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 16:58:46 +0100 Subject: [PATCH 10/38] feat: extract attribute disable_preview --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 4 +++- modules/core.py | 4 ++-- modules/default_pipeline.py | 11 ++++++++--- webui.py | 3 ++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 0caa3eec8..8683799c6 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ +adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -6,11 +6,11 @@ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 35 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 34 def set_all_advanced_parameters(*args): - global disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + global adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -20,7 +20,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index b2af67126..2c3a6cfd0 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -140,6 +140,7 @@ def handler(async_task): inpaint_input_image = args.pop() inpaint_additional_prompt = args.pop() inpaint_mask_image_upload = args.pop() + disable_preview = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -766,7 +767,8 @@ def callback(step, x0, x, total_steps, y): denoise=denoising_strength, tiled=tiled, cfg_scale=cfg_scale, - refiner_swap_method=refiner_swap_method + refiner_swap_method=refiner_swap_method, + disable_preview=disable_preview ) del task['c'], task['uc'], positive_cond, negative_cond # Save memory diff --git a/modules/core.py b/modules/core.py index 989b8e321..2d3255593 100644 --- a/modules/core.py +++ b/modules/core.py @@ -268,7 +268,7 @@ def preview_function(x0, step, total_steps): def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sampler_name='dpmpp_2m_sde_gpu', scheduler='karras', denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False, callback_function=None, refiner=None, refiner_switch=-1, - previewer_start=None, previewer_end=None, sigmas=None, noise_mean=None): + previewer_start=None, previewer_end=None, sigmas=None, noise_mean=None, disable_preview=False): if sigmas is not None: sigmas = sigmas.clone().to(ldm_patched.modules.model_management.get_torch_device()) @@ -299,7 +299,7 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa def callback(step, x0, x, total_steps): ldm_patched.modules.model_management.throw_exception_if_processing_interrupted() y = None - if previewer is not None and not modules.advanced_parameters.disable_preview: + if previewer is not None and not disable_preview: y = previewer(x0, previewer_start + step, previewer_end) if callback_function is not None: callback_function(previewer_start + step, x0, x, previewer_end, y) diff --git a/modules/default_pipeline.py b/modules/default_pipeline.py index 6001d97f0..5f66a36ed 100644 --- a/modules/default_pipeline.py +++ b/modules/default_pipeline.py @@ -315,7 +315,7 @@ def get_candidate_vae(steps, switch, denoise=1.0, refiner_swap_method='joint'): @torch.no_grad() @torch.inference_mode() -def process_diffusion(positive_cond, negative_cond, steps, switch, width, height, image_seed, callback, sampler_name, scheduler_name, latent=None, denoise=1.0, tiled=False, cfg_scale=7.0, refiner_swap_method='joint'): +def process_diffusion(positive_cond, negative_cond, steps, switch, width, height, image_seed, callback, sampler_name, scheduler_name, latent=None, denoise=1.0, tiled=False, cfg_scale=7.0, refiner_swap_method='joint', disable_preview=False): target_unet, target_vae, target_refiner_unet, target_refiner_vae, target_clip \ = final_unet, final_vae, final_refiner_unet, final_refiner_vae, final_clip @@ -374,6 +374,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height refiner_switch=switch, previewer_start=0, previewer_end=steps, + disable_preview=disable_preview ) decoded_latent = core.decode_vae(vae=target_vae, latent_image=sampled_latent, tiled=tiled) @@ -392,6 +393,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height scheduler=scheduler_name, previewer_start=0, previewer_end=steps, + disable_preview=disable_preview ) print('Refiner swapped by changing ksampler. Noise preserved.') @@ -414,6 +416,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height scheduler=scheduler_name, previewer_start=switch, previewer_end=steps, + disable_preview=disable_preview ) target_model = target_refiner_vae @@ -440,7 +443,8 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height sampler_name=sampler_name, scheduler=scheduler_name, previewer_start=0, - previewer_end=steps + previewer_end=steps, + disable_preview=disable_preview ) print('Fooocus VAE-based swap.') @@ -479,7 +483,8 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height previewer_start=switch, previewer_end=steps, sigmas=sigmas, - noise_mean=noise_mean + noise_mean=noise_mean, + disable_preview=disable_preview ) target_model = target_refiner_vae diff --git a/webui.py b/webui.py index fadd852af..6b2265e1d 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, + adps = [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, @@ -528,6 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] + ctrls += [disable_preview] ctrls += ip_ctrls state_is_generating = gr.State(False) From 3607059224a9073d106d8865677fbf3266ccd884 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 17:01:32 +0100 Subject: [PATCH 11/38] feat: extract attribute adm_scaler_positive --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 8683799c6..ee1a0effb 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ +adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -6,11 +6,11 @@ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 34 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 33 def set_all_advanced_parameters(*args): - global adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + global adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -20,7 +20,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 2c3a6cfd0..ac0dd3986 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -141,6 +141,7 @@ def handler(async_task): inpaint_additional_prompt = args.pop() inpaint_mask_image_upload = args.pop() disable_preview = args.pop() + adm_scaler_positive = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -193,7 +194,7 @@ def handler(async_task): cfg_scale = guidance_scale = 1.0 modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg = 1.0 refiner_switch = 1.0 - modules.patch.positive_adm_scale = advanced_parameters.adm_scaler_positive = 1.0 + modules.patch.positive_adm_scale = adm_scaler_positive = 1.0 modules.patch.negative_adm_scale = advanced_parameters.adm_scaler_negative = 1.0 modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end = 0.0 steps = 8 @@ -204,7 +205,7 @@ def handler(async_task): modules.patch.sharpness = sharpness print(f'[Parameters] Sharpness = {modules.patch.sharpness}') - modules.patch.positive_adm_scale = advanced_parameters.adm_scaler_positive + modules.patch.positive_adm_scale = adm_scaler_positive modules.patch.negative_adm_scale = advanced_parameters.adm_scaler_negative modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end print(f'[Parameters] ADM Scale = ' diff --git a/webui.py b/webui.py index 6b2265e1d..c172ff3b6 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, + adps = [adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview] + ctrls += [disable_preview, adm_scaler_positive] ctrls += ip_ctrls state_is_generating = gr.State(False) From 64dcdbbef3abde43aa340ba98de13b718f1f7655 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 17:02:43 +0100 Subject: [PATCH 12/38] feat: extract attribute adm_scaler_negative --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index ee1a0effb..d7ebda7f4 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ +adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -6,11 +6,11 @@ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 33 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 32 def set_all_advanced_parameters(*args): - global adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + global adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -20,7 +20,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, \ + adm_scaler_end, adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index ac0dd3986..03548231e 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -142,6 +142,7 @@ def handler(async_task): inpaint_mask_image_upload = args.pop() disable_preview = args.pop() adm_scaler_positive = args.pop() + adm_scaler_negative = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -195,7 +196,7 @@ def handler(async_task): modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg = 1.0 refiner_switch = 1.0 modules.patch.positive_adm_scale = adm_scaler_positive = 1.0 - modules.patch.negative_adm_scale = advanced_parameters.adm_scaler_negative = 1.0 + modules.patch.negative_adm_scale = adm_scaler_negative = 1.0 modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end = 0.0 steps = 8 @@ -206,7 +207,7 @@ def handler(async_task): print(f'[Parameters] Sharpness = {modules.patch.sharpness}') modules.patch.positive_adm_scale = adm_scaler_positive - modules.patch.negative_adm_scale = advanced_parameters.adm_scaler_negative + modules.patch.negative_adm_scale = adm_scaler_negative modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end print(f'[Parameters] ADM Scale = ' f'{modules.patch.positive_adm_scale} : ' diff --git a/webui.py b/webui.py index c172ff3b6..b190a2822 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, + adps = [adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative] ctrls += ip_ctrls state_is_generating = gr.State(False) From 618b01764c1ae3caf84a3101d5580e115543cf6a Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 17:09:01 +0100 Subject: [PATCH 13/38] feat: extract attribute adm_scaler_end --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index d7ebda7f4..e90a82956 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -adm_scaler_end, adaptive_cfg, sampler_name, \ +adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -6,11 +6,11 @@ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 32 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 31 def set_all_advanced_parameters(*args): - global adm_scaler_end, adaptive_cfg, sampler_name, \ + global adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -20,7 +20,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - adm_scaler_end, adaptive_cfg, sampler_name, \ + adaptive_cfg, sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 03548231e..e0093cead 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -143,6 +143,7 @@ def handler(async_task): disable_preview = args.pop() adm_scaler_positive = args.pop() adm_scaler_negative = args.pop() + adm_scaler_end = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -197,7 +198,7 @@ def handler(async_task): refiner_switch = 1.0 modules.patch.positive_adm_scale = adm_scaler_positive = 1.0 modules.patch.negative_adm_scale = adm_scaler_negative = 1.0 - modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end = 0.0 + modules.patch.adm_scaler_end = adm_scaler_end = 0.0 steps = 8 modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg @@ -208,7 +209,7 @@ def handler(async_task): modules.patch.positive_adm_scale = adm_scaler_positive modules.patch.negative_adm_scale = adm_scaler_negative - modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end + modules.patch.adm_scaler_end = adm_scaler_end print(f'[Parameters] ADM Scale = ' f'{modules.patch.positive_adm_scale} : ' f'{modules.patch.negative_adm_scale} : ' diff --git a/webui.py b/webui.py index b190a2822..ba3f9d8c2 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [adm_scaler_end, adaptive_cfg, sampler_name, + adps = [adaptive_cfg, sampler_name, scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end] ctrls += ip_ctrls state_is_generating = gr.State(False) From fc3da75baf77849905c8f55814f426590d9510b0 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 17:27:15 +0100 Subject: [PATCH 14/38] feat: extract attribute adaptive_cfg --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index e90a82956..314a27caf 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -adaptive_cfg, sampler_name, \ +sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -6,11 +6,11 @@ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 31 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 30 def set_all_advanced_parameters(*args): - global adaptive_cfg, sampler_name, \ + global sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ @@ -20,7 +20,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - adaptive_cfg, sampler_name, \ + sampler_name, \ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index e0093cead..6333cc566 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -144,6 +144,7 @@ def handler(async_task): adm_scaler_positive = args.pop() adm_scaler_negative = args.pop() adm_scaler_end = args.pop() + adaptive_cfg = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -194,14 +195,14 @@ def handler(async_task): scheduler_name = advanced_parameters.scheduler_name = 'lcm' modules.patch.sharpness = sharpness = 0.0 cfg_scale = guidance_scale = 1.0 - modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg = 1.0 + modules.patch.adaptive_cfg = adaptive_cfg = 1.0 refiner_switch = 1.0 modules.patch.positive_adm_scale = adm_scaler_positive = 1.0 modules.patch.negative_adm_scale = adm_scaler_negative = 1.0 modules.patch.adm_scaler_end = adm_scaler_end = 0.0 steps = 8 - modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg + modules.patch.adaptive_cfg = adaptive_cfg print(f'[Parameters] Adaptive CFG = {modules.patch.adaptive_cfg}') modules.patch.sharpness = sharpness diff --git a/webui.py b/webui.py index ba3f9d8c2..d8d146e39 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [adaptive_cfg, sampler_name, + adps = [sampler_name, scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] ctrls += ip_ctrls state_is_generating = gr.State(False) From e54bad87f11b6dc06ac1a380c6d94b8521015394 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:00:27 +0100 Subject: [PATCH 15/38] feat: extract attribute sampler_name --- modules/advanced_parameters.py | 11 ++++------- modules/async_worker.py | 4 ++-- webui.py | 5 ++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 314a27caf..0b6765e5f 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,17 +1,15 @@ -sampler_name, \ - scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ +scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 30 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 29 def set_all_advanced_parameters(*args): - global sampler_name, \ - scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + global scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -20,8 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - sampler_name, \ - scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 6333cc566..cf8472d27 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -145,6 +145,7 @@ def handler(async_task): adm_scaler_negative = args.pop() adm_scaler_end = args.pop() adaptive_cfg = args.pop() + sampler_name = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -191,7 +192,7 @@ def handler(async_task): print(f'Refiner disabled in LCM mode.') refiner_model_name = 'None' - sampler_name = advanced_parameters.sampler_name = 'lcm' + sampler_name = 'lcm' scheduler_name = advanced_parameters.scheduler_name = 'lcm' modules.patch.sharpness = sharpness = 0.0 cfg_scale = guidance_scale = 1.0 @@ -244,7 +245,6 @@ def handler(async_task): seed = int(image_seed) print(f'[Parameters] Seed = {seed}') - sampler_name = advanced_parameters.sampler_name scheduler_name = advanced_parameters.scheduler_name goals = [] diff --git a/webui.py b/webui.py index d8d146e39..a60cf2c73 100644 --- a/webui.py +++ b/webui.py @@ -446,8 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [sampler_name, - scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, + adps = [scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -528,7 +527,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name] ctrls += ip_ctrls state_is_generating = gr.State(False) From d72573aca433bbd6b6b1f93368fb409ecefc9b75 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:04:29 +0100 Subject: [PATCH 16/38] feat: extract attribute scheduler_name --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 ++--- webui.py | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 0b6765e5f..ceaa8c25f 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,15 +1,15 @@ -scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ +generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 29 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 28 def set_all_advanced_parameters(*args): - global scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + global generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -18,7 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index cf8472d27..2402f4493 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -146,6 +146,7 @@ def handler(async_task): adm_scaler_end = args.pop() adaptive_cfg = args.pop() sampler_name = args.pop() + scheduler_name = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -193,7 +194,7 @@ def handler(async_task): refiner_model_name = 'None' sampler_name = 'lcm' - scheduler_name = advanced_parameters.scheduler_name = 'lcm' + scheduler_name = 'lcm' modules.patch.sharpness = sharpness = 0.0 cfg_scale = guidance_scale = 1.0 modules.patch.adaptive_cfg = adaptive_cfg = 1.0 @@ -245,8 +246,6 @@ def handler(async_task): seed = int(image_seed) print(f'[Parameters] Seed = {seed}') - scheduler_name = advanced_parameters.scheduler_name - goals = [] tasks = [] diff --git a/webui.py b/webui.py index a60cf2c73..a6b1228fe 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, + adps = [generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -527,7 +527,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name] ctrls += ip_ctrls state_is_generating = gr.State(False) From 217be190bbae0cc10fd04516270558f9e1916ee2 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:23:10 +0100 Subject: [PATCH 17/38] feat: extract attribute generate_image_grid --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 10 +++++----- webui.py | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index ceaa8c25f..cee8ac8b8 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,15 +1,15 @@ -generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ +overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 28 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 27 def set_all_advanced_parameters(*args): - global generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + global overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -18,7 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 2402f4493..0b9ca67b8 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -69,9 +69,6 @@ def yield_result(async_task, imgs, do_not_show_finished_images=False): return def build_image_wall(async_task): - if not advanced_parameters.generate_image_grid: - return - results = async_task.results if len(results) < 2: @@ -279,7 +276,7 @@ def handler(async_task): and isinstance(inpaint_input_image, dict): inpaint_image = inpaint_input_image['image'] inpaint_mask = inpaint_input_image['mask'][:, :, 0] - + if advanced_parameters.inpaint_mask_upload_checkbox: if isinstance(inpaint_mask_image_upload, np.ndarray): if inpaint_mask_image_upload.ndim == 3: @@ -824,9 +821,12 @@ def callback(step, x0, x, total_steps, y): time.sleep(0.01) if len(async_tasks) > 0: task = async_tasks.pop(0) + generate_image_grid = task.args.pop(0) + try: handler(task) - build_image_wall(task) + if generate_image_grid: + build_image_wall(task) task.yields.append(['finish', task.results]) pipeline.prepare_text_encoder(async_call=True) except: diff --git a/webui.py b/webui.py index a6b1228fe..71e6eabfc 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height, + adps = [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -518,7 +518,8 @@ def inpaint_mode_change(mode): inpaint_strength, inpaint_respective_field ], show_progress=False, queue=False) - ctrls = [ + ctrls = [generate_image_grid] + ctrls += [ prompt, negative_prompt, style_selections, performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale ] From df35033cc921c790ac99d9101491e05140b3a593 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:34:06 +0100 Subject: [PATCH 18/38] feat: extract attribute overwrite_step --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index cee8ac8b8..5ef144e53 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,15 +1,15 @@ -overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ +overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 27 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 26 def set_all_advanced_parameters(*args): - global overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + global overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -18,7 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_step, overwrite_switch, overwrite_width, overwrite_height, \ + overwrite_switch, overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 0b9ca67b8..2e2c5829e 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -144,6 +144,7 @@ def handler(async_task): adaptive_cfg = args.pop() sampler_name = args.pop() scheduler_name = args.pop() + overwrite_step = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -338,8 +339,8 @@ def handler(async_task): switch = int(round(steps * refiner_switch)) - if advanced_parameters.overwrite_step > 0: - steps = advanced_parameters.overwrite_step + if overwrite_step > 0: + steps = overwrite_step if advanced_parameters.overwrite_switch > 0: switch = advanced_parameters.overwrite_switch diff --git a/webui.py b/webui.py index 71e6eabfc..7e9becdac 100644 --- a/webui.py +++ b/webui.py @@ -429,7 +429,7 @@ def refresh_seed(r, seed_string): '(default is 0, always process before any mask invert)') inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False) invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False) - + inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate] @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, + adps = [overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step] ctrls += ip_ctrls state_is_generating = gr.State(False) From 2b1f501462892089ef7738761ccccb9dd433f563 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:38:20 +0100 Subject: [PATCH 19/38] feat: extract attribute overwrite_switch --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 5ef144e53..482d0181b 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,15 +1,15 @@ -overwrite_switch, overwrite_width, overwrite_height, \ +overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 26 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 25 def set_all_advanced_parameters(*args): - global overwrite_switch, overwrite_width, overwrite_height, \ + global overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -18,7 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_switch, overwrite_width, overwrite_height, \ + overwrite_width, overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 2e2c5829e..bb63426b8 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -145,6 +145,7 @@ def handler(async_task): sampler_name = args.pop() scheduler_name = args.pop() overwrite_step = args.pop() + overwrite_switch = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -342,8 +343,8 @@ def handler(async_task): if overwrite_step > 0: steps = overwrite_step - if advanced_parameters.overwrite_switch > 0: - switch = advanced_parameters.overwrite_switch + if overwrite_switch > 0: + switch = overwrite_switch if advanced_parameters.overwrite_width > 0: width = advanced_parameters.overwrite_width diff --git a/webui.py b/webui.py index 7e9becdac..59b8ad57c 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_switch, overwrite_width, overwrite_height, + adps = [overwrite_width, overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step, overwrite_switch] ctrls += ip_ctrls state_is_generating = gr.State(False) From 2eed5a28f2e42a1230790729efa54564a79552e5 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:41:02 +0100 Subject: [PATCH 20/38] feat: extract attribute overwrite_width --- modules/advanced_parameters.py | 6 +++--- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 482d0181b..e71cc4c45 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,4 +1,4 @@ -overwrite_width, overwrite_height, \ +overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -9,7 +9,7 @@ def set_all_advanced_parameters(*args): - global overwrite_width, overwrite_height, \ + global overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ @@ -18,7 +18,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_width, overwrite_height, \ + overwrite_height, \ overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index bb63426b8..2cb4fa7a2 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -146,6 +146,7 @@ def handler(async_task): scheduler_name = args.pop() overwrite_step = args.pop() overwrite_switch = args.pop() + overwrite_width = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -346,8 +347,8 @@ def handler(async_task): if overwrite_switch > 0: switch = overwrite_switch - if advanced_parameters.overwrite_width > 0: - width = advanced_parameters.overwrite_width + if overwrite_width > 0: + width = overwrite_width if advanced_parameters.overwrite_height > 0: height = advanced_parameters.overwrite_height diff --git a/webui.py b/webui.py index 59b8ad57c..25a8321cc 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_width, overwrite_height, + adps = [overwrite_height, overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step, overwrite_switch] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step, overwrite_switch, overwrite_width] ctrls += ip_ctrls state_is_generating = gr.State(False) From 9f4a00e868a6bbb73d2865517d14a56a8fc6f8e9 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:42:54 +0100 Subject: [PATCH 21/38] feat: extract attribute overwrite_height --- modules/advanced_parameters.py | 11 ++++------- modules/async_worker.py | 5 +++-- webui.py | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index e71cc4c45..0585c4a80 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,16 +1,14 @@ -overwrite_height, \ - overwrite_vary_strength, overwrite_upscale_strength, \ +overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 25 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 24 def set_all_advanced_parameters(*args): - global overwrite_height, \ - overwrite_vary_strength, overwrite_upscale_strength, \ + global overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ @@ -18,8 +16,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_height, \ - overwrite_vary_strength, overwrite_upscale_strength, \ + overwrite_vary_strength, overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 2cb4fa7a2..7110d9952 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -147,6 +147,7 @@ def handler(async_task): overwrite_step = args.pop() overwrite_switch = args.pop() overwrite_width = args.pop() + overwrite_height = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -350,8 +351,8 @@ def handler(async_task): if overwrite_width > 0: width = overwrite_width - if advanced_parameters.overwrite_height > 0: - height = advanced_parameters.overwrite_height + if overwrite_height > 0: + height = overwrite_height print(f'[Parameters] Sampler = {sampler_name} - {scheduler_name}') print(f'[Parameters] Steps = {steps} - {switch}') diff --git a/webui.py b/webui.py index 25a8321cc..b6ece454d 100644 --- a/webui.py +++ b/webui.py @@ -446,8 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_height, - overwrite_vary_strength, overwrite_upscale_strength, + adps = [overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] @@ -528,7 +527,8 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, scheduler_name, overwrite_step, overwrite_switch, overwrite_width] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name] + ctrls += [scheduler_name, overwrite_step, overwrite_switch, overwrite_width, overwrite_height] ctrls += ip_ctrls state_is_generating = gr.State(False) From 22af976c5181ad57854edd9b15ebbebb828086c6 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:45:01 +0100 Subject: [PATCH 22/38] feat: extract attribute overwrite_vary_strength --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 5 +++-- webui.py | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 0585c4a80..57c72eaac 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,14 +1,14 @@ -overwrite_vary_strength, overwrite_upscale_strength, \ +overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 24 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 23 def set_all_advanced_parameters(*args): - global overwrite_vary_strength, overwrite_upscale_strength, \ + global overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ @@ -16,7 +16,7 @@ def set_all_advanced_parameters(*args): debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_vary_strength, overwrite_upscale_strength, \ + overwrite_upscale_strength, \ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 7110d9952..656657ba0 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -148,6 +148,7 @@ def handler(async_task): overwrite_switch = args.pop() overwrite_width = args.pop() overwrite_height = args.pop() + overwrite_vary_strength = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -451,8 +452,8 @@ def handler(async_task): denoising_strength = 0.5 if 'strong' in uov_method: denoising_strength = 0.85 - if advanced_parameters.overwrite_vary_strength > 0: - denoising_strength = advanced_parameters.overwrite_vary_strength + if overwrite_vary_strength > 0: + denoising_strength = overwrite_vary_strength shape_ceil = get_image_shape_ceil(uov_input_image) if shape_ceil < 1024: diff --git a/webui.py b/webui.py index b6ece454d..506bd30c0 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_vary_strength, overwrite_upscale_strength, + adps = [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] @@ -527,8 +527,9 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image] - ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name] - ctrls += [scheduler_name, overwrite_step, overwrite_switch, overwrite_width, overwrite_height] + ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] + ctrls += [sampler_name, scheduler_name] + ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += ip_ctrls state_is_generating = gr.State(False) From 2ab5593d71358f167cdccffda9f2ccf6590cc1a9 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:46:47 +0100 Subject: [PATCH 23/38] feat: extract attribute overwrite_upscale_strength --- modules/advanced_parameters.py | 11 ++++------- modules/async_worker.py | 5 +++-- webui.py | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 57c72eaac..3e1fa6ece 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,23 +1,20 @@ -overwrite_upscale_strength, \ - mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ +mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 23 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 21 def set_all_advanced_parameters(*args): - global overwrite_upscale_strength, \ - mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ + global mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - overwrite_upscale_strength, \ - mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ + mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 656657ba0..698a45ef4 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -149,6 +149,7 @@ def handler(async_task): overwrite_width = args.pop() overwrite_height = args.pop() overwrite_vary_strength = args.pop() + overwrite_upscale_strength = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -524,8 +525,8 @@ def handler(async_task): tiled = True denoising_strength = 0.382 - if advanced_parameters.overwrite_upscale_strength > 0: - denoising_strength = advanced_parameters.overwrite_upscale_strength + if overwrite_upscale_strength > 0: + denoising_strength = overwrite_upscale_strength initial_pixels = core.numpy_to_pytorch(uov_input_image) progressbar(async_task, 13, 'VAE encoding ...') diff --git a/webui.py b/webui.py index 506bd30c0..b3f3b4765 100644 --- a/webui.py +++ b/webui.py @@ -446,8 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [overwrite_upscale_strength, - mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, + adps = [mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls @@ -530,6 +529,7 @@ def inpaint_mode_change(mode): ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] + ctrls += [overwrite_upscale_strength] ctrls += ip_ctrls state_is_generating = gr.State(False) From cce9871cc5bf7c8c31f70241323ec2ea988177d0 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:49:29 +0100 Subject: [PATCH 24/38] feat: extract attribute mixing_image_prompt_and_vary_upscale --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 7 ++++--- webui.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 3e1fa6ece..d9560f4c8 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,20 +1,20 @@ -mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ +mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 21 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 20 def set_all_advanced_parameters(*args): - global mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ + global mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, \ + mixing_image_prompt_and_inpaint, \ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 698a45ef4..d8ac1e6be 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -150,6 +150,7 @@ def handler(async_task): overwrite_height = args.pop() overwrite_vary_strength = args.pop() overwrite_upscale_strength = args.pop() + mixing_image_prompt_and_vary_upscale = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -254,7 +255,7 @@ def handler(async_task): if input_image_checkbox: if (current_tab == 'uov' or ( - current_tab == 'ip' and advanced_parameters.mixing_image_prompt_and_vary_upscale)) \ + current_tab == 'ip' and mixing_image_prompt_and_vary_upscale)) \ and uov_method != flags.disabled and uov_input_image is not None: uov_input_image = HWC3(uov_input_image) if 'vary' in uov_method: @@ -322,8 +323,8 @@ def handler(async_task): prompt = inpaint_additional_prompt + '\n' + prompt goals.append('inpaint') if current_tab == 'ip' or \ - advanced_parameters.mixing_image_prompt_and_inpaint or \ - advanced_parameters.mixing_image_prompt_and_vary_upscale: + mixing_image_prompt_and_vary_upscale or \ + advanced_parameters.mixing_image_prompt_and_inpaint: goals.append('cn') progressbar(async_task, 1, 'Downloading control models ...') if len(cn_tasks[flags.cn_canny]) > 0: diff --git a/webui.py b/webui.py index b3f3b4765..0672bd0dc 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, + adps = [ mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls @@ -529,7 +529,7 @@ def inpaint_mode_change(mode): ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] - ctrls += [overwrite_upscale_strength] + ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale] ctrls += ip_ctrls state_is_generating = gr.State(False) From 6289e5daead55a374b8bff35e0de1f201142a9d3 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:51:12 +0100 Subject: [PATCH 25/38] feat: extract attribute mixing_image_prompt_and_inpaint --- modules/advanced_parameters.py | 11 ++++------- modules/async_worker.py | 5 +++-- webui.py | 5 ++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index d9560f4c8..3f8d51b9b 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,21 +1,18 @@ -mixing_image_prompt_and_inpaint, \ - debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ +debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 20 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 19 def set_all_advanced_parameters(*args): - global mixing_image_prompt_and_inpaint, \ - debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + global debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - mixing_image_prompt_and_inpaint, \ - debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index d8ac1e6be..c05e6fbda 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -151,6 +151,7 @@ def handler(async_task): overwrite_vary_strength = args.pop() overwrite_upscale_strength = args.pop() mixing_image_prompt_and_vary_upscale = args.pop() + mixing_image_prompt_and_inpaint = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -279,7 +280,7 @@ def handler(async_task): progressbar(async_task, 1, 'Downloading upscale models ...') modules.config.downloading_upscale_model() if (current_tab == 'inpaint' or ( - current_tab == 'ip' and advanced_parameters.mixing_image_prompt_and_inpaint)) \ + current_tab == 'ip' and mixing_image_prompt_and_inpaint)) \ and isinstance(inpaint_input_image, dict): inpaint_image = inpaint_input_image['image'] inpaint_mask = inpaint_input_image['mask'][:, :, 0] @@ -324,7 +325,7 @@ def handler(async_task): goals.append('inpaint') if current_tab == 'ip' or \ mixing_image_prompt_and_vary_upscale or \ - advanced_parameters.mixing_image_prompt_and_inpaint: + mixing_image_prompt_and_inpaint: goals.append('cn') progressbar(async_task, 1, 'Downloading control models ...') if len(cn_tasks[flags.cn_canny]) > 0: diff --git a/webui.py b/webui.py index 0672bd0dc..000ee9fce 100644 --- a/webui.py +++ b/webui.py @@ -446,8 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [ mixing_image_prompt_and_inpaint, - debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, + adps = [debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -529,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg] ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] - ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale] + ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] ctrls += ip_ctrls state_is_generating = gr.State(False) From 0bf41591a68a03c03d01c821eea4da639ba21699 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:52:41 +0100 Subject: [PATCH 26/38] feat: extract attribute debugging_cn_preprocessor --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 9 +++++---- webui.py | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 3f8d51b9b..13920c322 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,18 +1,18 @@ -debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ +skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 19 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 18 def set_all_advanced_parameters(*args): - global debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + global skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index c05e6fbda..0645210c7 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -152,6 +152,7 @@ def handler(async_task): overwrite_upscale_strength = args.pop() mixing_image_prompt_and_vary_upscale = args.pop() mixing_image_prompt_and_inpaint = args.pop() + debugging_cn_preprocessor = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -648,7 +649,7 @@ def handler(async_task): cn_img = HWC3(cn_img) task[0] = core.numpy_to_pytorch(cn_img) - if advanced_parameters.debugging_cn_preprocessor: + if debugging_cn_preprocessor: yield_result(async_task, cn_img, do_not_show_finished_images=True) return for task in cn_tasks[flags.cn_cpds]: @@ -660,7 +661,7 @@ def handler(async_task): cn_img = HWC3(cn_img) task[0] = core.numpy_to_pytorch(cn_img) - if advanced_parameters.debugging_cn_preprocessor: + if debugging_cn_preprocessor: yield_result(async_task, cn_img, do_not_show_finished_images=True) return for task in cn_tasks[flags.cn_ip]: @@ -671,7 +672,7 @@ def handler(async_task): cn_img = resize_image(cn_img, width=224, height=224, resize_mode=0) task[0] = ip_adapter.preprocess(cn_img, ip_adapter_path=ip_adapter_path) - if advanced_parameters.debugging_cn_preprocessor: + if debugging_cn_preprocessor: yield_result(async_task, cn_img, do_not_show_finished_images=True) return for task in cn_tasks[flags.cn_ip_face]: @@ -685,7 +686,7 @@ def handler(async_task): cn_img = resize_image(cn_img, width=224, height=224, resize_mode=0) task[0] = ip_adapter.preprocess(cn_img, ip_adapter_path=ip_adapter_face_path) - if advanced_parameters.debugging_cn_preprocessor: + if debugging_cn_preprocessor: yield_result(async_task, cn_img, do_not_show_finished_images=True) return diff --git a/webui.py b/webui.py index 000ee9fce..a4d6b49f7 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, + adps = [skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -529,6 +529,7 @@ def inpaint_mode_change(mode): ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] + ctrls += [debugging_cn_preprocessor] ctrls += ip_ctrls state_is_generating = gr.State(False) From 9f194a91fae3522854a6945f3a6093b5af428f67 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 18:54:01 +0100 Subject: [PATCH 27/38] feat: extract attribute skipping_cn_preprocessor --- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 7 ++++--- webui.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 13920c322..134eeba4a 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,18 +1,18 @@ -skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ +controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 18 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 17 def set_all_advanced_parameters(*args): - global skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + global controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \ + controlnet_softness, canny_low_threshold, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 0645210c7..53fda5ac7 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -153,6 +153,7 @@ def handler(async_task): mixing_image_prompt_and_vary_upscale = args.pop() mixing_image_prompt_and_inpaint = args.pop() debugging_cn_preprocessor = args.pop() + skipping_cn_preprocessor = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -644,7 +645,7 @@ def handler(async_task): cn_img, cn_stop, cn_weight = task cn_img = resize_image(HWC3(cn_img), width=width, height=height) - if not advanced_parameters.skipping_cn_preprocessor: + if not skipping_cn_preprocessor: cn_img = preprocessors.canny_pyramid(cn_img) cn_img = HWC3(cn_img) @@ -656,7 +657,7 @@ def handler(async_task): cn_img, cn_stop, cn_weight = task cn_img = resize_image(HWC3(cn_img), width=width, height=height) - if not advanced_parameters.skipping_cn_preprocessor: + if not skipping_cn_preprocessor: cn_img = preprocessors.cpds(cn_img) cn_img = HWC3(cn_img) @@ -679,7 +680,7 @@ def handler(async_task): cn_img, cn_stop, cn_weight = task cn_img = HWC3(cn_img) - if not advanced_parameters.skipping_cn_preprocessor: + if not skipping_cn_preprocessor: cn_img = extras.face_crop.crop_image(cn_img) # https://github.com/tencent-ailab/IP-Adapter/blob/d580c50a291566bbf9fc7ac0f760506607297e6d/README.md?plain=1#L75 diff --git a/webui.py b/webui.py index a4d6b49f7..8b940ceb3 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [skipping_cn_preprocessor, controlnet_softness, + adps = [controlnet_softness, canny_low_threshold, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -529,7 +529,7 @@ def inpaint_mode_change(mode): ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] - ctrls += [debugging_cn_preprocessor] + ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor] ctrls += ip_ctrls state_is_generating = gr.State(False) From ec486443ea83bedbaf5aabc0037f7a4948961153 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:06:10 +0100 Subject: [PATCH 28/38] feat: extract attribute canny_low_threshold --- extras/preprocessors.py | 16 ++++++++-------- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 3 ++- webui.py | 5 ++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/extras/preprocessors.py b/extras/preprocessors.py index 798fe15d2..05f7c2fdf 100644 --- a/extras/preprocessors.py +++ b/extras/preprocessors.py @@ -3,25 +3,25 @@ import modules.advanced_parameters as advanced_parameters -def centered_canny(x: np.ndarray): +def centered_canny(x: np.ndarray, canny_low_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 2 and x.dtype == np.uint8 - y = cv2.Canny(x, int(advanced_parameters.canny_low_threshold), int(advanced_parameters.canny_high_threshold)) + y = cv2.Canny(x, int(canny_low_threshold), int(advanced_parameters.canny_high_threshold)) y = y.astype(np.float32) / 255.0 return y -def centered_canny_color(x: np.ndarray): +def centered_canny_color(x: np.ndarray, canny_low_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 - result = [centered_canny(x[..., i]) for i in range(3)] + result = [centered_canny(x[..., i], canny_low_threshold) for i in range(3)] result = np.stack(result, axis=2) return result -def pyramid_canny_color(x: np.ndarray): +def pyramid_canny_color(x: np.ndarray, canny_low_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 @@ -31,7 +31,7 @@ def pyramid_canny_color(x: np.ndarray): for k in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]: Hs, Ws = int(H * k), int(W * k) small = cv2.resize(x, (Ws, Hs), interpolation=cv2.INTER_AREA) - edge = centered_canny_color(small) + edge = centered_canny_color(small, canny_low_threshold) if acc_edge is None: acc_edge = edge else: @@ -54,11 +54,11 @@ def norm255(x, low=4, high=96): return x * 255.0 -def canny_pyramid(x): +def canny_pyramid(x, canny_low_threshold): # For some reasons, SAI's Control-lora Canny seems to be trained on canny maps with non-standard resolutions. # Then we use pyramid to use all resolutions to avoid missing any structure in specific resolutions. - color_canny = pyramid_canny_color(x) + color_canny = pyramid_canny_color(x, canny_low_threshold) result = np.sum(color_canny, axis=2) return norm255(result, low=1, high=99).clip(0, 255).astype(np.uint8) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 134eeba4a..3614c9fea 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,18 +1,18 @@ -controlnet_softness, canny_low_threshold, canny_high_threshold, \ +controlnet_softness, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 17 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 16 def set_all_advanced_parameters(*args): - global controlnet_softness, canny_low_threshold, canny_high_threshold, \ + global controlnet_softness, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - controlnet_softness, canny_low_threshold, canny_high_threshold, \ + controlnet_softness, canny_high_threshold, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 53fda5ac7..13b63bf41 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -154,6 +154,7 @@ def handler(async_task): mixing_image_prompt_and_inpaint = args.pop() debugging_cn_preprocessor = args.pop() skipping_cn_preprocessor = args.pop() + canny_low_threshold = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -646,7 +647,7 @@ def handler(async_task): cn_img = resize_image(HWC3(cn_img), width=width, height=height) if not skipping_cn_preprocessor: - cn_img = preprocessors.canny_pyramid(cn_img) + cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold) cn_img = HWC3(cn_img) task[0] = core.numpy_to_pytorch(cn_img) diff --git a/webui.py b/webui.py index 8b940ceb3..be0dda865 100644 --- a/webui.py +++ b/webui.py @@ -446,8 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [controlnet_softness, - canny_low_threshold, canny_high_threshold, refiner_swap_method] + adps = [controlnet_softness, canny_high_threshold, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -529,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] - ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor] + ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold] ctrls += ip_ctrls state_is_generating = gr.State(False) From 2d8ca41ce53de3950e2b3494634b4743c0c723b4 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:08:54 +0100 Subject: [PATCH 29/38] feat: extract attribute canny_high_threshold --- extras/preprocessors.py | 16 ++++++++-------- modules/advanced_parameters.py | 8 ++++---- modules/async_worker.py | 3 ++- webui.py | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/extras/preprocessors.py b/extras/preprocessors.py index 05f7c2fdf..7720c0854 100644 --- a/extras/preprocessors.py +++ b/extras/preprocessors.py @@ -3,25 +3,25 @@ import modules.advanced_parameters as advanced_parameters -def centered_canny(x: np.ndarray, canny_low_threshold): +def centered_canny(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 2 and x.dtype == np.uint8 - y = cv2.Canny(x, int(canny_low_threshold), int(advanced_parameters.canny_high_threshold)) + y = cv2.Canny(x, int(canny_low_threshold), int(canny_high_threshold)) y = y.astype(np.float32) / 255.0 return y -def centered_canny_color(x: np.ndarray, canny_low_threshold): +def centered_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 - result = [centered_canny(x[..., i], canny_low_threshold) for i in range(3)] + result = [centered_canny(x[..., i], canny_low_threshold, canny_high_threshold) for i in range(3)] result = np.stack(result, axis=2) return result -def pyramid_canny_color(x: np.ndarray, canny_low_threshold): +def pyramid_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 @@ -31,7 +31,7 @@ def pyramid_canny_color(x: np.ndarray, canny_low_threshold): for k in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]: Hs, Ws = int(H * k), int(W * k) small = cv2.resize(x, (Ws, Hs), interpolation=cv2.INTER_AREA) - edge = centered_canny_color(small, canny_low_threshold) + edge = centered_canny_color(small, canny_low_threshold, canny_high_threshold) if acc_edge is None: acc_edge = edge else: @@ -54,11 +54,11 @@ def norm255(x, low=4, high=96): return x * 255.0 -def canny_pyramid(x, canny_low_threshold): +def canny_pyramid(x, canny_low_threshold, canny_high_threshold): # For some reasons, SAI's Control-lora Canny seems to be trained on canny maps with non-standard resolutions. # Then we use pyramid to use all resolutions to avoid missing any structure in specific resolutions. - color_canny = pyramid_canny_color(x, canny_low_threshold) + color_canny = pyramid_canny_color(x, canny_low_threshold, canny_high_threshold) result = np.sum(color_canny, axis=2) return norm255(result, low=1, high=99).clip(0, 255).astype(np.uint8) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 3614c9fea..f512afc37 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,18 +1,18 @@ -controlnet_softness, canny_high_threshold, \ +controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 16 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 15 def set_all_advanced_parameters(*args): - global controlnet_softness, canny_high_threshold, \ + global controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - controlnet_softness, canny_high_threshold, \ + controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 13b63bf41..192c44e77 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -155,6 +155,7 @@ def handler(async_task): debugging_cn_preprocessor = args.pop() skipping_cn_preprocessor = args.pop() canny_low_threshold = args.pop() + canny_high_threshold = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -647,7 +648,7 @@ def handler(async_task): cn_img = resize_image(HWC3(cn_img), width=width, height=height) if not skipping_cn_preprocessor: - cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold) + cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold, canny_high_threshold) cn_img = HWC3(cn_img) task[0] = core.numpy_to_pytorch(cn_img) diff --git a/webui.py b/webui.py index be0dda865..790b2d417 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [controlnet_softness, canny_high_threshold, refiner_swap_method] + adps = [controlnet_softness, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -528,7 +528,7 @@ def inpaint_mode_change(mode): ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] - ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold] + ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] ctrls += ip_ctrls state_is_generating = gr.State(False) From cfb70c0278ec3d2d334cf76321f2b3fc2795f4a5 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:10:32 +0100 Subject: [PATCH 30/38] feat: extract attribute refiner_swap_method --- modules/advanced_parameters.py | 5 +---- modules/async_worker.py | 2 +- webui.py | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index f512afc37..bc5c0bd56 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,19 +1,16 @@ controlnet_softness, \ - refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 15 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 14 def set_all_advanced_parameters(*args): global controlnet_softness, \ - refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate controlnet_softness, \ - refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = args diff --git a/modules/async_worker.py b/modules/async_worker.py index 192c44e77..301918c2d 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -156,6 +156,7 @@ def handler(async_task): skipping_cn_preprocessor = args.pop() canny_low_threshold = args.pop() canny_high_threshold = args.pop() + refiner_swap_method = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -238,7 +239,6 @@ def handler(async_task): width, height = int(width), int(height) skip_prompt_processing = False - refiner_swap_method = advanced_parameters.refiner_swap_method inpaint_worker.current_task = None inpaint_parameterized = advanced_parameters.inpaint_engine != 'None' diff --git a/webui.py b/webui.py index 790b2d417..c26dcb5b9 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [controlnet_softness, refiner_swap_method] + adps = [controlnet_softness] adps += freeu_ctrls adps += inpaint_ctrls @@ -529,6 +529,7 @@ def inpaint_mode_change(mode): ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] + ctrls += [refiner_swap_method] ctrls += ip_ctrls state_is_generating = gr.State(False) From eb1d3938fe5774f4ada7e9d6738a7836a8880a70 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:14:42 +0100 Subject: [PATCH 31/38] feat: extract freeu_ctrls attributes freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2 --- modules/advanced_parameters.py | 5 +---- modules/async_worker.py | 15 ++++++++++----- webui.py | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index bc5c0bd56..141546b4a 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,17 +1,14 @@ controlnet_softness, \ - freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 14 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 9 def set_all_advanced_parameters(*args): global controlnet_softness, \ - freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate controlnet_softness, \ - freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = args diff --git a/modules/async_worker.py b/modules/async_worker.py index 301918c2d..22c33c741 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -157,6 +157,11 @@ def handler(async_task): canny_low_threshold = args.pop() canny_high_threshold = args.pop() refiner_swap_method = args.pop() + freeu_enabled = args.pop() + freeu_b1 = args.pop() + freeu_b2 = args.pop() + freeu_s1 = args.pop() + freeu_s2 = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -698,14 +703,14 @@ def handler(async_task): if len(all_ip_tasks) > 0: pipeline.final_unet = ip_adapter.patch_model(pipeline.final_unet, all_ip_tasks) - if advanced_parameters.freeu_enabled: + if freeu_enabled: print(f'FreeU is enabled!') pipeline.final_unet = core.apply_freeu( pipeline.final_unet, - advanced_parameters.freeu_b1, - advanced_parameters.freeu_b2, - advanced_parameters.freeu_s1, - advanced_parameters.freeu_s2 + freeu_b1, + freeu_b2, + freeu_s1, + freeu_s2 ) all_steps = steps * image_number diff --git a/webui.py b/webui.py index c26dcb5b9..75bc7ceb2 100644 --- a/webui.py +++ b/webui.py @@ -447,7 +447,6 @@ def refresh_seed(r, seed_string): freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] adps = [controlnet_softness] - adps += freeu_ctrls adps += inpaint_ctrls def dev_mode_checked(r): @@ -530,6 +529,7 @@ def inpaint_mode_change(mode): ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] ctrls += [refiner_swap_method] + ctrls += freeu_ctrls ctrls += ip_ctrls state_is_generating = gr.State(False) From 4ce27aeb0fbf257a119359dee481fd8a223d61bb Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:20:04 +0100 Subject: [PATCH 32/38] feat: extract inpaint_ctrls attributes debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate --- modules/advanced_parameters.py | 12 +++--------- modules/async_worker.py | 32 ++++++++++++++++++++------------ webui.py | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 141546b4a..a9cd1f313 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,15 +1,9 @@ -controlnet_softness, \ - debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 9 +controlnet_softness, = [None] def set_all_advanced_parameters(*args): - global controlnet_softness, \ - debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate + global controlnet_softness - controlnet_softness, \ - debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = args + controlnet_softness = args return diff --git a/modules/async_worker.py b/modules/async_worker.py index 22c33c741..0af887941 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -162,6 +162,14 @@ def handler(async_task): freeu_b2 = args.pop() freeu_s1 = args.pop() freeu_s2 = args.pop() + debugging_inpaint_preprocessor = args.pop() + inpaint_disable_initial_latent = args.pop() + inpaint_engine = args.pop() + inpaint_strength = args.pop() + inpaint_respective_field = args.pop() + inpaint_mask_upload_checkbox = args.pop() + invert_mask_checkbox = args.pop() + inpaint_erode_or_dilate = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -246,7 +254,7 @@ def handler(async_task): skip_prompt_processing = False inpaint_worker.current_task = None - inpaint_parameterized = advanced_parameters.inpaint_engine != 'None' + inpaint_parameterized = inpaint_engine != 'None' inpaint_image = None inpaint_mask = None inpaint_head_model_path = None @@ -294,7 +302,7 @@ def handler(async_task): inpaint_image = inpaint_input_image['image'] inpaint_mask = inpaint_input_image['mask'][:, :, 0] - if advanced_parameters.inpaint_mask_upload_checkbox: + if inpaint_mask_upload_checkbox: if isinstance(inpaint_mask_image_upload, np.ndarray): if inpaint_mask_image_upload.ndim == 3: H, W, C = inpaint_image.shape @@ -303,10 +311,10 @@ def handler(async_task): inpaint_mask_image_upload = (inpaint_mask_image_upload > 127).astype(np.uint8) * 255 inpaint_mask = np.maximum(inpaint_mask, inpaint_mask_image_upload) - if int(advanced_parameters.inpaint_erode_or_dilate) != 0: - inpaint_mask = erode_or_dilate(inpaint_mask, advanced_parameters.inpaint_erode_or_dilate) + if int(inpaint_erode_or_dilate) != 0: + inpaint_mask = erode_or_dilate(inpaint_mask, inpaint_erode_or_dilate) - if advanced_parameters.invert_mask_checkbox: + if invert_mask_checkbox: inpaint_mask = 255 - inpaint_mask inpaint_image = HWC3(inpaint_image) @@ -317,7 +325,7 @@ def handler(async_task): if inpaint_parameterized: progressbar(async_task, 1, 'Downloading inpainter ...') inpaint_head_model_path, inpaint_patch_model_path = modules.config.downloading_inpaint_models( - advanced_parameters.inpaint_engine) + inpaint_engine) base_model_additional_loras += [(inpaint_patch_model_path, 1.0)] print(f'[Inpaint] Current inpaint model is {inpaint_patch_model_path}') if refiner_model_name == 'None': @@ -581,19 +589,19 @@ def handler(async_task): inpaint_image = np.ascontiguousarray(inpaint_image.copy()) inpaint_mask = np.ascontiguousarray(inpaint_mask.copy()) - advanced_parameters.inpaint_strength = 1.0 - advanced_parameters.inpaint_respective_field = 1.0 + inpaint_strength = 1.0 + inpaint_respective_field = 1.0 - denoising_strength = advanced_parameters.inpaint_strength + denoising_strength = inpaint_strength inpaint_worker.current_task = inpaint_worker.InpaintWorker( image=inpaint_image, mask=inpaint_mask, use_fill=denoising_strength > 0.99, - k=advanced_parameters.inpaint_respective_field + k=inpaint_respective_field ) - if advanced_parameters.debugging_inpaint_preprocessor: + if debugging_inpaint_preprocessor: yield_result(async_task, inpaint_worker.current_task.visualize_mask_processing(), do_not_show_finished_images=True) return @@ -639,7 +647,7 @@ def handler(async_task): model=pipeline.final_unet ) - if not advanced_parameters.inpaint_disable_initial_latent: + if not inpaint_disable_initial_latent: initial_latent = {'samples': latent_fill} B, C, H, W = latent_fill.shape diff --git a/webui.py b/webui.py index 75bc7ceb2..ddab05f2a 100644 --- a/webui.py +++ b/webui.py @@ -447,7 +447,6 @@ def refresh_seed(r, seed_string): freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] adps = [controlnet_softness] - adps += inpaint_ctrls def dev_mode_checked(r): return gr.update(visible=r) @@ -530,6 +529,7 @@ def inpaint_mode_change(mode): ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] ctrls += [refiner_swap_method] ctrls += freeu_ctrls + ctrls += inpaint_ctrls ctrls += ip_ctrls state_is_generating = gr.State(False) From 18446dc3a5c96c5252270b760a5a7eb4f42d306f Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:23:22 +0100 Subject: [PATCH 33/38] wip: add TODOs --- modules/patch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/patch.py b/modules/patch.py index 2e2409c54..84f82950f 100644 --- a/modules/patch.py +++ b/modules/patch.py @@ -28,6 +28,8 @@ from modules.patch_precision import patch_all_precision from modules.patch_clip import patch_all_clip +# TODO make these parameters dynamic: +# TODO sharpness, adm_scaler_end, positive_adm_scale, negative_adm_scale, adaptive_cfg + controlnet_softness sharpness = 2.0 From 78d2ec8d778356b1a4178333e3f330c067fdc9bf Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 19:52:25 +0100 Subject: [PATCH 34/38] chore: cleanup code --- modules/advanced_parameters.py | 4 +--- modules/async_worker.py | 13 ++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index a9cd1f313..bbd00b227 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,9 +1,7 @@ -controlnet_softness, = [None] +controlnet_softness = None def set_all_advanced_parameters(*args): global controlnet_softness controlnet_softness = args - - return diff --git a/modules/async_worker.py b/modules/async_worker.py index 0af887941..ece207d83 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -31,7 +31,6 @@ def worker(): import extras.preprocessors as preprocessors import modules.inpaint_worker as inpaint_worker import modules.constants as constants - import modules.advanced_parameters as advanced_parameters import extras.ip_adapter as ip_adapter import extras.face_crop import fooocus_version @@ -218,13 +217,13 @@ def handler(async_task): refiner_model_name = 'None' sampler_name = 'lcm' scheduler_name = 'lcm' - modules.patch.sharpness = sharpness = 0.0 - cfg_scale = guidance_scale = 1.0 - modules.patch.adaptive_cfg = adaptive_cfg = 1.0 + sharpness = 0.0 + guidance_scale = 1.0 + adaptive_cfg = 1.0 refiner_switch = 1.0 - modules.patch.positive_adm_scale = adm_scaler_positive = 1.0 - modules.patch.negative_adm_scale = adm_scaler_negative = 1.0 - modules.patch.adm_scaler_end = adm_scaler_end = 0.0 + adm_scaler_positive = 1.0 + adm_scaler_negative = 1.0 + adm_scaler_end = 0.0 steps = 8 modules.patch.adaptive_cfg = adaptive_cfg From f3222b0f274bf8296a6f74e1e2e5b87198e51ac3 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 20:09:24 +0100 Subject: [PATCH 35/38] feat: extract attribute controlnet_softness --- extras/preprocessors.py | 1 - modules/advanced_parameters.py | 7 ------- modules/async_worker.py | 4 ++++ modules/core.py | 1 - modules/patch.py | 8 ++++---- webui.py | 6 +----- 6 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 modules/advanced_parameters.py diff --git a/extras/preprocessors.py b/extras/preprocessors.py index 7720c0854..0aa83109a 100644 --- a/extras/preprocessors.py +++ b/extras/preprocessors.py @@ -1,6 +1,5 @@ import cv2 import numpy as np -import modules.advanced_parameters as advanced_parameters def centered_canny(x: np.ndarray, canny_low_threshold, canny_high_threshold): diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py deleted file mode 100644 index bbd00b227..000000000 --- a/modules/advanced_parameters.py +++ /dev/null @@ -1,7 +0,0 @@ -controlnet_softness = None - - -def set_all_advanced_parameters(*args): - global controlnet_softness - - controlnet_softness = args diff --git a/modules/async_worker.py b/modules/async_worker.py index ece207d83..9b198442c 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -156,6 +156,7 @@ def handler(async_task): canny_low_threshold = args.pop() canny_high_threshold = args.pop() refiner_swap_method = args.pop() + controlnet_softness = args.pop() freeu_enabled = args.pop() freeu_b1 = args.pop() freeu_b2 = args.pop() @@ -232,6 +233,9 @@ def handler(async_task): modules.patch.sharpness = sharpness print(f'[Parameters] Sharpness = {modules.patch.sharpness}') + modules.patch.controlnet_softness = controlnet_softness + print(f'[Parameters] ControlNet Softness = {modules.patch.controlnet_softness}') + modules.patch.positive_adm_scale = adm_scaler_positive modules.patch.negative_adm_scale = adm_scaler_negative modules.patch.adm_scaler_end = adm_scaler_end diff --git a/modules/core.py b/modules/core.py index 2d3255593..957a91524 100644 --- a/modules/core.py +++ b/modules/core.py @@ -16,7 +16,6 @@ import modules.sample_hijack import ldm_patched.modules.samplers import ldm_patched.modules.latent_formats -import modules.advanced_parameters from ldm_patched.modules.sd import load_checkpoint_guess_config from ldm_patched.contrib.external import VAEDecode, EmptyLatentImage, VAEEncode, VAEEncodeTiled, VAEDecodeTiled, \ diff --git a/modules/patch.py b/modules/patch.py index 84f82950f..2d5ebb517 100644 --- a/modules/patch.py +++ b/modules/patch.py @@ -17,7 +17,6 @@ import ldm_patched.modules.model_patcher import ldm_patched.modules.samplers import ldm_patched.modules.args_parser -import modules.advanced_parameters as advanced_parameters import warnings import safetensors.torch import modules.constants as constants @@ -37,11 +36,12 @@ positive_adm_scale = 1.5 negative_adm_scale = 0.8 +controlnet_softness = 0.25 + adaptive_cfg = 7.0 global_diffusion_progress = 0 eps_record = None - def calculate_weight_patched(self, patches, weight, key): for p in patches: alpha = p[0] @@ -359,10 +359,10 @@ def patched_cldm_forward(self, x, hint, timesteps, context, y=None, **kwargs): h = self.middle_block(h, emb, context) outs.append(self.middle_block_out(h, emb, context)) - if advanced_parameters.controlnet_softness > 0: + if controlnet_softness > 0: for i in range(10): k = 1.0 - float(i) / 9.0 - outs[i] = outs[i] * (1.0 - advanced_parameters.controlnet_softness * k) + outs[i] = outs[i] * (1.0 - controlnet_softness * k) return outs diff --git a/webui.py b/webui.py index ddab05f2a..aa4a58dc9 100644 --- a/webui.py +++ b/webui.py @@ -11,7 +11,6 @@ import modules.constants as constants import modules.flags as flags import modules.gradio_hijack as grh -import modules.advanced_parameters as advanced_parameters import modules.style_sorter as style_sorter import modules.meta_parser import args_manager @@ -446,8 +445,6 @@ def refresh_seed(r, seed_string): freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [controlnet_softness] - def dev_mode_checked(r): return gr.update(visible=r) @@ -527,7 +524,7 @@ def inpaint_mode_change(mode): ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] - ctrls += [refiner_swap_method] + ctrls += [refiner_swap_method, controlnet_softness] ctrls += freeu_ctrls ctrls += inpaint_ctrls ctrls += ip_ctrls @@ -584,7 +581,6 @@ def parse_meta(raw_prompt_txt, is_generating): generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True), outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ - .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False), outputs=[generate_button, stop_button, skip_button, state_is_generating]) \ From 177075ff7bc43ac392edc3e7826d8e238fdd471b Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 21:13:44 +0100 Subject: [PATCH 36/38] feat: extract remaining attributes, do not use globals in patch --- modules/async_worker.py | 45 ++++++++++++++---------- modules/default_pipeline.py | 6 ++-- modules/patch.py | 69 ++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 57 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 9b198442c..790ec118d 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -1,5 +1,6 @@ import threading - +import os +from modules.patch import PatchSettings, patch_settings class AsyncTask: def __init__(self, args): @@ -42,6 +43,9 @@ def worker(): get_image_shape_ceil, set_image_shape_ceil, get_shape_ceil, resample_image, erode_or_dilate from modules.upscaler import perform_upscale + pid = os.getpid() + print(f'Started worker with PID {pid}') + try: async_gradio_app = shared.gradio_root flag = f'''App started successful. Use the app with {str(async_gradio_app.local_url)} or {str(async_gradio_app.server_name)}:{str(async_gradio_app.server_port)}''' @@ -227,22 +231,22 @@ def handler(async_task): adm_scaler_end = 0.0 steps = 8 - modules.patch.adaptive_cfg = adaptive_cfg - print(f'[Parameters] Adaptive CFG = {modules.patch.adaptive_cfg}') - - modules.patch.sharpness = sharpness - print(f'[Parameters] Sharpness = {modules.patch.sharpness}') - - modules.patch.controlnet_softness = controlnet_softness - print(f'[Parameters] ControlNet Softness = {modules.patch.controlnet_softness}') - - modules.patch.positive_adm_scale = adm_scaler_positive - modules.patch.negative_adm_scale = adm_scaler_negative - modules.patch.adm_scaler_end = adm_scaler_end + print(f'[Parameters] Adaptive CFG = {adaptive_cfg}') + print(f'[Parameters] Sharpness = {sharpness}') + print(f'[Parameters] ControlNet Softness = {controlnet_softness}') print(f'[Parameters] ADM Scale = ' - f'{modules.patch.positive_adm_scale} : ' - f'{modules.patch.negative_adm_scale} : ' - f'{modules.patch.adm_scaler_end}') + f'{adm_scaler_positive} : ' + f'{adm_scaler_negative} : ' + f'{adm_scaler_end}') + + patch_settings[pid] = PatchSettings( + sharpness, + adm_scaler_end, + adm_scaler_positive, + adm_scaler_negative, + controlnet_softness, + adaptive_cfg + ) cfg_scale = float(guidance_scale) print(f'[Parameters] CFG = {cfg_scale}') @@ -815,9 +819,9 @@ def callback(step, x0, x, total_steps, y): ('Sharpness', sharpness), ('Guidance Scale', guidance_scale), ('ADM Guidance', str(( - modules.patch.positive_adm_scale, - modules.patch.negative_adm_scale, - modules.patch.adm_scaler_end))), + modules.patch.patch_settings[pid].positive_adm_scale, + modules.patch.patch_settings[pid].negative_adm_scale, + modules.patch.patch_settings[pid].adm_scaler_end))), ('Base Model', base_model_name), ('Refiner Model', refiner_model_name), ('Refiner Switch', refiner_switch), @@ -860,6 +864,9 @@ def callback(step, x0, x, total_steps, y): except: traceback.print_exc() task.yields.append(['finish', task.results]) + finally: + if pid in modules.patch.patch_settings: + del modules.patch.patch_settings[os.getpid()] pass diff --git a/modules/default_pipeline.py b/modules/default_pipeline.py index 5f66a36ed..2f45667cf 100644 --- a/modules/default_pipeline.py +++ b/modules/default_pipeline.py @@ -425,7 +425,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height decoded_latent = core.decode_vae(vae=target_model, latent_image=sampled_latent, tiled=tiled) if refiner_swap_method == 'vae': - modules.patch.eps_record = 'vae' + modules.patch.patch_settings[os.getpid()].eps_record = 'vae' if modules.inpaint_worker.current_task is not None: modules.inpaint_worker.current_task.unswap() @@ -463,7 +463,7 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height denoise=denoise)[switch:] * k_sigmas len_sigmas = len(sigmas) - 1 - noise_mean = torch.mean(modules.patch.eps_record, dim=1, keepdim=True) + noise_mean = torch.mean(modules.patch.patch_settings[os.getpid()].eps_record, dim=1, keepdim=True) if modules.inpaint_worker.current_task is not None: modules.inpaint_worker.current_task.swap() @@ -493,5 +493,5 @@ def process_diffusion(positive_cond, negative_cond, steps, switch, width, height decoded_latent = core.decode_vae(vae=target_model, latent_image=sampled_latent, tiled=tiled) images = core.pytorch_to_numpy(decoded_latent) - modules.patch.eps_record = None + modules.patch.patch_settings[os.getpid()].eps_record = None return images diff --git a/modules/patch.py b/modules/patch.py index 2d5ebb517..100613a82 100644 --- a/modules/patch.py +++ b/modules/patch.py @@ -27,20 +27,27 @@ from modules.patch_precision import patch_all_precision from modules.patch_clip import patch_all_clip -# TODO make these parameters dynamic: -# TODO sharpness, adm_scaler_end, positive_adm_scale, negative_adm_scale, adaptive_cfg + controlnet_softness -sharpness = 2.0 +class PatchSettings: + def __init__(self, + sharpness=2.0, + adm_scaler_end=0.3, + positive_adm_scale=1.5, + negative_adm_scale=0.8, + controlnet_softness=0.25, + adaptive_cfg=7.0): + self.sharpness = sharpness + self.adm_scaler_end = adm_scaler_end + self.positive_adm_scale = positive_adm_scale + self.negative_adm_scale = negative_adm_scale + self.controlnet_softness = controlnet_softness + self.adaptive_cfg = adaptive_cfg + self.global_diffusion_progress = 0 + self.eps_record = None -adm_scaler_end = 0.3 -positive_adm_scale = 1.5 -negative_adm_scale = 0.8 -controlnet_softness = 0.25 +patch_settings = {} -adaptive_cfg = 7.0 -global_diffusion_progress = 0 -eps_record = None def calculate_weight_patched(self, patches, weight, key): for p in patches: @@ -203,14 +210,12 @@ def __call__(sigma, sigma_next): def compute_cfg(uncond, cond, cfg_scale, t): - global adaptive_cfg - - mimic_cfg = float(adaptive_cfg) + mimic_cfg = float(patch_settings[os.getpid()].adaptive_cfg) real_cfg = float(cfg_scale) real_eps = uncond + real_cfg * (cond - uncond) - if cfg_scale > adaptive_cfg: + if cfg_scale > patch_settings[os.getpid()].adaptive_cfg: mimicked_eps = uncond + mimic_cfg * (cond - uncond) return real_eps * t + mimicked_eps * (1 - t) else: @@ -218,13 +223,11 @@ def compute_cfg(uncond, cond, cfg_scale, t): def patched_sampling_function(model, x, timestep, uncond, cond, cond_scale, model_options=None, seed=None): - global eps_record - if math.isclose(cond_scale, 1.0) and not model_options.get("disable_cfg1_optimization", False): final_x0 = calc_cond_uncond_batch(model, cond, None, x, timestep, model_options)[0] - if eps_record is not None: - eps_record = ((x - final_x0) / timestep).cpu() + if patch_settings[os.getpid()].eps_record is not None: + patch_settings[os.getpid()].eps_record = ((x - final_x0) / timestep).cpu() return final_x0 @@ -233,16 +236,16 @@ def patched_sampling_function(model, x, timestep, uncond, cond, cond_scale, mode positive_eps = x - positive_x0 negative_eps = x - negative_x0 - alpha = 0.001 * sharpness * global_diffusion_progress + alpha = 0.001 * patch_settings[os.getpid()].sharpness * patch_settings[os.getpid()].global_diffusion_progress positive_eps_degraded = anisotropic.adaptive_anisotropic_filter(x=positive_eps, g=positive_x0) positive_eps_degraded_weighted = positive_eps_degraded * alpha + positive_eps * (1.0 - alpha) final_eps = compute_cfg(uncond=negative_eps, cond=positive_eps_degraded_weighted, - cfg_scale=cond_scale, t=global_diffusion_progress) + cfg_scale=cond_scale, t=patch_settings[os.getpid()].global_diffusion_progress) - if eps_record is not None: - eps_record = (final_eps / timestep).cpu() + if patch_settings[os.getpid()].eps_record is not None: + patch_settings[os.getpid()].eps_record = (final_eps / timestep).cpu() return x - final_eps @@ -257,8 +260,6 @@ def round_to_64(x): def sdxl_encode_adm_patched(self, **kwargs): - global positive_adm_scale, negative_adm_scale - clip_pooled = ldm_patched.modules.model_base.sdxl_pooled(kwargs, self.noise_augmentor) width = kwargs.get("width", 1024) height = kwargs.get("height", 1024) @@ -266,11 +267,11 @@ def sdxl_encode_adm_patched(self, **kwargs): target_height = height if kwargs.get("prompt_type", "") == "negative": - width = float(width) * negative_adm_scale - height = float(height) * negative_adm_scale + width = float(width) * patch_settings[os.getpid()].negative_adm_scale + height = float(height) * patch_settings[os.getpid()].negative_adm_scale elif kwargs.get("prompt_type", "") == "positive": - width = float(width) * positive_adm_scale - height = float(height) * positive_adm_scale + width = float(width) * patch_settings[os.getpid()].positive_adm_scale + height = float(height) * patch_settings[os.getpid()].positive_adm_scale def embedder(number_list): h = self.embedder(torch.tensor(number_list, dtype=torch.float32)) @@ -324,7 +325,7 @@ def patched_KSamplerX0Inpaint_forward(self, x, sigma, uncond, cond, cond_scale, def timed_adm(y, timesteps): if isinstance(y, torch.Tensor) and int(y.dim()) == 2 and int(y.shape[1]) == 5632: - y_mask = (timesteps > 999.0 * (1.0 - float(adm_scaler_end))).to(y)[..., None] + y_mask = (timesteps > 999.0 * (1.0 - float(patch_settings[os.getpid()].adm_scaler_end))).to(y)[..., None] y_with_adm = y[..., :2816].clone() y_without_adm = y[..., 2816:].clone() return y_with_adm * y_mask + y_without_adm * (1.0 - y_mask) @@ -359,19 +360,17 @@ def patched_cldm_forward(self, x, hint, timesteps, context, y=None, **kwargs): h = self.middle_block(h, emb, context) outs.append(self.middle_block_out(h, emb, context)) - if controlnet_softness > 0: + if patch_settings[os.getpid()].controlnet_softness > 0: for i in range(10): k = 1.0 - float(i) / 9.0 - outs[i] = outs[i] * (1.0 - controlnet_softness * k) + outs[i] = outs[i] * (1.0 - patch_settings[os.getpid()].controlnet_softness * k) return outs def patched_unet_forward(self, x, timesteps=None, context=None, y=None, control=None, transformer_options={}, **kwargs): - global global_diffusion_progress - self.current_step = 1.0 - timesteps.to(x) / 999.0 - global_diffusion_progress = float(self.current_step.detach().cpu().numpy().tolist()[0]) + patch_settings[os.getpid()].global_diffusion_progress = float(self.current_step.detach().cpu().numpy().tolist()[0]) y = timed_adm(y, timesteps) @@ -485,7 +484,7 @@ def patch_all(): if ldm_patched.modules.model_management.directml_enabled: ldm_patched.modules.model_management.lowvram_available = True ldm_patched.modules.model_management.OOM_EXCEPTION = Exception - + patch_all_precision() patch_all_clip() From 21f4767c65a70aeef9ac5b67eb538b22b739e537 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 21:14:54 +0100 Subject: [PATCH 37/38] fix: resolve circular import, patch_all now in async_worker --- modules/async_worker.py | 5 ++++- modules/core.py | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 790ec118d..24f5b6f7c 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -1,6 +1,9 @@ import threading import os -from modules.patch import PatchSettings, patch_settings +from modules.patch import PatchSettings, patch_settings, patch_all + +patch_all() + class AsyncTask: def __init__(self, args): diff --git a/modules/core.py b/modules/core.py index 957a91524..7a29d9883 100644 --- a/modules/core.py +++ b/modules/core.py @@ -1,8 +1,3 @@ -from modules.patch import patch_all - -patch_all() - - import os import einops import torch From 031b1f8b112121b60abd6bde2f50f92dbb26cf99 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 22 Jan 2024 21:20:17 +0100 Subject: [PATCH 38/38] chore: cleanup pid code --- modules/async_worker.py | 2 +- modules/patch.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 24f5b6f7c..3d57dbf2d 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -869,7 +869,7 @@ def callback(step, x0, x, total_steps, y): task.yields.append(['finish', task.results]) finally: if pid in modules.patch.patch_settings: - del modules.patch.patch_settings[os.getpid()] + del modules.patch.patch_settings[pid] pass diff --git a/modules/patch.py b/modules/patch.py index 100613a82..3c2dd8f47 100644 --- a/modules/patch.py +++ b/modules/patch.py @@ -210,12 +210,13 @@ def __call__(sigma, sigma_next): def compute_cfg(uncond, cond, cfg_scale, t): - mimic_cfg = float(patch_settings[os.getpid()].adaptive_cfg) + pid = os.getpid() + mimic_cfg = float(patch_settings[pid].adaptive_cfg) real_cfg = float(cfg_scale) real_eps = uncond + real_cfg * (cond - uncond) - if cfg_scale > patch_settings[os.getpid()].adaptive_cfg: + if cfg_scale > patch_settings[pid].adaptive_cfg: mimicked_eps = uncond + mimic_cfg * (cond - uncond) return real_eps * t + mimicked_eps * (1 - t) else: @@ -223,11 +224,13 @@ def compute_cfg(uncond, cond, cfg_scale, t): def patched_sampling_function(model, x, timestep, uncond, cond, cond_scale, model_options=None, seed=None): + pid = os.getpid() + if math.isclose(cond_scale, 1.0) and not model_options.get("disable_cfg1_optimization", False): final_x0 = calc_cond_uncond_batch(model, cond, None, x, timestep, model_options)[0] - if patch_settings[os.getpid()].eps_record is not None: - patch_settings[os.getpid()].eps_record = ((x - final_x0) / timestep).cpu() + if patch_settings[pid].eps_record is not None: + patch_settings[pid].eps_record = ((x - final_x0) / timestep).cpu() return final_x0 @@ -236,16 +239,16 @@ def patched_sampling_function(model, x, timestep, uncond, cond, cond_scale, mode positive_eps = x - positive_x0 negative_eps = x - negative_x0 - alpha = 0.001 * patch_settings[os.getpid()].sharpness * patch_settings[os.getpid()].global_diffusion_progress + alpha = 0.001 * patch_settings[pid].sharpness * patch_settings[pid].global_diffusion_progress positive_eps_degraded = anisotropic.adaptive_anisotropic_filter(x=positive_eps, g=positive_x0) positive_eps_degraded_weighted = positive_eps_degraded * alpha + positive_eps * (1.0 - alpha) final_eps = compute_cfg(uncond=negative_eps, cond=positive_eps_degraded_weighted, - cfg_scale=cond_scale, t=patch_settings[os.getpid()].global_diffusion_progress) + cfg_scale=cond_scale, t=patch_settings[pid].global_diffusion_progress) - if patch_settings[os.getpid()].eps_record is not None: - patch_settings[os.getpid()].eps_record = (final_eps / timestep).cpu() + if patch_settings[pid].eps_record is not None: + patch_settings[pid].eps_record = (final_eps / timestep).cpu() return x - final_eps @@ -265,13 +268,14 @@ def sdxl_encode_adm_patched(self, **kwargs): height = kwargs.get("height", 1024) target_width = width target_height = height + pid = os.getpid() if kwargs.get("prompt_type", "") == "negative": - width = float(width) * patch_settings[os.getpid()].negative_adm_scale - height = float(height) * patch_settings[os.getpid()].negative_adm_scale + width = float(width) * patch_settings[pid].negative_adm_scale + height = float(height) * patch_settings[pid].negative_adm_scale elif kwargs.get("prompt_type", "") == "positive": - width = float(width) * patch_settings[os.getpid()].positive_adm_scale - height = float(height) * patch_settings[os.getpid()].positive_adm_scale + width = float(width) * patch_settings[pid].positive_adm_scale + height = float(height) * patch_settings[pid].positive_adm_scale def embedder(number_list): h = self.embedder(torch.tensor(number_list, dtype=torch.float32)) @@ -335,6 +339,7 @@ def timed_adm(y, timesteps): def patched_cldm_forward(self, x, hint, timesteps, context, y=None, **kwargs): t_emb = ldm_patched.ldm.modules.diffusionmodules.openaimodel.timestep_embedding(timesteps, self.model_channels, repeat_only=False).to(x.dtype) emb = self.time_embed(t_emb) + pid = os.getpid() guided_hint = self.input_hint_block(hint, emb, context) @@ -360,10 +365,10 @@ def patched_cldm_forward(self, x, hint, timesteps, context, y=None, **kwargs): h = self.middle_block(h, emb, context) outs.append(self.middle_block_out(h, emb, context)) - if patch_settings[os.getpid()].controlnet_softness > 0: + if patch_settings[pid].controlnet_softness > 0: for i in range(10): k = 1.0 - float(i) / 9.0 - outs[i] = outs[i] * (1.0 - patch_settings[os.getpid()].controlnet_softness * k) + outs[i] = outs[i] * (1.0 - patch_settings[pid].controlnet_softness * k) return outs