From a34bf501a5d342b0cfc5e82723c8621ca9f726b7 Mon Sep 17 00:00:00 2001 From: cyberslack_lee Date: Fri, 6 Dec 2024 17:06:11 +0800 Subject: [PATCH] =?UTF-8?q?[Hackathon=207th]=20=E4=BF=AE=E5=A4=8D=20openco?= =?UTF-8?q?pop=E7=9A=84svs1=E4=B8=AD=E7=9A=84shape=E9=97=AE=E9=A2=98=20(#3?= =?UTF-8?q?912)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix svs1 * fix * fix * fix * fix * add comment --- paddlespeech/t2s/modules/diffnet.py | 6 +++++- paddlespeech/t2s/modules/nets_utils.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/paddlespeech/t2s/modules/diffnet.py b/paddlespeech/t2s/modules/diffnet.py index 2f433ad68..deae4847f 100644 --- a/paddlespeech/t2s/modules/diffnet.py +++ b/paddlespeech/t2s/modules/diffnet.py @@ -120,7 +120,11 @@ class SinusoidalPosEmb(nn.Layer): self.dim = dim def forward(self, x: paddle.Tensor): - x = paddle.cast(x, 'float32') + # check if x is 0-dim tensor, if so, add a dimension + if x.ndim == 0: + x = paddle.cast(x.unsqueeze(0), 'float32') + else: + x = paddle.cast(x, 'float32') half_dim = self.dim // 2 emb = math.log(10000) / (half_dim - 1) emb = paddle.exp(paddle.arange(half_dim) * -emb) diff --git a/paddlespeech/t2s/modules/nets_utils.py b/paddlespeech/t2s/modules/nets_utils.py index 0a66a1c88..a3c6947b8 100644 --- a/paddlespeech/t2s/modules/nets_utils.py +++ b/paddlespeech/t2s/modules/nets_utils.py @@ -181,11 +181,12 @@ def make_pad_mask(lengths, xs=None, length_dim=-1): if length_dim == 0: raise ValueError("length_dim cannot be 0: {}".format(length_dim)) - # check if ilens is 0-dim tensor, if so, add a dimension + # check if lengths is 0-dim tensor, if so, add a dimension if lengths.ndim == 0: - lengths = lengths.unsqueeze(0) + bs = paddle.shape(lengths.unsqueeze(0)) + else: + bs = paddle.shape(lengths) - bs = paddle.shape(lengths) if xs is None: maxlen = paddle.cast(lengths.max(), dtype=bs.dtype) else: