Bring back CPU unloading of models when idle for a while (applies only when GPUs are present)

This commit is contained in:
cmdr2 2022-11-08 19:23:35 +05:30
parent 51fb1a43de
commit 8f1d214b12

View File

@ -273,11 +273,12 @@ def thread_render(device):
return
task = thread_get_next_task()
if task is None:
# if runtime.thread_data.device == 'cpu' and is_alive() > 1 and hasattr(runtime.thread_data, 'lastActive') and time.time() - runtime.thread_data.lastActive > CPU_UNLOAD_TIMEOUT:
# # GPUs present and CPU is idle. Unload resources.
# runtime.unload_models()
# runtime.unload_filters()
# del runtime.thread_data.lastActive
if runtime.thread_data.device == 'cpu' and is_alive() > 1 and hasattr(runtime.thread_data, 'lastActive') and time.time() - runtime.thread_data.lastActive > CPU_UNLOAD_TIMEOUT:
# GPUs present and CPU is idle. Unload resources.
runtime.unload_models()
runtime.unload_filters()
del runtime.thread_data.lastActive
print('unloaded models from CPU because it was idle for too long')
time.sleep(1)
continue
if task.error is not None: