MCPcopy Create free account
hub / github.com/ASLP-lab/OSUM / forward

Method forward

OSUM-EChat/tts/cosyvoice/flow/decoder.py:217–301  ·  view source on GitHub ↗

Forward pass of the UNet1DConditional model. Args: x (torch.Tensor): shape (batch_size, in_channels, time) mask (_type_): shape (batch_size, 1, time) t (_type_): shape (batch_size) spks (_type_, optional): shape: (batch_size, condition_channel

(self, x, mask, mu, t, spks=None, cond=None)

Source from the content-addressed store, hash-verified

215 nn.init.constant_(m.bias, 0)
216
217 def forward(self, x, mask, mu, t, spks=None, cond=None):
218 """Forward pass of the UNet1DConditional model.
219
220 Args:
221 x (torch.Tensor): shape (batch_size, in_channels, time)
222 mask (_type_): shape (batch_size, 1, time)
223 t (_type_): shape (batch_size)
224 spks (_type_, optional): shape: (batch_size, condition_channels). Defaults to None.
225 cond (_type_, optional): placeholder for future use. Defaults to None.
226
227 Raises:
228 ValueError: _description_
229 ValueError: _description_
230
231 Returns:
232 _type_: _description_
233 """
234
235 t = self.time_embeddings(t).to(t.dtype)
236 t = self.time_mlp(t)
237
238 x = pack([x, mu], "b * t")[0]
239
240 if spks is not None:
241 spks = repeat(spks, "b c -> b c t", t=x.shape[-1])
242 x = pack([x, spks], "b * t")[0]
243 if cond is not None:
244 x = pack([x, cond], "b * t")[0]
245
246 hiddens = []
247 masks = [mask]
248 for resnet, transformer_blocks, downsample in self.down_blocks:
249 mask_down = masks[-1]
250 x = resnet(x, mask_down, t)
251 x = rearrange(x, "b c t -> b t c").contiguous()
252 # attn_mask = torch.matmul(mask_down.transpose(1, 2).contiguous(), mask_down)
253 attn_mask = add_optional_chunk_mask(x, mask_down.bool(), False, False, 0, self.static_chunk_size, -1)
254 attn_mask = mask_to_bias(attn_mask == 1, x.dtype)
255 for transformer_block in transformer_blocks:
256 x = transformer_block(
257 hidden_states=x,
258 attention_mask=attn_mask,
259 timestep=t,
260 )
261 x = rearrange(x, "b t c -> b c t").contiguous()
262 hiddens.append(x) # Save hidden states for skip connections
263 x = downsample(x * mask_down)
264 masks.append(mask_down[:, :, ::2])
265 masks = masks[:-1]
266 mask_mid = masks[-1]
267
268 for resnet, transformer_blocks in self.mid_blocks:
269 x = resnet(x, mask_mid, t)
270 x = rearrange(x, "b c t -> b t c").contiguous()
271 # attn_mask = torch.matmul(mask_mid.transpose(1, 2).contiguous(), mask_mid)
272 attn_mask = add_optional_chunk_mask(x, mask_mid.bool(), False, False, 0, self.static_chunk_size, -1)
273 attn_mask = mask_to_bias(attn_mask == 1, x.dtype)
274 for transformer_block in transformer_blocks:

Callers

nothing calls this directly

Calls 2

add_optional_chunk_maskFunction · 0.90
mask_to_biasFunction · 0.90

Tested by

no test coverage detected