mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Update GPU detection logic
This commit is contained in:
+5
-7
@@ -263,15 +263,13 @@ if "%MISAKI_LANG%" NEQ "en" (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
:: Check GPU vendor
|
:: Check for NVIDIA GPU via is_nvidia()
|
||||||
echo Checking GPU vendor...
|
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from abogen.utils import is_nvidia; print(is_nvidia())"') do set IS_NVIDIA=%%i
|
||||||
set GPU_VENDOR=unknown
|
echo NVIDIA GPU detected: %IS_NVIDIA%
|
||||||
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from abogen.utils import get_gpu_vendor; print(get_gpu_vendor())"') do set GPU_VENDOR=%%i
|
|
||||||
echo GPU Vendor: %GPU_VENDOR%
|
|
||||||
|
|
||||||
:: Check if torch is installed with CUDA support
|
:: Check if torch is installed with CUDA support
|
||||||
echo Checking CUDA availability...
|
echo Checking CUDA availability...
|
||||||
if /I "%GPU_VENDOR%"=="nvidia" (
|
if /I "%IS_NVIDIA%"=="true" (
|
||||||
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from torch.cuda import is_available; print(is_available())"') do set cuda_available=%%i
|
for /f %%i in ('%PYTHON_CONSOLE_PATH% -c "from torch.cuda import is_available; print(is_available())"') do set cuda_available=%%i
|
||||||
|
|
||||||
if "%cuda_available%"=="False" (
|
if "%cuda_available%"=="False" (
|
||||||
@@ -287,7 +285,7 @@ if /I "%GPU_VENDOR%"=="nvidia" (
|
|||||||
echo CUDA is available on NVIDIA GPU.
|
echo CUDA is available on NVIDIA GPU.
|
||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
echo Non-NVIDIA GPU detected (%GPU_VENDOR%). Skipping PyTorch CUDA installation.
|
echo GPU is not NVIDIA. Skipping PyTorch CUDA installation.
|
||||||
)
|
)
|
||||||
|
|
||||||
:: Ask user if they want to create a desktop shortcut
|
:: Ask user if they want to create a desktop shortcut
|
||||||
|
|||||||
+19
-24
@@ -212,31 +212,26 @@ def calculate_text_length(text):
|
|||||||
return char_count
|
return char_count
|
||||||
|
|
||||||
|
|
||||||
def get_gpu_vendor():
|
def is_nvidia():
|
||||||
os_name = platform.system()
|
|
||||||
cmd = None
|
|
||||||
if os_name == "Windows":
|
|
||||||
cmd = "wmic path win32_VideoController get name"
|
|
||||||
elif os_name == "Linux":
|
|
||||||
cmd = "lspci | grep -i 'vga\\|3d\\|display'"
|
|
||||||
|
|
||||||
if cmd:
|
|
||||||
try:
|
try:
|
||||||
# Call create_process with capture_output=True
|
from torch import cuda # Attempt to import cuda from torch
|
||||||
proc = create_process(cmd, text=True, capture_output=True)
|
# Check if there are any CUDA-capable devices
|
||||||
output, _ = proc.communicate(timeout=5) # Add a timeout
|
device_count = cuda.device_count()
|
||||||
if proc.returncode == 0 and output:
|
if device_count == 0:
|
||||||
output_lower = output.lower()
|
return False
|
||||||
if "nvidia" in output_lower:
|
|
||||||
print("GPU Vendor: NVIDIA")
|
# Iterate through available devices to find an NVIDIA GPU
|
||||||
return "nvidia"
|
for i in range(device_count):
|
||||||
elif "amd" in output_lower or "radeon" in output_lower:
|
device_name = cuda.get_device_name(i).lower()
|
||||||
print("GPU Vendor: AMD")
|
print(f"Device {i}: {device_name}") # Debugging output
|
||||||
return "amd"
|
if 'nvidia' in device_name:
|
||||||
except (subprocess.TimeoutExpired, FileNotFoundError, Exception): # Catch more specific exceptions
|
return True
|
||||||
# Log error or handle as appropriate
|
|
||||||
return "unknown" # Fallback in case of any error
|
# If loop completes, CUDA devices are present, but none are identified as NVIDIA
|
||||||
return "unknown"
|
return False
|
||||||
|
except Exception:
|
||||||
|
# Catch any other exceptions (e.g., CUDA driver issues, unexpected errors)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_gpu_acceleration(enabled):
|
def get_gpu_acceleration(enabled):
|
||||||
|
|||||||
Reference in New Issue
Block a user