|
From 4394a62004260c3b9d781488e85f959a70910af1 Mon Sep 17 00:00:00 2001 |
|
Date: Sat, 8 Apr 2023 15:11:43 +1000 |
|
Subject: [PATCH] add DPMPP 2M V2 |
|
|
|
|
|
modules/sd_samplers_kdiffusion.py | 16 +++++++++------- |
|
1 file changed, 9 insertions(+), 7 deletions(-) |
|
|
|
|
|
|
|
|
|
|
|
@@ -27,12 +27,12 @@ samplers_k_diffusion = [ |
|
('DPM2 a Karras', 'sample_dpm_2_ancestral', ['k_dpm_2_a_ka'], {'scheduler': 'karras', 'discard_next_to_last_sigma': True}), |
|
('DPM++ 2S a Karras', 'sample_dpmpp_2s_ancestral', ['k_dpmpp_2s_a_ka'], {'scheduler': 'karras'}), |
|
('DPM++ 2M Karras', 'sample_dpmpp_2m', ['k_dpmpp_2m_ka'], {'scheduler': 'karras'}), |
|
+ ('DPM++ 2M v2', 'sample_dpmpp_2m_v2', ['k_dpmpp_2m'], {}), |
|
+ ('DPM++ 2M Karras v2', 'sample_dpmpp_2m_v2', ['k_dpmpp_2m_ka'], {'scheduler': 'karras'}), |
|
('DPM++ SDE Karras', 'sample_dpmpp_sde', ['k_dpmpp_sde_ka'], {'scheduler': 'karras'}), |
|
] |
|
|
|
-- |
|
|
|
|
|
k_diffusion/sampling.py | 36 ++++++++++++++++++++++++++++++++++++ |
|
1 file changed, 36 insertions(+) |
|
|
|
|
|
|
|
|
|
|
|
@@ -605,4 +605,39 @@ def sample_dpmpp_2m(model, x, sigmas, extra_args=None, callback=None, disable=No |
|
x = (sigma_fn(t_next) / sigma_fn(t)) * x - (-h).expm1() * denoised_d |
|
old_denoised = denoised |
|
return x |
|
+ |
|
+ |
|
[email protected]_grad() |
|
+def sample_dpmpp_2m_v2(model, x, sigmas, extra_args=None, callback=None, disable=None): |
|
+ """DPM-Solver++(2M)V2.""" |
|
+ extra_args = {} if extra_args is None else extra_args |
|
+ s_in = x.new_ones([x.shape[0]]) |
|
+ sigma_fn = lambda t: t.neg().exp() |
|
+ t_fn = lambda sigma: sigma.log().neg() |
|
+ old_denoised = None |
|
+ |
|
+ for i in trange(len(sigmas) - 1, disable=disable): |
|
+ denoised = model(x, sigmas[i] * s_in, **extra_args) |
|
+ if callback is not None: |
|
+ callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i], 'denoised': denoised}) |
|
+ t, t_next = t_fn(sigmas[i]), t_fn(sigmas[i + 1]) |
|
+ h = t_next - t |
|
+ |
|
+ t_min = min(sigma_fn(t_next), sigma_fn(t)) |
|
+ t_max = max(sigma_fn(t_next), sigma_fn(t)) |
|
+ |
|
+ if old_denoised is None or sigmas[i + 1] == 0: |
|
+ x = (t_min / t_max) * x - (-h).expm1() * denoised |
|
+ else: |
|
+ h_last = t - t_fn(sigmas[i - 1]) |
|
+ |
|
+ h_min = min(h_last, h) |
|
+ h_max = max(h_last, h) |
|
+ r = h_max / h_min |
|
+ |
|
+ h_d = (h_max + h_min) / 2 |
|
+ denoised_d = (1 + 1 / (2 * r)) * denoised - (1 / (2 * r)) * old_denoised |
|
+ x = (t_min / t_max) * x - (-h_d).expm1() * denoised_d |
|
+ |
|
+ old_denoised = denoised |
|
+ return x |
|
-- |
|
2.34.1 |
|
|
|
|