import html import sys import threading import traceback import time from modules import shared, progress queue_lock = threading.Lock() def wrap_queued_call(func): def f(*args, **kwargs): with queue_lock: res = func(*args, **kwargs) return res return f def wrap_gradio_gpu_call(func, extra_outputs=None): def f(*args, **kwargs): # if the first argument is a string that says "task(...)", it is treated as a job id if len(args) > 0 and type(args[0]) == str and args[0][0:5] == "task(" and args[0][-1] == ")": id_task = args[0] progress.add_task_to_queue(id_task) else: id_task = None with queue_lock: shared.state.begin() progress.start_task(id_task) try: res = func(*args, **kwargs) progress.record_results(id_task, res) finally: progress.finish_task(id_task) shared.state.end() return res return wrap_gradio_call(f, extra_outputs=extra_outputs, add_stats=True) def wrap_gradio_call(func, extra_outputs=None, add_stats=False): def f(*args, extra_outputs_array=extra_outputs, **kwargs): run_memmon = shared.opts.memmon_poll_rate > 0 and not shared.mem_mon.disabled and add_stats if run_memmon: shared.mem_mon.monitor() t = time.perf_counter() try: res = list(func(*args, **kwargs)) except Exception as e: # When printing out our debug argument list, do not print out more than a MB of text max_debug_str_len = 131072 # (1024*1024)/8 print("Error completing request", file=sys.stderr) argStr = f"Arguments: {args} {kwargs}" print(argStr[:max_debug_str_len], file=sys.stderr) if len(argStr) > max_debug_str_len: print(f"(Argument list truncated at {max_debug_str_len}/{len(argStr)} characters)", file=sys.stderr) print(traceback.format_exc(), file=sys.stderr) shared.state.job = "" shared.state.job_count = 0 if extra_outputs_array is None: extra_outputs_array = [None, ''] error_message = f'{type(e).__name__}: {e}' res = extra_outputs_array + [f"
Torch active/reserved: {active_peak}/{reserved_peak} MiB,
Time taken: