Skip to content

Commit 032f665

Browse files
committed
feat: added exponential scheduler
1 parent 697d000 commit 032f665

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

denoiser.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ struct DiscreteSchedule : SigmaSchedule {
4040
}
4141
};
4242

43+
struct ExponentialSchedule : SigmaSchedule {
44+
std::vector<float> get_sigmas(uint32_t n, float sigma_min, float sigma_max, t_to_sigma_t t_to_sigma) override {
45+
std::vector<float> sigmas;
46+
47+
// Calculate step size
48+
float log_sigma_min = std::log(sigma_min);
49+
float log_sigma_max = std::log(sigma_max);
50+
float step = (log_sigma_max - log_sigma_min) / (n - 1);
51+
52+
// Fill sigmas with exponential values
53+
for (uint32_t i = 0; i < n; ++i) {
54+
float sigma = std::exp(log_sigma_max - step * i);
55+
sigmas.push_back(sigma);
56+
}
57+
58+
sigmas.push_back(0);
59+
60+
return sigmas;
61+
}
62+
};
63+
4364
/*
4465
https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/howto.html
4566
*/

examples/cli/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const char* schedule_str[] = {
4545
"default",
4646
"discrete",
4747
"karras",
48+
"exponential",
4849
"ays",
4950
};
5051

@@ -193,7 +194,7 @@ void print_usage(int argc, const char* argv[]) {
193194
printf(" --rng {std_default, cuda} RNG (default: cuda)\n");
194195
printf(" -s SEED, --seed SEED RNG seed (default: 42, use random seed for < 0)\n");
195196
printf(" -b, --batch-count COUNT number of images to generate.\n");
196-
printf(" --schedule {discrete, karras, ays} Denoiser sigma schedule (default: discrete)\n");
197+
printf(" --schedule {discrete, karras, exponential, ays} Denoiser sigma schedule (default: discrete)\n");
197198
printf(" --clip-skip N ignore last layers of CLIP network; 1 ignores none, 2 ignores one layer (default: -1)\n");
198199
printf(" <= 0 represents unspecified, will be 1 for SD1.x, 2 for SD2.x\n");
199200
printf(" --vae-tiling process vae in tiles to reduce memory usage\n");

stable-diffusion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "rng.hpp"
55
#include "rng_philox.hpp"
66
#include "stable-diffusion.h"
7+
#include <memory>
78
#include "util.h"
89

910
#include "conditioner.hpp"
@@ -456,6 +457,10 @@ class StableDiffusionGGML {
456457
LOG_INFO("running with Karras schedule");
457458
denoiser->schedule = std::make_shared<KarrasSchedule>();
458459
break;
460+
case EXPONENTIAL:
461+
LOG_INFO("running exponential schedule");
462+
denoiser->schedule = std::make_shared<ExponentialSchedule>();
463+
break;
459464
case AYS:
460465
LOG_INFO("Running with Align-Your-Steps schedule");
461466
denoiser->schedule = std::make_shared<AYSSchedule>();

stable-diffusion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum schedule_t {
4949
DEFAULT,
5050
DISCRETE,
5151
KARRAS,
52+
EXPONENTIAL,
5253
AYS,
5354
N_SCHEDULES
5455
};

0 commit comments

Comments
 (0)