Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,36 @@
|
|
| 1 |
import os
|
| 2 |
import ctypes
|
| 3 |
-
import glob
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
import nvidia.cudnn
|
| 8 |
cudnn_lib_path = os.path.join(os.path.dirname(nvidia.cudnn.__file__), 'lib')
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
# Order matters: load base libraries before ops libraries
|
| 28 |
-
lib_order = ['libcudnn.so', 'libcudnn_ops_infer.so', 'libcudnn_ops_train.so',
|
| 29 |
-
'libcudnn_cnn_infer.so', 'libcudnn_cnn_train.so',
|
| 30 |
-
'libcudnn_adv_infer.so', 'libcudnn_adv_train.so']
|
| 31 |
-
|
| 32 |
-
loaded_libs = []
|
| 33 |
-
for lib_name in lib_order:
|
| 34 |
-
# Find any version of this library
|
| 35 |
-
matching = [l for l in cudnn_libs if l.startswith(lib_name)]
|
| 36 |
-
if matching:
|
| 37 |
-
lib_path = os.path.join(cudnn_lib_path, matching[0])
|
| 38 |
-
try:
|
| 39 |
-
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
|
| 40 |
-
loaded_libs.append(matching[0])
|
| 41 |
-
print(f"✅ Loaded: {matching[0]}")
|
| 42 |
-
except Exception as e:
|
| 43 |
-
print(f"⚠️ Failed to load {matching[0]}: {e}")
|
| 44 |
-
|
| 45 |
-
if loaded_libs:
|
| 46 |
-
print(f"\n✅ Successfully loaded {len(loaded_libs)} cuDNN libraries")
|
| 47 |
-
else:
|
| 48 |
-
print(f"⚠️ No cuDNN libraries were loaded")
|
| 49 |
-
else:
|
| 50 |
-
print(f"⚠️ cuDNN lib path doesn't exist: {cudnn_lib_path}")
|
| 51 |
|
|
|
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
print(f"⚠️ cuDNN loading error: {e}")
|
| 54 |
-
import traceback
|
| 55 |
-
traceback.print_exc()
|
| 56 |
|
| 57 |
# NOW import torch and other libraries
|
| 58 |
import torch
|
|
@@ -74,17 +52,19 @@ try:
|
|
| 74 |
from faster_whisper import WhisperModel
|
| 75 |
USE_FASTER_WHISPER = True
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
| 80 |
print(f"Loading faster-whisper...")
|
| 81 |
-
print(f" Device: {device}")
|
| 82 |
print(f" Compute type: {compute_type}")
|
| 83 |
|
| 84 |
model = WhisperModel("large-v3", device=device, compute_type=compute_type)
|
| 85 |
|
| 86 |
print("✅ SUCCESS: Using faster-whisper (CTranslate2 backend)")
|
| 87 |
-
print(f" Implementation: CTranslate2 backend")
|
| 88 |
print(f" Model: Whisper Large V3")
|
| 89 |
|
| 90 |
except ImportError as e:
|
|
|
|
| 1 |
import os
|
| 2 |
import ctypes
|
|
|
|
| 3 |
|
| 4 |
+
# Fix for faster-whisper + CUDA/cuDNN issue
|
| 5 |
+
# Based on: https://github.com/SYSTRAN/faster-whisper/issues/1086
|
| 6 |
+
|
| 7 |
+
# Explicitly load cuDNN libraries before CTranslate2 tries to use them
|
| 8 |
try:
|
| 9 |
import nvidia.cudnn
|
| 10 |
cudnn_lib_path = os.path.join(os.path.dirname(nvidia.cudnn.__file__), 'lib')
|
| 11 |
|
| 12 |
+
print(f"Loading cuDNN from: {cudnn_lib_path}")
|
| 13 |
+
|
| 14 |
+
# Load base cuDNN library first with RTLD_GLOBAL
|
| 15 |
+
import glob
|
| 16 |
+
cudnn_base = glob.glob(os.path.join(cudnn_lib_path, 'libcudnn.so*'))
|
| 17 |
+
if cudnn_base:
|
| 18 |
+
ctypes.CDLL(cudnn_base[0], mode=ctypes.RTLD_GLOBAL)
|
| 19 |
+
print(f"✅ Pre-loaded: {os.path.basename(cudnn_base[0])}")
|
| 20 |
+
|
| 21 |
+
# Load cudnn_ops libraries
|
| 22 |
+
cudnn_ops = glob.glob(os.path.join(cudnn_lib_path, 'libcudnn_ops*.so*'))
|
| 23 |
+
for lib in cudnn_ops:
|
| 24 |
+
try:
|
| 25 |
+
ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
|
| 26 |
+
print(f"✅ Pre-loaded: {os.path.basename(lib)}")
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"⚠️ Could not load {os.path.basename(lib)}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
except ImportError:
|
| 31 |
+
print("⚠️ nvidia-cudnn-cu12 not installed, GPU may not work")
|
| 32 |
except Exception as e:
|
| 33 |
print(f"⚠️ cuDNN loading error: {e}")
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# NOW import torch and other libraries
|
| 36 |
import torch
|
|
|
|
| 52 |
from faster_whisper import WhisperModel
|
| 53 |
USE_FASTER_WHISPER = True
|
| 54 |
|
| 55 |
+
# FORCE CPU MODE - cuDNN issues with faster-whisper on HF Spaces
|
| 56 |
+
# See: https://github.com/SYSTRAN/faster-whisper/issues/1086
|
| 57 |
+
device = "cpu"
|
| 58 |
+
compute_type = "int8"
|
| 59 |
|
| 60 |
print(f"Loading faster-whisper...")
|
| 61 |
+
print(f" Device: {device} (forced CPU due to cuDNN compatibility issues)")
|
| 62 |
print(f" Compute type: {compute_type}")
|
| 63 |
|
| 64 |
model = WhisperModel("large-v3", device=device, compute_type=compute_type)
|
| 65 |
|
| 66 |
print("✅ SUCCESS: Using faster-whisper (CTranslate2 backend)")
|
| 67 |
+
print(f" Implementation: CTranslate2 backend (CPU optimized)")
|
| 68 |
print(f" Model: Whisper Large V3")
|
| 69 |
|
| 70 |
except ImportError as e:
|