Skip to content

Commit 49d6570

Browse files
authored
feat: add SmoothStep Scheduler (#813)
1 parent 6bbaf16 commit 49d6570

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

denoiser.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,35 @@ struct KarrasSchedule : SigmaSchedule {
251251
}
252252
};
253253

254+
// Close to Beta Schedule, but increadably simple in code.
255+
struct SmoothStepSchedule : SigmaSchedule {
256+
static constexpr float smoothstep(float x) {
257+
return x * x * (3.0f - 2.0f * x);
258+
}
259+
260+
std::vector<float> get_sigmas(uint32_t n, float /*sigma_min*/, float /*sigma_max*/, t_to_sigma_t t_to_sigma) override {
261+
std::vector<float> result;
262+
result.reserve(n + 1);
263+
264+
const int t_max = TIMESTEPS - 1;
265+
if (n == 0) {
266+
return result;
267+
} else if (n == 1) {
268+
result.push_back(t_to_sigma((float)t_max));
269+
result.push_back(0.f);
270+
return result;
271+
}
272+
273+
for (uint32_t i = 0; i < n; i++) {
274+
float u = 1.f - float(i) / float(n);
275+
result.push_back(t_to_sigma(std::round(smoothstep(u) * t_max)));
276+
}
277+
278+
result.push_back(0.f);
279+
return result;
280+
}
281+
};
282+
254283
struct Denoiser {
255284
std::shared_ptr<SigmaSchedule> scheduler = std::make_shared<DiscreteSchedule>();
256285
virtual float sigma_min() = 0;

examples/cli/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void print_usage(int argc, const char* argv[]) {
238238
printf(" --skip-layers LAYERS Layers to skip for SLG steps: (default: [7,8,9])\n");
239239
printf(" --skip-layer-start START SLG enabling point: (default: 0.01)\n");
240240
printf(" --skip-layer-end END SLG disabling point: (default: 0.2)\n");
241-
printf(" --scheduler {discrete, karras, exponential, ays, gits} Denoiser sigma scheduler (default: discrete)\n");
241+
printf(" --scheduler {discrete, karras, exponential, ays, gits, smoothstep} Denoiser sigma scheduler (default: discrete)\n");
242242
printf(" --sampling-method {euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing, tcd}\n");
243243
printf(" sampling method (default: \"euler_a\")\n");
244244
printf(" --steps STEPS number of sample steps (default: 20)\n");
@@ -251,7 +251,7 @@ void print_usage(int argc, const char* argv[]) {
251251
printf(" --high-noise-skip-layers LAYERS (high noise) Layers to skip for SLG steps: (default: [7,8,9])\n");
252252
printf(" --high-noise-skip-layer-start (high noise) SLG enabling point: (default: 0.01)\n");
253253
printf(" --high-noise-skip-layer-end END (high noise) SLG disabling point: (default: 0.2)\n");
254-
printf(" --high-noise-scheduler {discrete, karras, exponential, ays, gits} Denoiser sigma scheduler (default: discrete)\n");
254+
printf(" --high-noise-scheduler {discrete, karras, exponential, ays, gits, smoothstep} Denoiser sigma scheduler (default: discrete)\n");
255255
printf(" --high-noise-sampling-method {euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing, tcd}\n");
256256
printf(" (high noise) sampling method (default: \"euler_a\")\n");
257257
printf(" --high-noise-steps STEPS (high noise) number of sample steps (default: -1 = auto)\n");

stable-diffusion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,10 @@ class StableDiffusionGGML {
751751
denoiser->scheduler = std::make_shared<GITSSchedule>();
752752
denoiser->scheduler->version = version;
753753
break;
754+
case SMOOTHSTEP:
755+
LOG_INFO("Running with SmoothStep scheduler");
756+
denoiser->scheduler = std::make_shared<SmoothStepSchedule>();
757+
break;
754758
case DEFAULT:
755759
// Don't touch anything.
756760
break;
@@ -1534,6 +1538,7 @@ const char* schedule_to_str[] = {
15341538
"exponential",
15351539
"ays",
15361540
"gits",
1541+
"smoothstep",
15371542
};
15381543

15391544
const char* sd_schedule_name(enum scheduler_t scheduler) {

stable-diffusion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum scheduler_t {
5757
EXPONENTIAL,
5858
AYS,
5959
GITS,
60+
SMOOTHSTEP,
6061
SCHEDULE_COUNT
6162
};
6263

0 commit comments

Comments
 (0)