Update GPU check logic

This commit is contained in:
Deniz Şafak
2025-05-20 04:11:17 +03:00
parent 814c171a90
commit 578da66f34
3 changed files with 23 additions and 25 deletions
+12
View File
@@ -0,0 +1,12 @@
import gpustat
def check():
stats = gpustat.new_query()
for gpu in stats.gpus:
print(gpu.name)
if 'nvidia' in gpu.name.lower():
return True
return False
if __name__ == "__main__":
print(check())
-22
View File
@@ -212,28 +212,6 @@ def calculate_text_length(text):
return char_count
def is_nvidia():
try:
from torch import cuda # Attempt to import cuda from torch
# Check if there are any CUDA-capable devices
device_count = cuda.device_count()
if device_count == 0:
return False
# Iterate through available devices to find an NVIDIA GPU
for i in range(device_count):
device_name = cuda.get_device_name(i).lower()
print(f"Device {i}: {device_name}") # Debugging output
if 'nvidia' in device_name:
return True
# If loop completes, CUDA devices are present, but none are identified as NVIDIA
return False
except Exception:
# Catch any other exceptions (e.g., CUDA driver issues, unexpected errors)
return False
def get_gpu_acceleration(enabled):
from torch.cuda import is_available