From fe22fe83b0915b208e1ec67152e2604f04f52d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20=C5=9Eafak?= Date: Sun, 16 Nov 2025 01:30:32 +0300 Subject: [PATCH] Possible fix for "CUDA is not available" issue, improvements in code and readme --- README.md | 17 ++++++++++++----- WINDOWS_INSTALL.bat | 8 ++++++-- abogen/main.py | 24 +++++++++--------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 191feeb..66e9446 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ python -m venv venv venv\Scripts\activate # For NVIDIA GPUs: -pip install torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cu128 +# We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628 +pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 # For AMD GPUs: # Not supported yet, because ROCm is not available on Windows. Use Linux if you have AMD GPU. @@ -345,14 +346,20 @@ This will start Abogen in command-line mode and display detailed error messages. How to fix "CUDA GPU is not available. Using CPU" warning? -> This message means PyTorch couldn't use your GPU. On Windows, Abogen supports NVIDIA GPUs with CUDA. AMD GPUs are supported only on Linux. Abogen will still run on the CPU, but it will be slower. +> This message means PyTorch could not use your GPU and has fallen back to the CPU. On Windows, Abogen only supports NVIDIA GPUs with CUDA. AMD GPUs are not supported on Windows (they are only supported on Linux with ROCm). Abogen will still work on the CPU, but processing will be slower compared to a supported GPU. > > If you have a compatible NVIDIA GPU on Windows and still see this warning: > Open your terminal in the Abogen folder (the folder that contains `python_embedded`) and type: > ```bash -> python_embedded\python.exe -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 +> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 > ``` -> If you have an AMD GPU, use Linux and follow the Linux/ROCm [instructions](#how-to-install-). If you want to keep running on CPU, no action is required, but performance will just be reduced. See [#32](https://github.com/denizsafak/abogen/issues/32) for more details. +> +> If this does not resolve the issue and you are using an older NVIDIA GPU that does not support CUDA 12.8, you can try installing an older version of PyTorch that supports your GPU. For example, for CUDA 12.6, run: +> ```bash +> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu126 torchvision==0.23.0+cu126 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu126 +> ``` +> +> If you have an AMD GPU, you need to use Linux and follow the Linux/ROCm [instructions](#linux). If you want to keep running on CPU, no action is required, but performance will just be reduced. See [#32](https://github.com/denizsafak/abogen/issues/32) for more details. @@ -382,7 +389,7 @@ This will start Abogen in command-line mode and display detailed error messages. > I faced this error when trying to run Abogen in a virtual Windows machine without GPU support. Here's how I fixed it: > If you installed Abogen using the Windows installer `(WINDOWS_INSTALL.bat)`, go to Abogen's folder (that contains `python_embedded`), open your terminal there and run: > ```bash -> python_embedded\python.exe -m pip install torch==2.8.0 torchaudio==2.8.0 torchvision==0.23.0 +> python_embedded\python.exe -m pip install --force-reinstall torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 > ``` > If you installed Abogen using pip, open your terminal in the virtual environment and run: > ```bash diff --git a/WINDOWS_INSTALL.bat b/WINDOWS_INSTALL.bat index 35af1ed..a9beca6 100644 --- a/WINDOWS_INSTALL.bat +++ b/WINDOWS_INSTALL.bat @@ -260,7 +260,9 @@ if exist %PYPROJECT_FILE% ( :: Install misaki again if MISAKI_LANG is not set to "en" if "%MISAKI_LANG%" NEQ "en" ( echo Configuring language pack: %MISAKI_LANG% - %PYTHON_CONSOLE_PATH% -m pip install misaki[%MISAKI_LANG%] --upgrade --no-warn-script-location + :: We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628 + :: Solution mentioned by @mazenemam19 in #99: + %PYTHON_CONSOLE_PATH% -m pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location if errorlevel 1 ( echo Failed to install misaki language pack. pause @@ -279,7 +281,9 @@ if /I "%IS_NVIDIA%"=="true" ( if "%cuda_available%"=="False" ( echo Installing PyTorch with CUDA (12.8) support... - %PYTHON_CONSOLE_PATH% -m pip install torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location + :: We need to use an older version of PyTorch (2.8.0) until this issue is fixed: https://github.com/pytorch/pytorch/issues/166628 + :: Solution mentioned by @mazenemam19 in #99: + %PYTHON_CONSOLE_PATH% -m pip install torch==2.8.0+cu128 torchvision==0.23.0+cu128 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location echo. if errorlevel 1 ( echo Failed to install PyTorch. diff --git a/abogen/main.py b/abogen/main.py index 8c68453..86982e8 100644 --- a/abogen/main.py +++ b/abogen/main.py @@ -4,23 +4,17 @@ import platform import atexit import signal -# Fix PyTorch DLL loading issue on Windows before importing PyQt6 +# Fix PyTorch DLL loading issue ([WinError 1114]) on Windows before importing PyQt6 if platform.system() == "Windows": import ctypes - import site - - for site_path in site.getsitepackages(): - torch_lib_path = os.path.join(site_path, "torch", "lib") - if os.path.exists(torch_lib_path): - # Pre-load torch DLLs before Qt can interfere - for dll in ['c10.dll', 'torch_cpu.dll', 'torch_python.dll']: - dll_path = os.path.join(torch_lib_path, dll) - if os.path.exists(dll_path): - try: - ctypes.CDLL(dll_path) - except Exception: - pass - break + from importlib.util import find_spec + try: + if (spec := find_spec("torch")) and spec.origin and os.path.exists( + dll_path := os.path.join(os.path.dirname(spec.origin), "lib", "c10.dll") + ): + ctypes.CDLL(os.path.normpath(dll_path)) + except Exception: + pass # Qt platform plugin detection (fixes #59) try: