From 06a5255937af9c16fc136d1b860a6e9999f3c898 Mon Sep 17 00:00:00 2001 From: Tristan Helmich Date: Thu, 7 May 2026 13:14:40 +0200 Subject: [PATCH] fix(transcribe): auto-fallback to CPU with int8 when CUDA is unavailable Instead of raising ValueError when the requested CUDA device is not present, automatically fall back to CPU and downgrade compute_type from float16 to int8 (float16 is unsupported on CPU). Also indicate whether CPU is forced or a fallback in the model-loading print message. --- meet/transcribe.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/meet/transcribe.py b/meet/transcribe.py index b7d06d4..3283664 100644 --- a/meet/transcribe.py +++ b/meet/transcribe.py @@ -494,23 +494,31 @@ def __post_init__(self): # Validate device availability when torch is installed. We deliberately # skip validation when torch can't be imported so that # `TranscriptionConfig` remains constructible in torch-less test - # environments and lightweight CLI helpers (e.g. `meet check`). + # environments and lightweight CLI helpers. + # + # When the requested device is not available we automatically fall back + # to CPU instead of raising — this handles the common case where CUDA + # was requested but no GPU is present (e.g. running on a laptop or + # inside a container without GPU passthrough). for field_name, value in ( ("device", self.device), ("torch_device", self.torch_device), ): available = _torch_device_available(value) if available is None: - # torch is not installed (or device string is unknown to our - # helper) — skip. continue if not available: - raise ValueError( - f"{field_name}='{value}' but {value.upper()} is not " - f"available on this system. " - "Try --device cpu (and --torch-device cpu/mps) or install " - "the appropriate torch build." + fallback = "cpu" if value == "cuda" else "cpu" + log.warning( + "%s='%s' is not available, falling back to '%s'", + field_name, value, fallback, ) + if field_name == "device": + self.device = fallback + if self.compute_type == "float16": + self.compute_type = "int8" + elif field_name == "torch_device": + self.torch_device = fallback if self.hf_token is None: self.hf_token = os.environ.get("HF_TOKEN") @@ -822,8 +830,18 @@ def _load_whisperx_asr_model(config: TranscriptionConfig, language: str | None): "vad_onset": config.vad_onset, "vad_offset": config.vad_offset, } + device_note = "" + if config.device == "cpu": + try: + import torch as _torch + if _torch.cuda.is_available(): + device_note = " (forced)" + else: + device_note = " (fallback — no GPU)" + except ImportError: + device_note = " (no torch)" print( - f" Loading model: {config.model} ({config.compute_type}) on {config.device}" + f" Loading model: {config.model} ({config.compute_type}) on {config.device}{device_note}" ) return whisperx.load_model( config.model,