-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use torch.special.expm1
#6388
Use torch.special.expm1
#6388
Conversation
This function provides greater precision than `exp(x) - 1` for small values of `x`. Found with TorchFix https://github.com/pytorch-labs/torchfix/
@@ -40,7 +40,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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just be able to do:
sigmas = torch.sqrt((beta_d * t ** 2 / 2 + beta_min * t).expm1())
That's the approach other stuff in ComfyUI that uses expm1
takes (see k_diffusion/sampling.py
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also fine, doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't matter.
The result is the same, generally it's easier from a code maintenance perspective if different parts of the code implementing something don't each use a different approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update to this style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
This function provides greater precision than
exp(x) - 1
for small values ofx
.Found with TorchFix https://github.com/pytorch-labs/torchfix/