https://hf.co/hexgrad/Kokoro-82M
Python
Enable MPS GPU Accerlation on MacOS (#164)
fondoger6d87f4ae7abc
diff --git a/README.md b/README.mdindex 57a6a24..765dcc7 100644--- a/README.md+++ b/README.md@@ -95,6 +95,14 @@ To install espeak-ng on Windows:For advanced configuration and usage on Windows, see the [official espeak-ng Windows guide](https://github.com/espeak-ng/espeak-ng/blob/master/docs/guide.md)+### MacOS Apple Silicon GPU Acceleration++On Mac M1/M2/M3/M4 devices, you can explicitly specify the environment variable `PYTORCH_ENABLE_MPS_FALLBACK=1` to enable GPU acceleration.++```bash+PYTORCH_ENABLE_MPS_FALLBACK=1 python run-your-kokoro-script.py+```+### Conda EnvironmentUse the following conda `environment.yml` if you're facing any dependency issues.```yamldiff --git a/kokoro/pipeline.py b/kokoro/pipeline.pyindex f23b13e..3377069 100644--- a/kokoro/pipeline.py+++ b/kokoro/pipeline.py@@ -6,6 +6,7 @@ from misaki import en, espeakfrom typing import Callable, Generator, List, Optional, Tuple, Unionimport reimport torch+import osALIASES = {'en-us': 'a',@@ -93,8 +94,17 @@ class KPipeline:elif model:if device == 'cuda' and not torch.cuda.is_available():raise RuntimeError("CUDA requested but not available")+ if device == 'mps' and not torch.backends.mps.is_available():+ raise RuntimeError("MPS requested but not available")+ if device == 'mps' and os.environ.get('PYTORCH_ENABLE_MPS_FALLBACK') != '1':+ raise RuntimeError("MPS requested but fallback not enabled")if device is None:- device = 'cuda' if torch.cuda.is_available() else 'cpu'+ if torch.cuda.is_available():+ device = 'cuda'+ elif os.environ.get('PYTORCH_ENABLE_MPS_FALLBACK') == '1' and torch.backends.mps.is_available():+ device = 'mps'+ else:+ device = 'cpu'try:self.model = KModel(repo_id=repo_id).to(device).eval()except RuntimeError as e: