Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

advanced params refactoring + prevent users from skipping/stopping other users tasks in queue #981

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d3f9156
only make stop_button and skip_button interactive when rendering proc…
mashb1t Nov 18, 2023
617255d
use AsyncTask for last_stop handling instead of shared
mashb1t Nov 18, 2023
83efbbd
Revert "only make stop_button and skip_button interactive when render…
mashb1t Nov 18, 2023
ebad9ea
introduce state for task skipping/stopping
mashb1t Nov 18, 2023
8060e50
fix return parameters of stop_clicked
mashb1t Nov 18, 2023
4a576bf
code cleanup, do not disable skip/stop on stop_clicked
mashb1t Nov 18, 2023
d2cc9a4
reset last_stop when skipping for further processing
mashb1t Nov 19, 2023
8acb2d7
Merge branch 'main_upstream' into hotfix/prevent-skipping-and-stoppin…
mashb1t Nov 20, 2023
d2e2540
Merge branch 'lllyasviel:main' into hotfix/prevent-skipping-and-stopp…
mashb1t Nov 21, 2023
5496ec4
Merge remote-tracking branch 'upstream/main' into hotfix/prevent-skip…
mashb1t Dec 14, 2023
0ab7dd0
Merge branch 'main_upstream' into hotfix/prevent-skipping-and-stoppin…
mashb1t Dec 27, 2023
ee3d70a
fix: replace fcbh with ldm_patched
mashb1t Jan 4, 2024
e68c8aa
Merge branch 'main_upstream' into hotfix/prevent-skipping-and-stoppin…
mashb1t Jan 4, 2024
04ba160
fix: use currentTask instead of ctrls after merging upstream
mashb1t Jan 4, 2024
79a6349
feat: extract attribute disable_preview
mashb1t Jan 22, 2024
3607059
feat: extract attribute adm_scaler_positive
mashb1t Jan 22, 2024
64dcdbb
feat: extract attribute adm_scaler_negative
mashb1t Jan 22, 2024
618b017
feat: extract attribute adm_scaler_end
mashb1t Jan 22, 2024
fc3da75
feat: extract attribute adaptive_cfg
mashb1t Jan 22, 2024
e54bad8
feat: extract attribute sampler_name
mashb1t Jan 22, 2024
d72573a
feat: extract attribute scheduler_name
mashb1t Jan 22, 2024
217be19
feat: extract attribute generate_image_grid
mashb1t Jan 22, 2024
df35033
feat: extract attribute overwrite_step
mashb1t Jan 22, 2024
2b1f501
feat: extract attribute overwrite_switch
mashb1t Jan 22, 2024
2eed5a2
feat: extract attribute overwrite_width
mashb1t Jan 22, 2024
9f4a00e
feat: extract attribute overwrite_height
mashb1t Jan 22, 2024
22af976
feat: extract attribute overwrite_vary_strength
mashb1t Jan 22, 2024
2ab5593
feat: extract attribute overwrite_upscale_strength
mashb1t Jan 22, 2024
cce9871
feat: extract attribute mixing_image_prompt_and_vary_upscale
mashb1t Jan 22, 2024
6289e5d
feat: extract attribute mixing_image_prompt_and_inpaint
mashb1t Jan 22, 2024
0bf4159
feat: extract attribute debugging_cn_preprocessor
mashb1t Jan 22, 2024
9f194a9
feat: extract attribute skipping_cn_preprocessor
mashb1t Jan 22, 2024
ec48644
feat: extract attribute canny_low_threshold
mashb1t Jan 22, 2024
2d8ca41
feat: extract attribute canny_high_threshold
mashb1t Jan 22, 2024
cfb70c0
feat: extract attribute refiner_swap_method
mashb1t Jan 22, 2024
eb1d393
feat: extract freeu_ctrls attributes
mashb1t Jan 22, 2024
4ce27ae
feat: extract inpaint_ctrls attributes
mashb1t Jan 22, 2024
18446dc
wip: add TODOs
mashb1t Jan 22, 2024
78d2ec8
chore: cleanup code
mashb1t Jan 22, 2024
f3222b0
feat: extract attribute controlnet_softness
mashb1t Jan 22, 2024
177075f
feat: extract remaining attributes, do not use globals in patch
mashb1t Jan 22, 2024
21f4767
fix: resolve circular import, patch_all now in async_worker
mashb1t Jan 22, 2024
031b1f8
chore: cleanup pid code
mashb1t Jan 22, 2024
148eddf
Merge branch 'feature/extract-advanced-parameters' into hotfix/preven…
mashb1t Jan 22, 2024
7ebd2cc
Merge branch 'main_upstream' into hotfix/prevent-skipping-and-stoppin…
mashb1t Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def __init__(self, args):
self.args = args
self.yields = []
self.results = []
self.last_stop = False
self.processing = False


async_tasks = []
Expand Down Expand Up @@ -115,6 +117,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()
Expand Down Expand Up @@ -722,6 +725,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()
mashb1t marked this conversation as resolved.
Show resolved Hide resolved
positive_cond, negative_cond = task['c'], task['uc']

if 'cn' in goals:
Expand Down Expand Up @@ -786,16 +791,17 @@ def callback(step, x0, x, total_steps, y):

yield_result(async_task, imgs, do_not_show_finished_images=len(tasks) == 1)
except ldm_patched.modules.model_management.InterruptProcessingException as e:
if shared.last_stop == 'skip':
if async_task.last_stop == 'skip':
print('User skipped')
async_task.last_stop = False
continue
else:
print('User stopped')
break

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:
Expand Down
3 changes: 1 addition & 2 deletions shared.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gradio_root = None
last_stop = None
gradio_root = None
39 changes: 22 additions & 17 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
from modules.ui_gradio_extensions import reload_javascript
from modules.auth import auth_enabled, check_auth

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):
import ldm_patched.modules.model_management as model_management

with model_management.interrupt_processing_mutex:
model_management.interrupt_processing = False

# outputs=[progress_html, progress_window, progress_gallery, gallery]

execution_start_time = time.perf_counter()
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 ...')), \
Expand Down Expand Up @@ -88,6 +90,7 @@ def generate_clicked(*args):
css=modules.html.css).queue()

with shared.gradio_root:
currentTask = gr.State(worker.AsyncTask(args=[]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi this can also be empty, just to prevent future checks for e.g. processing or last_stop

with gr.Row():
with gr.Column(scale=2):
with gr.Row():
Expand Down Expand Up @@ -115,21 +118,22 @@ 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 ldm_patched.modules.model_management as model_management
shared.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 currentTask

def skip_clicked():
def skip_clicked(currentTask):
import ldm_patched.modules.model_management as model_management
shared.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],
queue=False, show_progress=False, _js='cancelGenerateForever')
skip_button.click(skip_clicked, 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')
Expand Down Expand Up @@ -503,7 +507,7 @@ def inpaint_mode_change(mode):
], show_progress=False, queue=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
]

Expand Down Expand Up @@ -560,7 +564,8 @@ def parse_meta(raw_prompt_txt):
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')

Expand Down