From f2f09fc215aead461d06f8673be539c2e92b3c18 Mon Sep 17 00:00:00 2001 From: harisreedhar Date: Wed, 11 Feb 2026 16:26:22 +0530 Subject: [PATCH] move detect_execution_devices to system.py --- facefusion/execution.py | 76 -------------------------------------- facefusion/system.py | 81 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 78 deletions(-) diff --git a/facefusion/execution.py b/facefusion/execution.py index 7d210549..15f89b39 100644 --- a/facefusion/execution.py +++ b/facefusion/execution.py @@ -127,79 +127,3 @@ def resolve_openvino_device_type(execution_device_id : int) -> str: if execution_device_id == 0: return 'GPU' return 'GPU.' + str(execution_device_id) - - -@lru_cache() -def detect_static_execution_devices() -> List[ExecutionDevice]: - return detect_execution_devices() - - -def detect_execution_devices() -> List[ExecutionDevice]: - execution_devices : List[ExecutionDevice] = [] - - try: - pynvml.nvmlInit() - device_count = pynvml.nvmlDeviceGetCount() - - for device_id in range(device_count): - handle = pynvml.nvmlDeviceGetHandleByIndex(device_id) - - execution_devices.append( - { - 'driver_version': pynvml.nvmlSystemGetDriverVersion(), - 'framework': - { - 'name': 'CUDA', - 'version': pynvml.nvmlSystemGetCudaDriverVersion() - }, - 'product': - { - 'vendor': 'NVIDIA', - 'name': pynvml.nvmlDeviceGetName(handle) - }, - 'video_memory': - { - 'total': - { - 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).total // (1024 * 1024 * 1024), - 'unit': 'GB' - }, - 'free': - { - 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).free // (1024 * 1024 * 1024), - 'unit': 'GB' - } - }, - 'temperature': - { - 'gpu': - { - 'value': pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU), - 'unit': 'C' - }, - 'memory': - { - 'value': 0, - 'unit': '%' - } - }, - 'utilization': - { - 'gpu': - { - 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).gpu, - 'unit': '%' - }, - 'memory': - { - 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).memory, - 'unit': '%' - } - } - }) - - pynvml.nvmlShutdown() - except Exception: - pass - - return execution_devices diff --git a/facefusion/system.py b/facefusion/system.py index d85b3854..8bbdcd90 100644 --- a/facefusion/system.py +++ b/facefusion/system.py @@ -1,12 +1,13 @@ import shutil +from functools import lru_cache from pathlib import Path from typing import List import psutil +import pynvml from facefusion import state_manager -from facefusion.execution import detect_execution_devices -from facefusion.types import DiskMetrics, MemoryMetrics, Metrics, NetworkMetrics, ProcessorMetrics +from facefusion.types import DiskMetrics, ExecutionDevice, MemoryMetrics, Metrics, NetworkMetrics, ProcessorMetrics def get_metrics_set() -> Metrics: @@ -22,6 +23,82 @@ def get_metrics_set() -> Metrics: } +@lru_cache() +def detect_static_execution_devices() -> List[ExecutionDevice]: + return detect_execution_devices() + + +def detect_execution_devices() -> List[ExecutionDevice]: + execution_devices : List[ExecutionDevice] = [] + + try: + pynvml.nvmlInit() + device_count = pynvml.nvmlDeviceGetCount() + + for device_id in range(device_count): + handle = pynvml.nvmlDeviceGetHandleByIndex(device_id) + + execution_devices.append( + { + 'driver_version': pynvml.nvmlSystemGetDriverVersion(), + 'framework': + { + 'name': 'CUDA', + 'version': pynvml.nvmlSystemGetCudaDriverVersion() + }, + 'product': + { + 'vendor': 'NVIDIA', + 'name': pynvml.nvmlDeviceGetName(handle) + }, + 'video_memory': + { + 'total': + { + 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).total // (1024 * 1024 * 1024), + 'unit': 'GB' + }, + 'free': + { + 'value': pynvml.nvmlDeviceGetMemoryInfo(handle).free // (1024 * 1024 * 1024), + 'unit': 'GB' + } + }, + 'temperature': + { + 'gpu': + { + 'value': pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU), + 'unit': 'C' + }, + 'memory': + { + 'value': 0, + 'unit': '%' + } + }, + 'utilization': + { + 'gpu': + { + 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).gpu, + 'unit': '%' + }, + 'memory': + { + 'value': pynvml.nvmlDeviceGetUtilizationRates(handle).memory, + 'unit': '%' + } + } + }) + + pynvml.nvmlShutdown() + except Exception: + pass + + return execution_devices + + def detect_disk_metrics(drive_paths : List[str]) -> List[DiskMetrics]: disk_metrics : List[DiskMetrics] = []