mirror of
https://github.com/facefusion/facefusion.git
synced 2026-10-01 03:29:38 +02:00
prevent countless importlib.import_module calls
This commit is contained in:
1 parent
c2cb048ac7
commit
25df9aee48
1 file changed
+5
-3
@@ -1,5 +1,6 @@
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
|
from functools import lru_cache
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ def get_inference_pool(module_name : str, model_names : List[str], model_source_
|
|||||||
while process_manager.is_checking():
|
while process_manager.is_checking():
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
execution_device_ids = state_manager.get_item('execution_device_ids')
|
execution_device_ids = state_manager.get_item('execution_device_ids')
|
||||||
execution_providers = resolve_execution_providers(module_name)
|
execution_providers = resolve_static_execution_providers(module_name)
|
||||||
app_context = detect_app_context()
|
app_context = detect_app_context()
|
||||||
|
|
||||||
for execution_device_id in execution_device_ids:
|
for execution_device_id in execution_device_ids:
|
||||||
@@ -55,7 +56,7 @@ def create_inference_pool(model_source_set : DownloadSet, execution_device_id :
|
|||||||
|
|
||||||
def clear_inference_pool(module_name : str, model_names : List[str]) -> None:
|
def clear_inference_pool(module_name : str, model_names : List[str]) -> None:
|
||||||
execution_device_ids = state_manager.get_item('execution_device_ids')
|
execution_device_ids = state_manager.get_item('execution_device_ids')
|
||||||
execution_providers = resolve_execution_providers(module_name)
|
execution_providers = resolve_static_execution_providers(module_name)
|
||||||
app_context = detect_app_context()
|
app_context = detect_app_context()
|
||||||
|
|
||||||
if is_windows() and has_execution_provider('directml'):
|
if is_windows() and has_execution_provider('directml'):
|
||||||
@@ -87,7 +88,8 @@ def get_inference_context(module_name : str, model_names : List[str], execution_
|
|||||||
return inference_context
|
return inference_context
|
||||||
|
|
||||||
|
|
||||||
def resolve_execution_providers(module_name : str) -> List[ExecutionProvider]:
|
@lru_cache()
|
||||||
|
def resolve_static_execution_providers(module_name : str) -> List[ExecutionProvider]:
|
||||||
module = importlib.import_module(module_name)
|
module = importlib.import_module(module_name)
|
||||||
|
|
||||||
if hasattr(module, 'resolve_execution_providers'):
|
if hasattr(module, 'resolve_execution_providers'):
|
||||||
|
|||||||
Reference in new issue
Block a user