feat(config): добавлена поддержка устройства openvino в конфиге и auto-detect

- Зачем:
  - подготовка к OpenVINO бэкенду: config и utils должны знать о новом устройстве.
- Что:
  - config.py: openvino добавлен в _VALID_DEVICES и DEVICE_DEFAULTS (model=medium, compute_type=int8).
  - utils.py: detect_device() расширен цепочкой CUDA → OpenVINO → CPU; _is_openvino_available() проверяет архитектуру (x86_64/AMD64) и наличие openvino_genai.
  - cli.py: --device help text обновлён (auto|cpu|cuda|openvino).
  - добавлены тесты: config с openvino device, device defaults, auto-detect приоритет.
- Проверка:
  - uv run pytest -v — 103 passed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-21 23:22:13 +03:00
co-authored by Claude Opus 4.6
parent 4c5399c2fc
commit fae25a7fb3
5 changed files with 63 additions and 4 deletions
+15
View File
@@ -128,3 +128,18 @@ def test_apply_device_defaults_config_overrides():
result = apply_device_defaults(defaults, "cuda", cli, config)
assert result["model"] == "small"
assert result["compute_type"] == "int8"
def test_load_config_openvino_device(tmp_path):
config = tmp_path / "config.toml"
config.write_text('device = "openvino"\n')
result = load_config(config)
assert result == {"device": "openvino"}
def test_apply_device_defaults_openvino():
defaults = {"model": "medium", "language": "ru", "device": "auto", "compute_type": "float32"}
cli = {"model": None, "language": None, "device": None, "compute_type": None}
result = apply_device_defaults(defaults, "openvino", cli, {})
assert result["model"] == "medium"
assert result["compute_type"] == "int8"
+28
View File
@@ -58,6 +58,34 @@ def test_build_output_path_custom():
def test_detect_device_explicit():
assert detect_device("cpu") == "cpu"
assert detect_device("cuda") == "cuda"
assert detect_device("openvino") == "openvino"
def test_detect_device_auto_openvino():
"""Нет nvidia-smi, есть openvino_genai, x86_64 → openvino."""
with (
patch("local_transcriber.utils.shutil.which", return_value=None),
patch("local_transcriber.utils._is_openvino_available", return_value=True),
):
assert detect_device("auto") == "openvino"
def test_detect_device_cuda_over_openvino():
"""nvidia-smi доступен и openvino тоже → cuda побеждает."""
with (
patch("local_transcriber.utils.shutil.which", return_value="/usr/bin/nvidia-smi"),
patch("local_transcriber.utils._is_openvino_available", return_value=True),
):
assert detect_device("auto") == "cuda"
def test_detect_device_auto_cpu_fallback():
"""Ни nvidia-smi, ни openvino → cpu."""
with (
patch("local_transcriber.utils.shutil.which", return_value=None),
patch("local_transcriber.utils._is_openvino_available", return_value=False),
):
assert detect_device("auto") == "cpu"
def test_get_gpu_name_no_nvidia_smi():