Try faster-whisper first for audio pre-load, fall back to GGUF

parent 4f6d64d4
......@@ -3613,17 +3613,13 @@ def main():
if should_preload:
print(f"Pre-loading audio model...")
try:
# Try faster-whisper first (requires torch)
from faster_whisper import WhisperModel
import torch
model_to_use = args.audio_model
model_path = None
# Check if model is a GGUF file - use llama.cpp (Vulkan) instead of faster-whisper
is_gguf = model_to_use.endswith('.gguf') or '.gguf?' in model_to_use or 'gguf' in model_to_use.lower()
if is_gguf:
# Use llama.cpp for GGUF audio models (works with Vulkan)
print(f"Using GGUF format with llama.cpp (Vulkan)...")
from llama_cpp import Llama
# Check if model is a URL - handle caching
if model_to_use.startswith('http://') or model_to_use.startswith('https://'):
cached_path = get_cached_model_path(model_to_use)
......@@ -3636,22 +3632,29 @@ def main():
model_path = download_model(model_to_use, cache_dir)
model_to_use = model_path
# Load with llama.cpp (Vulkan)
audio_model = Llama(
model_path=model_to_use,
n_gpu_layers=-1, # All layers to GPU
n_ctx=2048,
verbose=False
# Determine compute type
compute_type = "float16" if torch.cuda.is_available() else "int8"
# Load the model
whisper_model = WhisperModel(
model_to_use,
device="cuda" if torch.cuda.is_available() else "cpu",
compute_type=compute_type
)
# Store in multi_model_manager
model_key = f"audio:{args.audio_model}"
multi_model_manager.add_model(model_key, audio_model)
print(f"Audio model loaded successfully (GGUF/Vulkan)")
else:
# Use faster-whisper for non-GGUF models
from faster_whisper import WhisperModel
import torch
multi_model_manager.add_model(model_key, whisper_model)
print(f"Audio model loaded successfully (faster-whisper)")
except ImportError:
# faster-whisper not available, try GGUF with llama.cpp
print("faster-whisper not available, trying GGUF with llama.cpp...")
try:
from llama_cpp import Llama
model_to_use = args.audio_model
model_path = None
# Check if model is a URL - handle caching
if model_to_use.startswith('http://') or model_to_use.startswith('https://'):
......@@ -3665,26 +3668,27 @@ def main():
model_path = download_model(model_to_use, cache_dir)
model_to_use = model_path
# Determine compute type
compute_type = "float16" if torch.cuda.is_available() else "int8"
# Load the model
whisper_model = WhisperModel(
model_to_use,
device="cuda" if torch.cuda.is_available() else "cpu",
compute_type=compute_type
# Load with llama.cpp (Vulkan)
audio_model = Llama(
model_path=model_to_use,
n_gpu_layers=-1, # All layers to GPU
n_ctx=2048,
verbose=False
)
# Store in multi_model_manager
model_key = f"audio:{args.audio_model}"
multi_model_manager.add_model(model_key, whisper_model)
print(f"Audio model loaded successfully")
multi_model_manager.add_model(model_key, audio_model)
print(f"Audio model loaded successfully (GGUF/Vulkan)")
except Exception as e:
print(f"Warning: Could not pre-load audio model: {e}")
import traceback
traceback.print_exc()
except Exception as e:
print(f"Warning: Could not pre-load audio model: {e}")
# Set up TTS model if specified
if args.tts_model:
print(f"\nText-to-speech model: {args.tts_model}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment