fix: address PR review feedback — SystemExit, AUTO device, thread timing

- Catch SystemExit from add_openvino_libs_to_path() so a missing
  OpenVINO installation never causes a hard exit on Windows
- Replace hard-coded GPU+FP16 with AUTO:GPU,NPU,CPU device priority,
  letting OpenVINO pick the best available accelerator
- Extract shared OPENVINO_PROVIDER_CONFIG constant to avoid
  duplication between _onnx_enhancer and face_swapper
- Defer thread-suggestion evaluation until after execution_providers
  is assigned, fixing a latent timing bug that affected OpenVINO,
  CUDA, and DML thread hints
This commit is contained in:
dunegym
2026-07-11 12:45:00 +08:00
parent 897dc21da4
commit 7d2d7fb1f3
4 changed files with 19 additions and 13 deletions
+7 -1
View File
@@ -58,7 +58,7 @@ def parse_args() -> None:
program.add_argument('--live-resizable', help='The live camera frame is resizable', dest='live_resizable', action='store_true', default=False)
program.add_argument('--max-memory', help='maximum amount of RAM in GB', dest='max_memory', type=int, default=suggest_max_memory())
program.add_argument('--execution-provider', help='execution provider', dest='execution_provider', default=[suggest_default_execution_provider()], choices=suggest_execution_providers(), nargs='+')
program.add_argument('--execution-threads', help='number of execution threads', dest='execution_threads', type=int, default=suggest_execution_threads())
program.add_argument('--execution-threads', help='number of execution threads', dest='execution_threads', type=int, default=None)
program.add_argument('-v', '--version', action='version', version=f'{modules.metadata.name} {modules.metadata.version}')
# register deprecated args
@@ -90,6 +90,12 @@ def parse_args() -> None:
modules.globals.execution_threads = args.execution_threads
modules.globals.lang = args.lang
# The argparse default (None) avoids evaluating suggest_execution_threads()
# before providers are decoded, and deprecated-arg overrides above may
# have already set execution_threads.
if modules.globals.execution_threads is None:
modules.globals.execution_threads = suggest_execution_threads()
#for ENHANCER tumblers:
for enhancer_key in ('face_enhancer', 'face_enhancer_gpen256', 'face_enhancer_gpen512'):
modules.globals.fp_ui[enhancer_key] = enhancer_key in args.frame_processor
+7 -7
View File
@@ -20,6 +20,11 @@ IS_APPLE_SILICON = platform.system() == "Darwin" and platform.machine() == "arm6
# Limit concurrent ONNX calls to avoid VRAM exhaustion on multi-face frames
THREAD_SEMAPHORE = threading.Semaphore(min(max(1, (os.cpu_count() or 1)), 8))
# OpenVINO provider configuration.
# AUTO:GPU,NPU,CPU lets OpenVINO try the best available device in priority
# order (Intel GPU → NPU → CPU).
OPENVINO_PROVIDER_CONFIG = ("OpenVINOExecutionProvider", {"device_type": "AUTO:GPU,NPU,CPU"})
def build_provider_config(providers=None):
"""Wrap raw provider name strings with optimised CUDA / CoreML options.
@@ -51,13 +56,8 @@ def build_provider_config(providers=None):
},
))
elif p == "OpenVINOExecutionProvider":
# Prefer Intel GPU with FP16 precision when available.
# NB: GPU_FP16 is deprecated since OpenVINO 2025.4 — use
# device_type="GPU" + precision="FP16" instead.
config.append((
"OpenVINOExecutionProvider",
{"device_type": "GPU", "precision": "FP16"},
))
# AUTO lets OpenVINO select the best device
config.append(OPENVINO_PROVIDER_CONFIG)
else:
config.append(p)
return config
+4 -4
View File
@@ -271,10 +271,10 @@ def get_face_swapper() -> Any:
# fastest on modern GPUs (Blackwell/sm_120).
providers_config.append(p)
elif p == "OpenVINOExecutionProvider":
providers_config.append((
"OpenVINOExecutionProvider",
{"device_type": "GPU", "precision": "FP16"},
))
from modules.processors.frame._onnx_enhancer import (
OPENVINO_PROVIDER_CONFIG,
)
providers_config.append(OPENVINO_PROVIDER_CONFIG)
else:
providers_config.append(p)
FACE_SWAPPER = insightface.model_zoo.get_model(
+1 -1
View File
@@ -39,7 +39,7 @@ if sys.platform == "win32":
add_openvino_libs_to_path,
)
add_openvino_libs_to_path()
except (ImportError, FileNotFoundError):
except (ImportError, FileNotFoundError, SystemExit):
pass # OpenVINO not installed — no-op
# On Linux, pre-load NVIDIA shared libraries (cuDNN, cuBLAS, nvrtc...) shipped