|
From 36078b25801787f0a0f145143637f46d33d8c389 Mon Sep 17 00:00:00 2001 |
|
From: Ashen <[email protected]> |
|
Date: Fri, 7 Apr 2023 22:04:35 -0700 |
|
Subject: [PATCH] karras v2 experimental |
|
|
|
|
|
k_diffusion/sampling.py | 36 ++++++++++++++++++++++++++++++++++++ |
|
1 file changed, 36 insertions(+) |
|
|
|
|
|
|
|
|
|
|
|
@@ -605,3 +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_test(model, x, sigmas, extra_args=None, callback=None, disable=None): |
|
+ """DPM-Solver++(2M).""" |
|
+ 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 |
|
\ No newline at end of file |
|
-- |
|
2.40.0 |
|
|
|
|