feat(cuda): добавлен прозрачный GPU runtime для Linux/WSL2
- Зачем:
- ctranslate2 требует libcublas.so.12 для CUDA, но не бандлит её в wheel —
без системного CUDA toolkit GPU не работает из коробки.
- Что:
- добавлена зависимость nvidia-cublas-cu12 (Linux x86_64).
- создан _cuda_bootstrap.py: preload libcublas через ctypes.CDLL(RTLD_GLOBAL)
до импорта ctranslate2 (LD_LIBRARY_PATH не работает — glibc кеширует пути).
- добавлен strict_device в transcriber: --device cuda/cpu не делает silent fallback.
- CLI: диагностика requested vs resolved device, Windows CUDA-подсказка.
- Проверка:
- uv run pytest -v (52 passed, 1 skipped).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
@@ -6,7 +7,7 @@ from rich.console import Console
|
||||
from rich.status import Status
|
||||
|
||||
from .formatter import format_transcript, write_transcript
|
||||
from .transcriber import Segment, ensure_model_available, transcribe
|
||||
from .transcriber import Segment, _is_cuda_error, ensure_model_available, transcribe
|
||||
from .utils import build_output_path, check_ffmpeg, detect_device, get_gpu_name, validate_input_file
|
||||
|
||||
app = typer.Typer()
|
||||
@@ -27,7 +28,9 @@ def main(
|
||||
|
||||
check_ffmpeg()
|
||||
validated_file = validate_input_file(file)
|
||||
requested_device = device
|
||||
resolved_device = detect_device(device)
|
||||
strict = requested_device != "auto"
|
||||
output_path = build_output_path(validated_file, output)
|
||||
|
||||
console.print(f"Файл: [bold]{validated_file.name}[/bold]")
|
||||
@@ -38,19 +41,45 @@ def main(
|
||||
def on_segment(seg: Segment) -> None:
|
||||
console.print(f" [{seg.start:.2f}s] {seg.text.strip()}")
|
||||
|
||||
with Status("Подготавливаю запуск...", console=console) as status:
|
||||
result = transcribe(
|
||||
file_path=validated_file,
|
||||
model_name=model_path,
|
||||
device=resolved_device,
|
||||
compute_type=compute_type,
|
||||
language=language if language != "auto" else None,
|
||||
on_segment=on_segment if verbose else None,
|
||||
on_status=status.update,
|
||||
)
|
||||
try:
|
||||
with Status("Подготавливаю запуск...", console=console) as status:
|
||||
result = transcribe(
|
||||
file_path=validated_file,
|
||||
model_name=model_path,
|
||||
device=resolved_device,
|
||||
compute_type=compute_type,
|
||||
language=language if language != "auto" else None,
|
||||
on_segment=on_segment if verbose else None,
|
||||
on_status=status.update,
|
||||
strict_device=strict,
|
||||
)
|
||||
except (RuntimeError, ValueError) as exc:
|
||||
if _is_cuda_error(exc) and sys.platform == "win32":
|
||||
console.print(
|
||||
"GPU на Windows требует CUDA toolkit (включает cuBLAS).\n"
|
||||
"Установите одним из способов:\n"
|
||||
" choco install cuda\n"
|
||||
" winget install -e --id Nvidia.CUDA\n"
|
||||
"После установки перезапустите терминал.",
|
||||
style="yellow",
|
||||
)
|
||||
raise
|
||||
|
||||
if result.device_used != resolved_device:
|
||||
if requested_device == "auto":
|
||||
console.print(
|
||||
f"Определено устройство {resolved_device}, "
|
||||
f"но использовано {result.device_used} (fallback)",
|
||||
style="yellow",
|
||||
)
|
||||
else:
|
||||
console.print(
|
||||
f"Запрошено {requested_device}, использовано {result.device_used}",
|
||||
style="yellow",
|
||||
)
|
||||
|
||||
if len(result.segments) == 0:
|
||||
console.print(f"⚠ Речь не обнаружена в файле {validated_file.name}", style="yellow")
|
||||
console.print(f"Речь не обнаружена в файле {validated_file.name}", style="yellow")
|
||||
|
||||
if result.device_used == "cuda":
|
||||
gpu_name = get_gpu_name()
|
||||
@@ -70,7 +99,7 @@ def main(
|
||||
write_transcript(content, output_path)
|
||||
|
||||
elapsed = time.monotonic() - start
|
||||
console.print(f"✓ Транскрипт сохранён: [bold]{output_path}[/bold]", style="green")
|
||||
console.print(f"Транскрипт сохранён: [bold]{output_path}[/bold]", style="green")
|
||||
console.print(f" Сегментов: {len(result.segments)} Время: {elapsed:.1f}с")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user