feat(transcription): drive engine choice from AccelPath resolver (P0)

load_transcriber now resolves the accel path instead of assuming a GPU
BackendId has a working offload. Only requests whisper GPU offload for
WhisperCuda/WhisperVulkan; NPU goes to the ONNX engine; everything else decodes
on CPU and reports the backend actually used.
This commit is contained in:
iamdoubz
2026-07-05 19:27:28 -05:00
parent e9567b823a
commit 7fe0d87e55
+20 -5
View File
@@ -119,8 +119,15 @@ fn load_transcriber(
backend: BackendId,
whisper_model: &Path,
) -> Result<(Box<dyn Transcriber>, BackendId), crate::transcription::TrxError> {
use crate::hardware::{resolve_accel, AccelPath};
// Resolve how this backend is actually served in *this* build (CUDA/Vulkan
// baked in? NPU/DirectML runtime present?) rather than assuming a GPU
// backend has a working accel path just because the hardware exists.
let path = resolve_accel(backend);
#[cfg(feature = "npu")]
if backend == BackendId::Npu {
if path == AccelPath::OnnxOpenVino {
use crate::transcription::{onnx_models, OnnxNpuTranscriber};
if onnx_models::is_installed(onnx_models::DEFAULT_ONNX_MODEL) {
let dir = onnx_models::model_dir(onnx_models::DEFAULT_ONNX_MODEL);
@@ -134,10 +141,18 @@ fn load_transcriber(
);
}
}
match WhisperTranscriber::load(whisper_model, backend) {
Ok(t) => Ok((Box::new(t), backend)),
Err(e) if backend != BackendId::Cpu => {
tracing::warn!("backend {backend:?} failed to load ({e}); falling back to CPU");
// whisper.cpp path: only ask for GPU offload when the resolver picked a
// whisper GPU backend that's compiled in — otherwise a bogus `use_gpu` for a
// vendor with no accel path just no-ops. Anything else decodes on the CPU.
let whisper_backend = match path {
AccelPath::WhisperCuda | AccelPath::WhisperVulkan => backend,
_ => BackendId::Cpu,
};
match WhisperTranscriber::load(whisper_model, whisper_backend) {
Ok(t) => Ok((Box::new(t), whisper_backend)),
Err(e) if whisper_backend != BackendId::Cpu => {
tracing::warn!("backend {whisper_backend:?} failed to load ({e}); falling back to CPU");
WhisperTranscriber::load(whisper_model, BackendId::Cpu)
.map(|t| (Box::new(t) as Box<dyn Transcriber>, BackendId::Cpu))
}