Add temperature=0.667 & Sway sampling to reduce hiss/noise
Browse files188 unmodified lines189190191192193194195196197198199200201202203204205206207208209210211212213188 unmodified linesmethod: str = "midpoint",mel_mask: Optional[torch.Tensor] = None,cfg_scale: float = 1.0,) -> torch.Tensor:"""Ultrafast ODE sampling from t=0 (noise) to t=1 (mel spectrogram) with optional CFG.cond: (B, cond_dim, T)"""B, _, T = cond.shapedevice = cond.devicemask_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)if mask_3d is not None:x = x * mask_3dcond = cond * mask_3ddt = 1.0 / num_stepst_steps = torch.linspace(0.0, 1.0, num_steps + 1, device=device, dtype=cond.dtype)for i in range(num_steps):t_curr = t_steps[i].repeat(B)if method == "midpoint":188 unmodified lines189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218188 unmodified linesmethod: 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,temperature scaling (removes background hiss), and Sway Sampling (F5-TTS).cond: (B, cond_dim, T)"""B, _, T = cond.shapedevice = cond.devicemask_3d = mel_mask.unsqueeze(1).to(cond.dtype) if mel_mask is not None else None# Start at scaled noise x0 ~ N(0, temperature^2 * I)x = torch.randn(B, self.vf.mel_dim, T, device=device, dtype=cond.dtype) * temperatureif mask_3d is not None:x = x * mask_3dcond = cond * mask_3dt_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