diff --git a/src/senselab/audio/tasks/speech_to_text/canary_qwen.py b/src/senselab/audio/tasks/speech_to_text/canary_qwen.py index b2cac113d..b93f25647 100644 --- a/src/senselab/audio/tasks/speech_to_text/canary_qwen.py +++ b/src/senselab/audio/tasks/speech_to_text/canary_qwen.py @@ -25,7 +25,13 @@ from senselab.audio.data_structures import Audio from senselab.utils.data_structures import DeviceType, HFModel, ScriptLine, _select_device_and_dtype -from senselab.utils.subprocess_venv import _clean_subprocess_env, ensure_venv, parse_subprocess_result, venv_python +from senselab.utils.subprocess_venv import ( + _clean_subprocess_env, + _find_uv, + ensure_venv, + parse_subprocess_result, + venv_python, +) # Dedicated venv — kept separate from the existing nemo-diarization venv. # Canary-Qwen needs nemo_toolkit[asr,tts] (the [tts] extra pulls @@ -147,6 +153,35 @@ def transcribe_with_canary_qwen( device_type = device or _select_device_and_dtype(compatible_devices=[DeviceType.CUDA, DeviceType.CPU])[0] venv_dir = ensure_venv(_CANARY_VENV, _CANARY_REQUIREMENTS, python_version=_CANARY_PYTHON) + + # PyPI ships torch 2.8.x as +cu129 but torchaudio 2.8.x as +cu128 — a + # CUDA-tag skew that triggers a torchaudio RuntimeError ("PyTorch has + # CUDA 12.9 whereas TorchAudio has CUDA 12.8") at import. Force- + # reinstall both from the cu128 PyTorch index so they share a CUDA + # tag; --no-deps leaves NeMo and the nvidia-*-cu12 runtime libs in + # place. cu128 is forward-compatible with cu12+ and cu13 drivers. + cuda_fixup_marker = venv_dir / ".senselab-canary-cuda-fixup" + if not cuda_fixup_marker.is_file(): + subprocess.run( + [ + _find_uv(), + "pip", + "install", + "--python", + venv_python(venv_dir), + "--force-reinstall", + "--no-deps", + "--index-url", + "https://download.pytorch.org/whl/cu128", + "torch>=2.8,<2.9", + "torchaudio>=2.8,<2.9", + ], + check=True, + capture_output=True, + text=True, + ) + cuda_fixup_marker.touch() + python = venv_python(venv_dir) with tempfile.TemporaryDirectory(prefix="senselab-canary-qwen-") as tmpdir: diff --git a/src/senselab/utils/subprocess_venv.py b/src/senselab/utils/subprocess_venv.py index aceac4f17..b25321826 100644 --- a/src/senselab/utils/subprocess_venv.py +++ b/src/senselab/utils/subprocess_venv.py @@ -217,7 +217,7 @@ def ensure_venv( try: subprocess.run( - [uv, "venv", "--python", py_ver, str(venv_dir)], + [uv, "venv", "--managed-python", "--python", py_ver, str(venv_dir)], check=True, capture_output=True, text=True,