Skip to content

High-Quality Voice Cloning TTS for 600+ Languages

Python

Add Intel XPU (Intel Arc GPU) inference support (#55)

Michael Ashley33a8ca325d9c
diff --git a/README.md b/README.md
index 481ca61..cf76e7e 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,34 @@ pip install torch==2.8.0 torchaudio==2.8.0
</details>
+<details>
+<summary>Intel Arc GPU (XPU)</summary>
+
+Intel Arc GPUs (Alchemist and Battlemage architectures) are supported via PyTorch's XPU backend.
+
+1. Install the [Intel GPU drivers](https://dgpu-docs.intel.com/driver/installation.html) for your OS.
+
+2. Install PyTorch with XPU support from Intel's wheel index:
+
+```bash
+pip install torch torchaudio --index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/
+```
+
+> See [Intel's PyTorch XPU guide](https://intel.github.io/intel-extension-for-pytorch/xpu/latest/) for version-specific instructions.
+
+3. Verify the backend is working:
+
+```bash
+python -c "import torch; print(torch.xpu.is_available(), torch.xpu.device_count())"
+```
+
+**Notes**:
+- `flash_attn` is not available on XPU; the model automatically falls back to SDPA.
+- Training with packed sequences (`flex_attention`) has partial XPU support; single-GPU SDPA training should work.
+- Tested on Arc A310 (Alchemist, 4 GB) and Arc Pro B50 (Battlemage, 16 GB).
+
+</details>
+
**Step 2**: Install OmniVoice (choose one)
```bash
@@ -125,6 +153,7 @@ model = OmniVoice.from_pretrained(
dtype=torch.float16
)
# Apple Silicon users: use device_map="mps" instead
+# Intel Arc GPU users: use device_map="xpu" instead
audio = model.generate(
text="Hello, this is a test of zero-shot voice cloning.",
diff --git a/omnivoice/cli/demo.py b/omnivoice/cli/demo.py
index f45ac77..8dd3f2c 100644
--- a/omnivoice/cli/demo.py
+++ b/omnivoice/cli/demo.py
@@ -32,18 +32,10 @@ import numpy as np
import torch
from omnivoice import OmniVoice, OmniVoiceGenerationConfig
+from omnivoice.utils.common import get_best_device
from omnivoice.utils.lang_map import LANG_NAMES, lang_display_name
-def get_best_device():
- """Auto-detect the best available device: CUDA > MPS > CPU."""
- if torch.cuda.is_available():
- return "cuda"
- if torch.backends.mps.is_available():
- return "mps"
- return "cpu"
-
-
# ---------------------------------------------------------------------------
# Language list — all 600+ supported languages
# ---------------------------------------------------------------------------
diff --git a/omnivoice/cli/infer.py b/omnivoice/cli/infer.py
index 32447b9..ce4657d 100644
--- a/omnivoice/cli/infer.py
+++ b/omnivoice/cli/infer.py
@@ -27,16 +27,7 @@ import torch
import soundfile as sf
from omnivoice.models.omnivoice import OmniVoice
-from omnivoice.utils.common import str2bool
-
-
-def get_best_device():
- """Auto-detect the best available device: CUDA > MPS > CPU."""
- if torch.cuda.is_available():
- return "cuda"
- if torch.backends.mps.is_available():
- return "mps"
- return "cpu"
+from omnivoice.utils.common import get_best_device, str2bool
def get_parser() -> argparse.ArgumentParser:
diff --git a/omnivoice/cli/infer_batch.py b/omnivoice/cli/infer_batch.py
index 4b24912..b1d19d6 100644
--- a/omnivoice/cli/infer_batch.py
+++ b/omnivoice/cli/infer_batch.py
@@ -48,20 +48,11 @@ from omnivoice.models.omnivoice import OmniVoice
import soundfile as sf
from omnivoice.utils.audio import load_audio
-from omnivoice.utils.common import str2bool
+from omnivoice.utils.common import get_best_device_with_count, str2bool
from omnivoice.utils.data_utils import read_test_list
from omnivoice.utils.duration import RuleDurationEstimator
-def get_best_device():
- """Auto-detect the best available device: CUDA > MPS > CPU."""
- if torch.cuda.is_available():
- return "cuda", torch.cuda.device_count()
- if torch.backends.mps.is_available():
- return "mps", 1
- return "cpu", 1
-
-
worker_model = None
SAMPLING_RATE = 24000
@@ -228,7 +219,7 @@ def process_init(rank_queue, model_checkpoint, warmup=0):
elif device_type == "mps":
worker_device = "mps"
else:
- worker_device = f"cuda:{device_id}"
+ worker_device = f"{device_type}:{device_id}"
logging.info(f"Initializing worker on device: {worker_device}")
@@ -420,7 +411,7 @@ def main():
args = get_parser().parse_args()
os.makedirs(args.res_dir, exist_ok=True)
- device_type, num_devices = get_best_device()
+ device_type, num_devices = get_best_device_with_count()
if device_type == "cpu":
logging.warning(
"No GPU found. Falling back to CPU inference. This might be slow."
diff --git a/omnivoice/models/omnivoice.py b/omnivoice/models/omnivoice.py
index 96673eb..4d78f8a 100644
--- a/omnivoice/models/omnivoice.py
+++ b/omnivoice/models/omnivoice.py
@@ -305,7 +305,7 @@ class OmniVoice(PreTrainedModel):
logger.info("Loading ASR model %s ...", model_name)
asr_dtype = (
- torch.float16 if str(self.device).startswith("cuda") else torch.float32
+ torch.float16 if str(self.device).startswith(("cuda", "xpu")) else torch.float32
)
model_name = _resolve_model_path(model_name)
diff --git a/omnivoice/utils/common.py b/omnivoice/utils/common.py
index 6bdd342..fd8378b 100644
--- a/omnivoice/utils/common.py
+++ b/omnivoice/utils/common.py
@@ -43,6 +43,28 @@ def str2bool(v):
raise argparse.ArgumentTypeError("Boolean value expected.")
+def get_best_device():
+ """Auto-detect the best available device: CUDA > XPU > MPS > CPU."""
+ if torch.cuda.is_available():
+ return "cuda"
+ if hasattr(torch, "xpu") and torch.xpu.is_available():
+ return "xpu"
+ if torch.backends.mps.is_available():
+ return "mps"
+ return "cpu"
+
+
+def get_best_device_with_count():
+ """Auto-detect best device and return (device_type, device_count)."""
+ if torch.cuda.is_available():
+ return "cuda", torch.cuda.device_count()
+ if hasattr(torch, "xpu") and torch.xpu.is_available():
+ return "xpu", torch.xpu.device_count()
+ if torch.backends.mps.is_available():
+ return "mps", 1
+ return "cpu", 1
+
+
def fix_random_seed(random_seed: int):
"""
Set the same random seed for the libraries and modules.