openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Fix voice model GPU detection and acceleration selection

Open Al629176 opened this issue 7 months ago • 1 comments

Summary

Fix voice model runtime so GPU detection works reliably and the model uses GPU acceleration when available.

Problem

Voice model is failing to detect GPU, causing fallback to slower/non-accelerated execution.

Scope

  • Audit GPU detection logic and runtime capability checks.
  • Validate platform/device-specific detection paths.
  • Improve logs for GPU discovery, fallback reason, and selected execution mode.
  • Ensure safe fallback to CPU with clear diagnostics when GPU is unavailable.

Acceptance Criteria

  • GPU is detected on supported systems and used by voice model.
  • Fallback to CPU is explicit, correct, and logged with reason.
  • No crashes/regressions across supported platforms.
  • Tests/verification steps included for GPU-present and GPU-absent cases.

Al629176 avatar Apr 14 '26 08:04 Al629176

Refined Scope & Root Cause Analysis

Root Cause

Two compounding issues prevent GPU acceleration for the voice model:

  1. whisper-rs has no GPU features enabled — Cargo.toml declares whisper-rs = "0.16" with no features. The crate's internal _gpu flag is never set, so WhisperContextParameters::default() sets use_gpu: false. On macOS, Metal acceleration is not compiled in.

  2. GPU detection is disconnected from whisper initialization — device.rs detects Apple Silicon (Metal) and populates DeviceProfile.has_gpu, but this field is only used for model tier recommendation. It is never passed to WhisperContextParameters in whisper_engine.rs. Even if GPU were detected, the engine wouldn't use it.

Additionally, non-Apple platforms (Windows/Linux) get no GPU detection at all — detect_gpu() returns (false, None) unconditionally.

Refined Scope

Phase 1 (this issue): Focus on a single model with proper GPU detection and acceleration selection:

  • Enable metal feature for macOS builds (compile whisper.cpp with Metal support)
  • Thread DeviceProfile to whisper engine initialization so use_gpu/flash_attn are set based on detected hardware
  • Expand GPU detection to cover Windows NVIDIA via lightweight nvidia-smi probe
  • Add diagnostic logging for GPU discovery, selected backend, and fallback reason
  • Ensure safe CPU fallback with clear diagnostics when GPU is unavailable

Deferred: Multi-model selection UI, CUDA compile-time feature flag, Vulkan support.

Files to Change

File What Changes
Cargo.toml Add metal feature for whisper-rs on macOS target
src/openhuman/local_ai/device.rs Expand detect_gpu() — Windows NVIDIA probe, better logging
src/openhuman/local_ai/service/whisper_engine.rs Accept DeviceProfile, configure use_gpu/flash_attn explicitly
src/openhuman/local_ai/service/bootstrap.rs Pass DeviceProfile to whisper engine load
src/openhuman/local_ai/service/speech.rs Pass DeviceProfile through lazy load path

oxoxDev avatar Apr 14 '26 13:04 oxoxDev