From f309586b5f0b4ffd57b1298eaad53f9672a60790 Mon Sep 17 00:00:00 2001 From: Dawid Date: Sat, 14 Jan 2023 09:49:19 -0800 Subject: [PATCH 1/3] TextToSpeech to utilize passed device arg --- tortoise/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tortoise/api.py b/tortoise/api.py index 296ef14a..856cb2c9 100644 --- a/tortoise/api.py +++ b/tortoise/api.py @@ -213,7 +213,9 @@ def __init__(self, autoregressive_batch_size=None, models_dir=MODELS_DIR, enable self.models_dir = models_dir self.autoregressive_batch_size = pick_best_batch_size_for_gpu() if autoregressive_batch_size is None else autoregressive_batch_size self.enable_redaction = enable_redaction - self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') + if device is None: + device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') + self.device = device if self.enable_redaction: self.aligner = Wav2VecAlignment() From 4de0c4205e3a376f6f5a28379fa209ef0d1e1b32 Mon Sep 17 00:00:00 2001 From: Dawid Date: Wed, 24 May 2023 21:18:42 -0700 Subject: [PATCH 2/3] Explicit logging if device isn't set --- tortoise/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tortoise/api.py b/tortoise/api.py index 856cb2c9..ea979266 100644 --- a/tortoise/api.py +++ b/tortoise/api.py @@ -1,3 +1,4 @@ +import logging import os import random import uuid @@ -214,6 +215,7 @@ def __init__(self, autoregressive_batch_size=None, models_dir=MODELS_DIR, enable self.autoregressive_batch_size = pick_best_batch_size_for_gpu() if autoregressive_batch_size is None else autoregressive_batch_size self.enable_redaction = enable_redaction if device is None: + logging.warning("No device specified. This will default to the first GPU if available, otherwise CPU.") device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') self.device = device if self.enable_redaction: From c6088aa6ff48cbfae457a21e053a964d5862014e Mon Sep 17 00:00:00 2001 From: Dawid Date: Wed, 24 May 2023 21:25:18 -0700 Subject: [PATCH 3/3] Isolate device setter with loud warning --- tortoise/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tortoise/api.py b/tortoise/api.py index ea979266..088c7250 100644 --- a/tortoise/api.py +++ b/tortoise/api.py @@ -214,10 +214,7 @@ def __init__(self, autoregressive_batch_size=None, models_dir=MODELS_DIR, enable self.models_dir = models_dir self.autoregressive_batch_size = pick_best_batch_size_for_gpu() if autoregressive_batch_size is None else autoregressive_batch_size self.enable_redaction = enable_redaction - if device is None: - logging.warning("No device specified. This will default to the first GPU if available, otherwise CPU.") - device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') - self.device = device + self._set_device(device) if self.enable_redaction: self.aligner = Wav2VecAlignment() @@ -254,6 +251,14 @@ def __init__(self, autoregressive_batch_size=None, models_dir=MODELS_DIR, enable self.rlg_auto = None self.rlg_diffusion = None + def _set_device(self, device): + if device is None: + logging.warning("No device specified. This will default to the first GPU if available, otherwise CPU.") + device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') + if device == 'cpu' or (isinstance(device, torch.device) and device.type == 'cpu'): + logging.warning("Running on CPU. This will be painfully slow. You've been warned.") + self.device = device + def load_cvvp(self): """Load CVVP model.""" self.cvvp = CVVP(model_dim=512, transformer_heads=8, dropout=0, mel_codes=8192, conditioning_enc_depth=8, cond_mask_percentage=0,