mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Test MPS GPU acceleratin on Silicon Mac
This commit is contained in:
+20
-3
@@ -23,6 +23,7 @@ import abogen.hf_tracker as hf_tracker
|
||||
import static_ffmpeg
|
||||
import threading # for efficient waiting
|
||||
import subprocess
|
||||
import platform
|
||||
|
||||
|
||||
def get_sample_voice_text(lang_code):
|
||||
@@ -310,8 +311,15 @@ class ConversionThread(QThread):
|
||||
|
||||
self.log_updated.emit("\nInitializing TTS pipeline...")
|
||||
|
||||
# Set device based on use_gpu setting
|
||||
device = "cuda" if self.use_gpu else "cpu"
|
||||
# Set device based on use_gpu setting and platform
|
||||
if self.use_gpu:
|
||||
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||
device = "mps" # Use MPS for Apple Silicon
|
||||
else:
|
||||
device = "cuda" # Use CUDA for other platforms
|
||||
else:
|
||||
device = "cpu"
|
||||
|
||||
tts = self.KPipeline(
|
||||
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
||||
)
|
||||
@@ -1319,7 +1327,16 @@ class VoicePreviewThread(QThread):
|
||||
|
||||
# Generate the preview and save to cache
|
||||
try:
|
||||
device = "cuda" if self.use_gpu else "cpu"
|
||||
|
||||
# Set device based on use_gpu setting and platform
|
||||
if self.use_gpu:
|
||||
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||
device = "mps" # Use MPS for Apple Silicon
|
||||
else:
|
||||
device = "cuda" # Use CUDA for other platforms
|
||||
else:
|
||||
device = "cpu"
|
||||
|
||||
tts = self.kpipeline_class(
|
||||
lang_code=self.lang_code, repo_id="hexgrad/Kokoro-82M", device=device
|
||||
)
|
||||
|
||||
+15
-5
@@ -239,13 +239,23 @@ def calculate_text_length(text):
|
||||
def get_gpu_acceleration(enabled):
|
||||
try:
|
||||
import torch
|
||||
from torch.cuda import is_available
|
||||
from torch.cuda import is_available as cuda_available
|
||||
|
||||
if not enabled:
|
||||
return "CUDA GPU available but using CPU.", False
|
||||
if is_available():
|
||||
return "GPU available but using CPU.", False
|
||||
|
||||
# Check for Apple Silicon MPS
|
||||
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||
if torch.backends.mps.is_available():
|
||||
return "MPS GPU available and enabled.", True
|
||||
else:
|
||||
return "MPS GPU not available on Apple Silicon. Using CPU.", False
|
||||
|
||||
# Check for CUDA
|
||||
if cuda_available():
|
||||
return "CUDA GPU available and enabled.", True
|
||||
# Gather more diagnostic info if CUDA is not available
|
||||
|
||||
# Gather CUDA diagnostic info if not available
|
||||
try:
|
||||
cuda_devices = torch.cuda.device_count()
|
||||
cuda_error = (
|
||||
@@ -257,7 +267,7 @@ def get_gpu_acceleration(enabled):
|
||||
cuda_error = str(e)
|
||||
return f"CUDA GPU is not available. Using CPU. ({cuda_error})", False
|
||||
except Exception as e:
|
||||
return f"Error checking CUDA GPU: {e}", False
|
||||
return f"Error checking GPU: {e}", False
|
||||
|
||||
|
||||
def prevent_sleep_start():
|
||||
|
||||
Reference in New Issue
Block a user