MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / forward

Method forward

modules/fastspeech/tts_modules.py:282–307  ·  view source on GitHub ↗

:param x: [B, T, C] :param padding_mask: [B, T] :return: [B, T, C] or [L, B, T, C]

(self, x, padding_mask=None, attn_mask=None, return_hiddens=False)

Source from the content-addressed store, hash-verified

280 self.layer_norm = None
281
282 def forward(self, x, padding_mask=None, attn_mask=None, return_hiddens=False):
283 """
284 :param x: [B, T, C]
285 :param padding_mask: [B, T]
286 :return: [B, T, C] or [L, B, T, C]
287 """
288 padding_mask = x.abs().sum(-1).eq(0).data if padding_mask is None else padding_mask
289 nonpadding_mask_TB = 1 - padding_mask.transpose(0, 1).float()[:, :, None] # [T, B, 1]
290 if self.use_pos_embed:
291 positions = self.pos_embed_alpha * self.embed_positions(x[..., 0])
292 x = x + positions
293 x = F.dropout(x, p=self.dropout, training=self.training)
294 # B x T x C -> T x B x C
295 x = x.transpose(0, 1) * nonpadding_mask_TB
296 hiddens = []
297 for layer in self.layers:
298 x = layer(x, encoder_padding_mask=padding_mask, attn_mask=attn_mask) * nonpadding_mask_TB
299 hiddens.append(x)
300 if self.use_last_norm:
301 x = self.layer_norm(x) * nonpadding_mask_TB
302 if return_hiddens:
303 x = torch.stack(hiddens, 0) # [L, T, B, C]
304 x = x.transpose(1, 2) # [L, B, T, C]
305 else:
306 x = x.transpose(0, 1) # [B, T, C]
307 return x
308
309
310class FastspeechEncoder(FFTBlocks):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected