From dccfb2326e4f228cb4f0f2338906924f8857cda2 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Wed, 25 Oct 2023 15:24:50 +0700 Subject: [PATCH] fix: new comfyui break sampling --- animatediff/sliding_context_sampling.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/animatediff/sliding_context_sampling.py b/animatediff/sliding_context_sampling.py index cfd1956..6e7fd9c 100644 --- a/animatediff/sliding_context_sampling.py +++ b/animatediff/sliding_context_sampling.py @@ -17,6 +17,10 @@ orig_comfy_sample = comfy.sample.sample orig_sampling_function = comfy_samplers.sampling_function +def lcm(a, b): + return abs(a * b) // math.gcd(a, b) + + class SlidingContext: def __init__( self, @@ -177,7 +181,7 @@ def __sliding_sample_factory(ctx: SlidingContext): if s1[0] != s2[0] or s1[2] != s2[2]: # these 2 cases should not happen return False - mult_min = comfy_samplers.lcm(s1[1], s2[1]) + mult_min = lcm(s1[1], s2[1]) diff = mult_min // min(s1[1], s2[1]) if ( diff > 4 @@ -222,7 +226,7 @@ def __sliding_sample_factory(ctx: SlidingContext): if crossattn_max_len == 0: crossattn_max_len = c.shape[1] else: - crossattn_max_len = comfy_samplers.lcm(crossattn_max_len, c.shape[1]) + crossattn_max_len = lcm(crossattn_max_len, c.shape[1]) c_crossattn.append(c) if "c_concat" in x: c_concat.append(x["c_concat"])