Skip to content

Commit 2a88d2d

Browse files
committed
feat: added exponential scheduler
1 parent 697d000 commit 2a88d2d

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ class StableDiffusionGGML {
456456
LOG_INFO("running with Karras schedule");
457457
denoiser->schedule = std::make_shared<KarrasSchedule>();
458458
break;
459+
case EXPONENTIAL:
460+
LOG_INFO("running exponential schedule");
461+
denoiser->schedule = std::make_shared<ExponentialSchedule>();
462+
break;
459463
case AYS:
460464
LOG_INFO("Running with Align-Your-Steps schedule");
461465
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)