Remove xml parsing for gpu metrics (#1030)

* remove xml parsing

* remove aitop
This commit is contained in:
Harisreedhar
2026-05-11 16:35:10 +02:00
committed by henryruhs
parent 0c18508f70
commit abeef470cc
2 changed files with 72 additions and 51 deletions
+71 -50
View File
@@ -1,10 +1,10 @@
import os import os
import shutil import shutil
import subprocess import subprocess
import xml.etree.ElementTree as ElementTree
from functools import lru_cache from functools import lru_cache
from typing import List, Optional from typing import List, Optional
import pynvml
import onnxruntime import onnxruntime
import facefusion.choices import facefusion.choices
@@ -129,9 +129,8 @@ def resolve_openvino_device_type(execution_device_id : int) -> str:
return 'GPU.' + str(execution_device_id) return 'GPU.' + str(execution_device_id)
def run_nvidia_smi() -> subprocess.Popen[bytes]: def resolve_cuda_driver_version(cuda_driver_version : int) -> str:
commands = [ shutil.which('nvidia-smi'), '--query', '--xml-format' ] return '{}.{}'.format(cuda_driver_version // 1000, (cuda_driver_version % 1000) // 10)
return subprocess.Popen(commands, stdout = subprocess.PIPE)
@lru_cache() @lru_cache()
@@ -143,52 +142,74 @@ def detect_execution_devices() -> List[ExecutionDevice]:
execution_devices : List[ExecutionDevice] = [] execution_devices : List[ExecutionDevice] = []
try: try:
output, _ = run_nvidia_smi().communicate() pynvml.nvmlInit()
root_element = ElementTree.fromstring(output) device_count = pynvml.nvmlDeviceGetCount()
except Exception:
root_element = ElementTree.Element('xml')
for gpu_element in root_element.findall('gpu'): for device_id in range(device_count):
execution_devices.append( handle = pynvml.nvmlDeviceGetHandleByIndex(device_id)
{ product_name = pynvml.nvmlDeviceGetName(handle)
'driver_version': root_element.findtext('driver_version'), driver_version = pynvml.nvmlSystemGetDriverVersion()
'framework': cuda_driver_version = resolve_cuda_driver_version(pynvml.nvmlSystemGetCudaDriverVersion())
memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)
temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU)
memory_total_mib = memory_info.total // (1024 * 1024)
memory_free_mib = memory_info.free // (1024 * 1024)
memory_used_mib = memory_info.used // (1024 * 1024)
memory_percent = memory_used_mib / memory_total_mib * 100
execution_devices.append(
{ {
'name': 'CUDA', 'driver_version': driver_version,
'version': root_element.findtext('cuda_version') 'framework':
}, {
'product': 'name': 'CUDA',
{ 'version': cuda_driver_version
'vendor': 'NVIDIA', },
'name': gpu_element.findtext('product_name').replace('NVIDIA', '').strip() 'product':
}, {
'video_memory': 'vendor': 'NVIDIA',
{ 'name': product_name.replace('NVIDIA', '').strip()
'total': create_value_and_unit(gpu_element.findtext('fb_memory_usage/total')), },
'free': create_value_and_unit(gpu_element.findtext('fb_memory_usage/free')) 'video_memory':
}, {
'temperature': 'total':
{ {
'gpu': create_value_and_unit(gpu_element.findtext('temperature/gpu_temp')), 'value': int(memory_total_mib),
'memory': create_value_and_unit(gpu_element.findtext('temperature/memory_temp')) 'unit': 'MiB'
}, },
'utilization': 'free':
{ {
'gpu': create_value_and_unit(gpu_element.findtext('utilization/gpu_util')), 'value': int(memory_free_mib),
'memory': create_value_and_unit(gpu_element.findtext('utilization/memory_util')) 'unit': 'MiB'
} }
}) },
'temperature':
{
'gpu':
{
'value': int(temperature),
'unit': 'C'
},
'memory': None
},
'utilization':
{
'gpu':
{
'value': int(utilization.gpu),
'unit': '%'
},
'memory':
{
'value': int(memory_percent),
'unit': '%'
}
}
})
pynvml.nvmlShutdown()
except Exception:
pass
return execution_devices return execution_devices
def create_value_and_unit(text : str) -> Optional[ValueAndUnit]:
if ' ' in text:
value, unit = text.split()
return\
{
'value': int(value),
'unit': str(unit)
}
return None
+1 -1
View File
@@ -1,4 +1,4 @@
numpy==2.2.1 numpy==2.2.6
onnx==1.21.0 onnx==1.21.0
onnxruntime==1.24.4 onnxruntime==1.24.4
opencv-python==4.13.0.92 opencv-python==4.13.0.92