From a10487986925ca8fd07ee7ae7fc5034752298551 Mon Sep 17 00:00:00 2001 From: Kohaku-Blueleaf <59680068+KohakuBlueleaf@users.noreply.github.com> Date: Mon, 22 May 2023 21:52:46 +0800 Subject: Add custom karras scheduler --- modules/ui.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 001b9792..a65f8d85 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -484,6 +484,7 @@ def create_ui(): with FormRow(elem_classes="checkboxes-row", variant="compact"): restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="txt2img_restore_faces") tiling = gr.Checkbox(label='Tiling', value=False, elem_id="txt2img_tiling") + t2i_enable_k_sched = gr.Checkbox(label='Custom Karras Scheduler', value=False, elem_id="txt2img_enable_k_sched") enable_hr = gr.Checkbox(label='Hires. fix', value=False, elem_id="txt2img_enable_hr") hr_final_resolution = FormHTML(value="", elem_id="txtimg_hr_finalres", label="Upscaled resolution", interactive=False) @@ -510,6 +511,13 @@ def create_ui(): with gr.Row(): hr_negative_prompt = gr.Textbox(label="Negative prompt", elem_id="hires_neg_prompt", show_label=False, lines=3, placeholder="Negative prompt for hires fix pass.\nLeave empty to use the same negative prompt as in first pass.", elem_classes=["prompt"]) + elif category == "karras_scheduler": + with FormGroup(visible=False, elem_id="txt2img_karras_scheduler") as t2i_k_sched_options: + with FormRow(elem_id="txt2img_karras_scheduler_row1", variant="compact"): + t2i_k_sched_sigma_max = gr.Slider(minimum=0.0, maximum=0.5, step=0.05, label='sigma min', value=0.1, elem_id="txt2img_sigma_min") + t2i_k_sched_sigma_min = gr.Slider(minimum=5.0, maximum=50.0, step=0.1, label='sigma max', value=10.0, elem_id="txt2img_sigma_max") + t2i_k_sched_rho = gr.Slider(minimum=3.0, maximum=10.0, step=0.5, label='rho', value=7.0, elem_id="txt2img_rho") + elif category == "batch": if not opts.dimensions_and_batch_together: with FormRow(elem_id="txt2img_column_batch"): @@ -578,6 +586,10 @@ def create_ui(): hr_prompt, hr_negative_prompt, override_settings, + t2i_enable_k_sched, + t2i_k_sched_sigma_max, + t2i_k_sched_sigma_min, + t2i_k_sched_rho ] + custom_inputs, @@ -627,6 +639,13 @@ def create_ui(): show_progress = False, ) + t2i_enable_k_sched.change( + fn=lambda x: gr_show(x), + inputs=[t2i_enable_k_sched], + outputs=[t2i_k_sched_options], + show_progress=False + ) + txt2img_paste_fields = [ (txt2img_prompt, "Prompt"), (txt2img_negative_prompt, "Negative prompt"), @@ -655,6 +674,10 @@ def create_ui(): (hr_prompt, "Hires prompt"), (hr_negative_prompt, "Hires negative prompt"), (hr_prompts_container, lambda d: gr.update(visible=True) if d.get("Hires prompt", "") != "" or d.get("Hires negative prompt", "") != "" else gr.update()), + (t2i_enable_k_sched, "Enable CustomKarras Schedule"), + (t2i_k_sched_sigma_max, "Karras Scheduler sigma_max"), + (t2i_k_sched_sigma_min, "Karras Scheduler sigma_min"), + (t2i_k_sched_rho, "Karras Scheduler rho"), *modules.scripts.scripts_txt2img.infotext_fields ] parameters_copypaste.add_paste_fields("txt2img", None, txt2img_paste_fields, override_settings) @@ -846,6 +869,14 @@ def create_ui(): with FormRow(elem_classes="checkboxes-row", variant="compact"): restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="img2img_restore_faces") tiling = gr.Checkbox(label='Tiling', value=False, elem_id="img2img_tiling") + i2i_enable_k_sched = gr.Checkbox(label='Custom Karras Scheduler', value=False, elem_id="txt2img_enable_k_sched") + + elif category == "karras_scheduler": + with FormGroup(visible=False, elem_id="img2img_karras_scheduler") as i2i_k_sched_options: + with FormRow(elem_id="img2img_karras_scheduler_row1", variant="compact"): + i2i_k_sched_sigma_max = gr.Slider(minimum=0.0, maximum=0.5, step=0.05, label='sigma min', value=0.1, elem_id="txt2img_sigma_min") + i2i_k_sched_sigma_min = gr.Slider(minimum=5.0, maximum=50.0, step=0.1, label='sigma max', value=10.0, elem_id="txt2img_sigma_max") + i2i_k_sched_rho = gr.Slider(minimum=3.0, maximum=10.0, step=0.5, label='rho', value=7.0, elem_id="txt2img_rho") elif category == "batch": if not opts.dimensions_and_batch_together: @@ -949,6 +980,10 @@ def create_ui(): img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, override_settings, + i2i_enable_k_sched, + i2i_k_sched_sigma_max, + i2i_k_sched_sigma_min, + i2i_k_sched_rho ] + custom_inputs, outputs=[ img2img_gallery, @@ -1032,6 +1067,13 @@ def create_ui(): outputs=[prompt, negative_prompt, styles], ) + i2i_enable_k_sched.change( + fn=lambda x: gr_show(x), + inputs=[i2i_enable_k_sched], + outputs=[i2i_k_sched_options], + show_progress=False + ) + token_button.click(fn=update_token_counter, inputs=[img2img_prompt, steps], outputs=[token_counter]) negative_token_button.click(fn=wrap_queued_call(update_token_counter), inputs=[img2img_negative_prompt, steps], outputs=[negative_token_counter]) @@ -1043,6 +1085,10 @@ def create_ui(): (steps, "Steps"), (sampler_index, "Sampler"), (restore_faces, "Face restoration"), + (i2i_enable_k_sched, "Enable Karras Schedule"), + (i2i_k_sched_sigma_max, "Karras Scheduler sigma_max"), + (i2i_k_sched_sigma_min, "Karras Scheduler sigma_min"), + (i2i_k_sched_rho, "Karras Scheduler rho"), (cfg_scale, "CFG scale"), (image_cfg_scale, "Image CFG scale"), (seed, "Seed"), -- cgit v1.2.3