Sync CFG-enabled tts_engine.py
Browse files157 unmodified lines15815916016116216316416515 unmodified lines18118218318418518635 unmodified lines222223224225226227228229230231232233234157 unmodified lines# 4. Expand text representations to mel length using alignmentcond_mel = torch.bmm(h_text.transpose(1, 2), align_path.to(h_text.dtype)) # (B, C, T_mel)# 5. Masked Flow Matching Losscfm_loss = self.cfm.compute_loss(mel_gt, cond_mel, mel_mask=mel_mask)total_loss = (self.train_config.cfm_loss_weight * cfm_loss15 unmodified linestext_lengths: Optional[torch.Tensor] = None,num_steps: Optional[int] = None,speed: float = 1.0,return_waveform: bool = True,) -> Dict[str, torch.Tensor]:"""35 unmodified linesT_mel = cond.shape[-1]mel_mask = torch.arange(T_mel, device=device).unsqueeze(0) < mel_lengths.unsqueeze(1)# 4. Solve Flow Matching ODEsteps = num_steps if num_steps is not None else self.config.default_ode_stepsmel_pred = self.cfm.sample(cond,num_steps=steps,method=self.config.ode_method,mel_mask=mel_mask,)result = {"mel": mel_pred, "mel_lengths": mel_lengths}157 unmodified lines15815916016116216316416516616715 unmodified lines18318418518618718818935 unmodified lines225226227228229230231232233234235236237238239157 unmodified lines# 4. Expand text representations to mel length using alignmentcond_mel = torch.bmm(h_text.transpose(1, 2), align_path.to(h_text.dtype)) # (B, C, T_mel)# 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 linestext_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 linesT_mel = cond.shape[-1]mel_mask = torch.arange(T_mel, device=device).unsqueeze(0) < mel_lengths.unsqueeze(1)# 4. Solve Flow Matching ODE with Classifier-Free Guidancesteps = num_steps if num_steps is not None else self.config.default_ode_stepsguidance = cfg_scale if cfg_scale is not None else self.config.default_cfg_scalemel_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