From 6d20ce0108d3f3bb1aef3da1ae95b166583a879b Mon Sep 17 00:00:00 2001 From: shanshan shen Date: Wed, 16 Oct 2024 13:04:53 +0000 Subject: [PATCH] fix bugs of npu support --- ChatTTS/model/dvae.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ChatTTS/model/dvae.py b/ChatTTS/model/dvae.py index 0f745cee4..ad26b5286 100644 --- a/ChatTTS/model/dvae.py +++ b/ChatTTS/model/dvae.py @@ -199,8 +199,15 @@ def __call__(self, audio: torch.Tensor) -> torch.Tensor: return super().__call__(audio) def forward(self, audio: torch.Tensor) -> torch.Tensor: - audio = audio.to(self.device) - mel: torch.Tensor = self.mel_spec(audio) + if "npu" in str(self.device): + # Computation of MelSpectrogram on npu is not supported now, use cpu fallback. + audio = audio.to(torch.device("cpu")) + self.mel_spec.to(torch.device("cpu")) + mel: torch.Tensor = self.mel_spec(audio) + mel = mel.to(self.device) + else: + audio = audio.to(self.device) + mel: torch.Tensor = self.mel_spec(audio) features = torch.log(torch.clip(mel, min=1e-5)) return features