Skip to content

Commit 1b3bf0a

Browse files
authored
Fix res_multistep_ancestral sampler (Comfy-Org#8030)
1 parent ae60b15 commit 1b3bf0a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

comfy/k_diffusion/sampling.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ def res_multistep(model, x, sigmas, extra_args=None, callback=None, disable=None
12771277
phi1_fn = lambda t: torch.expm1(t) / t
12781278
phi2_fn = lambda t: (phi1_fn(t) - 1.0) / t
12791279

1280+
old_sigma_down = None
12801281
old_denoised = None
12811282
uncond_denoised = None
12821283
def post_cfg_function(args):
@@ -1304,9 +1305,9 @@ def post_cfg_function(args):
13041305
x = x + d * dt
13051306
else:
13061307
# Second order multistep method in https://arxiv.org/pdf/2308.02157
1307-
t, t_next, t_prev = t_fn(sigmas[i]), t_fn(sigma_down), t_fn(sigmas[i - 1])
1308+
t, t_old, t_next, t_prev = t_fn(sigmas[i]), t_fn(old_sigma_down), t_fn(sigma_down), t_fn(sigmas[i - 1])
13081309
h = t_next - t
1309-
c2 = (t_prev - t) / h
1310+
c2 = (t_prev - t_old) / h
13101311

13111312
phi1_val, phi2_val = phi1_fn(-h), phi2_fn(-h)
13121313
b1 = torch.nan_to_num(phi1_val - phi2_val / c2, nan=0.0)
@@ -1326,6 +1327,7 @@ def post_cfg_function(args):
13261327
old_denoised = uncond_denoised
13271328
else:
13281329
old_denoised = denoised
1330+
old_sigma_down = sigma_down
13291331
return x
13301332

13311333
@torch.no_grad()

0 commit comments

Comments
 (0)