mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-02-04 02:43:36 +00:00
fix: avoid issues when sigma_min is close to 0 (#1138)
This commit is contained in:
parent
6eefd2d49a
commit
a119a4da9a
20
denoiser.hpp
20
denoiser.hpp
@ -276,6 +276,10 @@ struct KarrasScheduler : SigmaScheduler {
|
||||
// but does anybody ever bother to touch them?
|
||||
float rho = 7.f;
|
||||
|
||||
if (sigma_min <= 1e-6f) {
|
||||
sigma_min = 1e-6f;
|
||||
}
|
||||
|
||||
std::vector<float> result(n + 1);
|
||||
|
||||
float min_inv_rho = pow(sigma_min, (1.f / rho));
|
||||
@ -347,7 +351,6 @@ struct SmoothStepScheduler : SigmaScheduler {
|
||||
}
|
||||
};
|
||||
|
||||
// Implementation adapted from https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/15608
|
||||
struct KLOptimalScheduler : SigmaScheduler {
|
||||
std::vector<float> get_sigmas(uint32_t n, float sigma_min, float sigma_max, t_to_sigma_t t_to_sigma) override {
|
||||
std::vector<float> sigmas;
|
||||
@ -355,27 +358,28 @@ struct KLOptimalScheduler : SigmaScheduler {
|
||||
if (n == 0) {
|
||||
return sigmas;
|
||||
}
|
||||
|
||||
if (n == 1) {
|
||||
sigmas.push_back(sigma_max);
|
||||
sigmas.push_back(0.0f);
|
||||
return sigmas;
|
||||
}
|
||||
|
||||
if (sigma_min <= 1e-6f) {
|
||||
sigma_min = 1e-6f;
|
||||
}
|
||||
|
||||
sigmas.reserve(n + 1);
|
||||
|
||||
float alpha_min = std::atan(sigma_min);
|
||||
float alpha_max = std::atan(sigma_max);
|
||||
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
// t goes from 0.0 to 1.0
|
||||
float t = static_cast<float>(i) / static_cast<float>(n - 1);
|
||||
|
||||
// Interpolate in the angle domain
|
||||
float t = static_cast<float>(i) / static_cast<float>(n - 1);
|
||||
float angle = t * alpha_min + (1.0f - t) * alpha_max;
|
||||
|
||||
// Convert back to sigma
|
||||
sigmas.push_back(std::tan(angle));
|
||||
}
|
||||
|
||||
// Append the final zero to sigma
|
||||
sigmas.push_back(0.0f);
|
||||
|
||||
return sigmas;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user