feat: Add GPU configuration for Supertonic to enable acceleration support

This commit is contained in:
JB
2025-12-21 08:51:05 -08:00
parent 899c9f5aa5
commit c2209eeb2a
+25
View File
@@ -123,6 +123,28 @@ def _remove_unsupported_characters(text: str, unsupported: Iterable[str]) -> str
return result return result
def _configure_supertonic_gpu() -> None:
"""Patch supertonic's config to enable GPU acceleration if available."""
try:
import onnxruntime as ort
available = ort.get_available_providers()
# Prefer CUDA, then TensorRT, then CPU
providers = []
if "CUDAExecutionProvider" in available:
providers.append("CUDAExecutionProvider")
if "TensorrtExecutionProvider" in available:
providers.insert(0, "TensorrtExecutionProvider")
providers.append("CPUExecutionProvider")
# Patch supertonic's config before TTS import
import supertonic.config as supertonic_config
supertonic_config.DEFAULT_ONNX_PROVIDERS = providers
logger.info("Supertonic ONNX providers configured: %s", providers)
except Exception as exc:
logger.warning("Could not configure supertonic GPU providers: %s", exc)
class SupertonicPipeline: class SupertonicPipeline:
"""Minimal adapter that mimics Kokoro's pipeline iteration interface.""" """Minimal adapter that mimics Kokoro's pipeline iteration interface."""
@@ -138,6 +160,9 @@ class SupertonicPipeline:
self.total_steps = int(total_steps) self.total_steps = int(total_steps)
self.max_chunk_length = int(max_chunk_length) self.max_chunk_length = int(max_chunk_length)
# Configure GPU providers before importing TTS
_configure_supertonic_gpu()
try: try:
from supertonic import TTS # type: ignore[import-not-found] from supertonic import TTS # type: ignore[import-not-found]
except Exception as exc: # pragma: no cover except Exception as exc: # pragma: no cover