Device resolution

Resolve a device spec (“auto” / “cpu” / “cuda” / “cuda:N”) to a concrete torch device string.

Centralizes the "cuda" if torch.cuda.is_available() else "cpu" idiom that Whisper, Voxtral-HF, Qwen3-FA, Demucs, and LavaSR each reimplement in _apply_config / _load_model.


resolve_torch_device


def resolve_torch_device(
    spec:str='auto', # Requested device: "auto", "cpu", "cuda", or "cuda:N"
)->str: # Concrete device string

Resolve a device spec to a concrete torch device string.

"auto" resolves to "cuda" when CUDA is available, else "cpu". Any explicit spec ("cpu", "cuda", "cuda:0", …) is returned unchanged.

Tests.

# Explicit specs pass through unchanged.
assert resolve_torch_device("cpu") == "cpu"
assert resolve_torch_device("cuda:1") == "cuda:1"

# "auto" resolves to a concrete device matching CUDA availability.
assert resolve_torch_device("auto") in ("cuda", "cpu")
assert resolve_torch_device("auto") == ("cuda" if torch.cuda.is_available() else "cpu")