From c7f9f4b56b5198b6301f06693e769c4222927427 Mon Sep 17 00:00:00 2001 From: Sergii Dymchenko Date: Tue, 7 Jan 2025 15:52:45 -0800 Subject: [PATCH] Use `torch.special.expm1` This function provides greater precision than `exp(x) - 1` for small values of `x`. Found with TorchFix https://github.com/pytorch-labs/torchfix/ --- k_diffusion/sampling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k_diffusion/sampling.py b/k_diffusion/sampling.py index 9f10e8d..691189f 100644 --- a/k_diffusion/sampling.py +++ b/k_diffusion/sampling.py @@ -39,7 +39,7 @@ def get_sigmas_polyexponential(n, sigma_min, sigma_max, rho=1., device='cpu'): def get_sigmas_vp(n, beta_d=19.9, beta_min=0.1, eps_s=1e-3, device='cpu'): """Constructs a continuous VP noise schedule.""" t = torch.linspace(1, eps_s, n, device=device) - sigmas = torch.sqrt(torch.exp(beta_d * t ** 2 / 2 + beta_min * t) - 1) + sigmas = torch.sqrt(torch.special.expm1(beta_d * t ** 2 / 2 + beta_min * t)) return append_zero(sigmas)