Skip to content

Commit 2174ce5

Browse files
authored
Fix Beta sampling to match the paper (#16926)
1 parent 82bf9a3 commit 2174ce5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

modules/sd_schedulers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,15 @@ def ddim_scheduler(n, sigma_min, sigma_max, inner_model, device):
117117

118118

119119
def beta_scheduler(n, sigma_min, sigma_max, inner_model, device):
120-
# From "Beta Sampling is All You Need" [arXiv:2407.12173] (Lee et. al, 2024) """
120+
# From "Beta Sampling is All You Need" [arXiv:2407.12173] (Lee et. al, 2024)
121121
alpha = shared.opts.beta_dist_alpha
122122
beta = shared.opts.beta_dist_beta
123-
timesteps = 1 - np.linspace(0, 1, n)
124-
timesteps = [stats.beta.ppf(x, alpha, beta) for x in timesteps]
125-
sigmas = [sigma_min + (x * (sigma_max-sigma_min)) for x in timesteps]
123+
curve = [stats.beta.ppf(x, alpha, beta) for x in np.linspace(1, 0, n)]
124+
125+
start = inner_model.sigma_to_t(torch.tensor(sigma_max))
126+
end = inner_model.sigma_to_t(torch.tensor(sigma_min))
127+
timesteps = [end + x * (start - end) for x in curve]
128+
sigmas = [inner_model.t_to_sigma(ts) for ts in timesteps]
126129
sigmas += [0.0]
127130
return torch.FloatTensor(sigmas).to(device)
128131

modules/shared_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@
407407
'uni_pc_lower_order_final': OptionInfo(True, "UniPC lower order final", infotext='UniPC lower order final'),
408408
'sd_noise_schedule': OptionInfo("Default", "Noise schedule for sampling", gr.Radio, {"choices": ["Default", "Zero Terminal SNR"]}, infotext="Noise Schedule").info("for use with zero terminal SNR trained models"),
409409
'skip_early_cond': OptionInfo(0.0, "Ignore negative prompt during early sampling", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}, infotext="Skip Early CFG").info("disables CFG on a proportion of steps at the beginning of generation; 0=skip none; 1=skip all; can both improve sample diversity/quality and speed up sampling; XYZ plot: Skip Early CFG"),
410-
'beta_dist_alpha': OptionInfo(0.6, "Beta scheduler - alpha", gr.Slider, {"minimum": 0.01, "maximum": 1.0, "step": 0.01}, infotext='Beta scheduler alpha').info('Default = 0.6; the alpha parameter of the beta distribution used in Beta sampling'),
411-
'beta_dist_beta': OptionInfo(0.6, "Beta scheduler - beta", gr.Slider, {"minimum": 0.01, "maximum": 1.0, "step": 0.01}, infotext='Beta scheduler beta').info('Default = 0.6; the beta parameter of the beta distribution used in Beta sampling'),
410+
'beta_dist_alpha': OptionInfo(0.6, "Beta scheduler - alpha", gr.Slider, {"minimum": 0.01, "maximum": 5.0, "step": 0.01}, infotext='Beta scheduler alpha').info('Default = 0.6; the alpha parameter of the beta distribution used in Beta sampling'),
411+
'beta_dist_beta': OptionInfo(0.6, "Beta scheduler - beta", gr.Slider, {"minimum": 0.01, "maximum": 5.0, "step": 0.01}, infotext='Beta scheduler beta').info('Default = 0.6; the beta parameter of the beta distribution used in Beta sampling'),
412412
}))
413413

414414
options_templates.update(options_section(('postprocessing', "Postprocessing", "postprocessing"), {

0 commit comments

Comments
 (0)