Add temperature=0.667 & Sway sampling to reduce hiss/noise
Browse files188 unmodified lines189190191192193194195194196197198199200201202203201202204205206207208209207210211212213214215216217218188 unmodified lines method: str = "midpoint", mel_mask: Optional[torch.Tensor] = None, cfg_scale: float = 1.0, temperature: float = 0.667, sway_sampling_coef: float = -1.0, ) -> torch.Tensor: """ Ultrafast ODE sampling from t=0 (noise) to t=1 (mel spectrogram) with optional CFG. Ultrafast ODE sampling from t=0 (noise) to t=1 (mel spectrogram) with optional CFG, temperature scaling (removes background hiss), and Sway Sampling (F5-TTS). cond: (B, cond_dim, T) """ B, _, T = cond.shape device = cond.device mask_3d = mel_mask.unsqueeze(1).to(cond.dtype) if mel_mask is not None else None
# Start at noise x0 ~ N(0, I) x = torch.randn(B, self.vf.mel_dim, T, device=device, dtype=cond.dtype) # Start at scaled noise x0 ~ N(0, temperature^2 * I) x = torch.randn(B, self.vf.mel_dim, T, device=device, dtype=cond.dtype) * temperature if mask_3d is not None: x = x * mask_3d cond = cond * mask_3d
dt = 1.0 / num_steps t_steps = torch.linspace(0.0, 1.0, num_steps + 1, device=device, dtype=cond.dtype) if sway_sampling_coef != 0.0: t_steps = t_steps + sway_sampling_coef * (torch.cos(math.pi / 2.0 * t_steps) - 1.0 + t_steps)
for i in range(num_steps): dt = (t_steps[i + 1] - t_steps[i]).item() t_curr = t_steps[i].repeat(B)
if method == "midpoint":models/flow_matching.py+9-4