Spaces:
Running
on
Zero
Running
on
Zero
Update whisper_cs_dev.py
Browse filesAdded load_cudnn to solve the LD_LIBRARY_PATH issue
- whisper_cs_dev.py +43 -0
whisper_cs_dev.py
CHANGED
@@ -6,9 +6,51 @@ import torchaudio
|
|
6 |
import torch
|
7 |
import re
|
8 |
import time
|
|
|
|
|
|
|
|
|
9 |
|
10 |
from settings import DEBUG_MODE, MODEL_PATH_V2_FAST, MODEL_PATH_V2, LEFT_CHANNEL_TEMP_PATH, RIGHT_CHANNEL_TEMP_PATH, FAKE_AUDIO_PATH, RESAMPLING_FREQ
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def get_settings():
|
14 |
|
@@ -310,6 +352,7 @@ def generate(audio_path, use_v2_fast):
|
|
310 |
|
311 |
start = time.time()
|
312 |
|
|
|
313 |
device, compute_type = get_settings()
|
314 |
model, fake_model = load_model(use_v2_fast, device, compute_type)
|
315 |
split_input_stereo_channels(audio_path)
|
|
|
6 |
import torch
|
7 |
import re
|
8 |
import time
|
9 |
+
import sys
|
10 |
+
from pathlib import Path
|
11 |
+
import glob
|
12 |
+
import ctypes
|
13 |
|
14 |
from settings import DEBUG_MODE, MODEL_PATH_V2_FAST, MODEL_PATH_V2, LEFT_CHANNEL_TEMP_PATH, RIGHT_CHANNEL_TEMP_PATH, FAKE_AUDIO_PATH, RESAMPLING_FREQ
|
15 |
|
16 |
+
def load_cudnn():
|
17 |
+
|
18 |
+
if not torch.cuda.is_available():
|
19 |
+
if DEBUG_MODE: print("[INFO] CUDA is not available, skipping cuDNN setup.")
|
20 |
+
return
|
21 |
+
|
22 |
+
if DEBUG_MODE: print(f"[INFO] sys.platform: {sys.platform}")
|
23 |
+
if sys.platform == "win32":
|
24 |
+
torch_lib_dir = Path(torch.__file__).parent / "lib"
|
25 |
+
if torch_lib_dir.exists():
|
26 |
+
os.add_dll_directory(str(torch_lib_dir))
|
27 |
+
if DEBUG_MODE: print(f"[INFO] Added DLL directory: {torch_lib_dir}")
|
28 |
+
else:
|
29 |
+
if DEBUG_MODE: print(f"[WARNING] Torch lib directory not found: {torch_lib_dir}")
|
30 |
+
|
31 |
+
elif sys.platform == "linux":
|
32 |
+
site_packages = Path(torch.__file__).resolve().parents[1]
|
33 |
+
cudnn_dir = site_packages / "nvidia" / "cudnn" / "lib"
|
34 |
+
|
35 |
+
if not cudnn_dir.exists():
|
36 |
+
if DEBUG_MODE: print(f"[ERROR] cudnn dir not found: {cudnn_dir}")
|
37 |
+
return
|
38 |
+
|
39 |
+
pattern = str(cudnn_dir / "libcudnn_cnn*.so*")
|
40 |
+
matching_files = sorted(glob.glob(pattern))
|
41 |
+
if not matching_files:
|
42 |
+
if DEBUG_MODE: print(f"[ERROR] No libcudnn_cnn*.so* found in {cudnn_dir}")
|
43 |
+
return
|
44 |
+
|
45 |
+
for so_path in matching_files:
|
46 |
+
try:
|
47 |
+
ctypes.CDLL(so_path, mode=ctypes.RTLD_GLOBAL)
|
48 |
+
if DEBUG_MODE: print(f"[INFO] Loaded: {so_path}")
|
49 |
+
except OSError as e:
|
50 |
+
if DEBUG_MODE: print(f"[WARNING] Failed to load {so_path}: {e}")
|
51 |
+
else:
|
52 |
+
if DEBUG_MODE: print(f"[WARNING] sys.platform is not win32 or linux")
|
53 |
+
|
54 |
|
55 |
def get_settings():
|
56 |
|
|
|
352 |
|
353 |
start = time.time()
|
354 |
|
355 |
+
load_cudnn()
|
356 |
device, compute_type = get_settings()
|
357 |
model, fake_model = load_model(use_v2_fast, device, compute_type)
|
358 |
split_input_stereo_channels(audio_path)
|