22 lines
923 B
Python
22 lines
923 B
Python
import glob, os, site
|
|
import numpy as np
|
|
|
|
# pip nvidia-* wheels ship cublas/cudnn DLLs; ctranslate2 needs them on PATH (Windows)
|
|
for sp in site.getsitepackages():
|
|
for b in glob.glob(os.path.join(sp, "nvidia", "*", "bin")):
|
|
os.add_dll_directory(b); os.environ["PATH"] = b + os.pathsep + os.environ["PATH"]
|
|
|
|
from faster_whisper import WhisperModel
|
|
|
|
CORES = max(1, (os.cpu_count() or 2) // 2) # ponytail: logical/2 ~ physical cores (no psutil); exact count if hybrid CPUs need it
|
|
|
|
def load_model(name):
|
|
"""CUDA if it really works (probe one decode), else CPU int8."""
|
|
try:
|
|
m = WhisperModel(name, device="cuda", compute_type="default")
|
|
list(m.transcribe(np.zeros(16000, np.float32))[0])
|
|
return m, "cuda"
|
|
except Exception as e:
|
|
print("cuda failed, using cpu:", e, flush=True)
|
|
return WhisperModel(name, device="cpu", compute_type="int8", cpu_threads=CORES), "cpu"
|