63 lines
2.2 KiB
Python
Executable File
63 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Validation sur une machine AVEC GPU : la roue voit-elle le GPU, et
|
|
faster-whisper transcrit-il en français dessus ?
|
|
|
|
pip install faster-whisper --extra-index-url https://git.lemesre.org/api/packages/<owner>/pypi/simple
|
|
python3 tools/smoke-gpu.py [audio.wav]
|
|
|
|
Sans argument, seul le comptage des GPU est fait. cuBLAS 13 et cuDNN 9
|
|
doivent être trouvables (toolkit CUDA système, ou paquets pip nvidia-*
|
|
dont le script ajoute les dossiers lib à LD_LIBRARY_PATH s'ils existent).
|
|
"""
|
|
import ctypes
|
|
import importlib
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
|
|
def dossiers_nvidia_pip() -> list[str]:
|
|
dossiers = []
|
|
for module in ("nvidia.cublas", "nvidia.cudnn", "nvidia.cuda_runtime"):
|
|
try:
|
|
m = importlib.import_module(module)
|
|
except ImportError:
|
|
continue
|
|
lib = os.path.join(os.path.dirname(m.__file__), "lib")
|
|
if os.path.isdir(lib):
|
|
dossiers.append(lib)
|
|
return dossiers
|
|
|
|
|
|
def main() -> int:
|
|
for d in dossiers_nvidia_pip():
|
|
for f in sorted(os.listdir(d)):
|
|
if f.startswith(("libcublas", "libcudnn")) and ".so" in f:
|
|
try:
|
|
ctypes.CDLL(os.path.join(d, f))
|
|
except OSError:
|
|
pass
|
|
import ctranslate2
|
|
n = ctranslate2.get_cuda_device_count()
|
|
print(f"ctranslate2 {ctranslate2.__version__} — GPU CUDA visibles : {n}")
|
|
if n == 0:
|
|
print("aucun GPU : la roue est CPU ou CUDA est introuvable", file=sys.stderr)
|
|
return 1
|
|
print("types de calcul GPU :", sorted(ctranslate2.get_supported_compute_types("cuda")))
|
|
if len(sys.argv) < 2:
|
|
return 0
|
|
from faster_whisper import WhisperModel
|
|
modele = WhisperModel("large-v3", device="cuda", compute_type="float16")
|
|
debut = time.perf_counter()
|
|
segments, info = modele.transcribe(sys.argv[1], language="fr", beam_size=5, vad_filter=True)
|
|
texte = [(s.start, s.end, s.text) for s in segments]
|
|
duree = time.perf_counter() - debut
|
|
print(f"audio {info.duration:.1f} s transcrit en {duree:.1f} s, langue forcée fr")
|
|
for start, end, t in texte[:10]:
|
|
print(f"[{start:6.1f}-{end:6.1f}] {t.strip()}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|