Sync CFG-enabled tts_engine.py
Browse files157 unmodified lines15815916016116216116216316416516616715 unmodified lines18318418518618718818935 unmodified lines225226227225228229230231232233234235236237238239157 unmodified lines # 4. Expand text representations to mel length using alignment cond_mel = torch.bmm(h_text.transpose(1, 2), align_path.to(h_text.dtype)) # (B, C, T_mel)
# 5. Masked Flow Matching Loss cfm_loss = self.cfm.compute_loss(mel_gt, cond_mel, mel_mask=mel_mask) # 5. Masked Flow Matching Loss (with CFG condition dropout) cfm_loss = self.cfm.compute_loss( mel_gt, cond_mel, mel_mask=mel_mask, p_uncond=self.config.p_uncond )
total_loss = ( self.train_config.cfm_loss_weight * cfm_loss15 unmodified lines text_lengths: Optional[torch.Tensor] = None, num_steps: Optional[int] = None, speed: float = 1.0, cfg_scale: Optional[float] = None, return_waveform: bool = True, ) -> Dict[str, torch.Tensor]: """35 unmodified lines T_mel = cond.shape[-1] mel_mask = torch.arange(T_mel, device=device).unsqueeze(0) < mel_lengths.unsqueeze(1)
# 4. Solve Flow Matching ODE # 4. Solve Flow Matching ODE with Classifier-Free Guidance steps = num_steps if num_steps is not None else self.config.default_ode_steps guidance = cfg_scale if cfg_scale is not None else self.config.default_cfg_scale mel_pred = self.cfm.sample( cond, num_steps=steps, method=self.config.ode_method, mel_mask=mel_mask, cfg_scale=guidance, )
result = {"mel": mel_pred, "mel_lengths": mel_lengths}models/tts_engine.py+8-3