Skip to content

Commit 58017e8

Browse files
authored
feat: add causal_fix parameter to add_keyframe_index and append_keyframe (Comfy-Org#12797)
Allows explicit control over the causal_fix flag passed to latent_to_pixel_coords. Defaults to frame_idx == 0 when not specified, fixing the previous heuristic.
1 parent 17b43c2 commit 58017e8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

comfy_extras/nodes_lt.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ def get_latent_index(cls, cond, latent_length, guide_length, frame_idx, scale_fa
253253
return frame_idx, latent_idx
254254

255255
@classmethod
256-
def add_keyframe_index(cls, cond, frame_idx, guiding_latent, scale_factors, latent_downscale_factor=1):
256+
def add_keyframe_index(cls, cond, frame_idx, guiding_latent, scale_factors, latent_downscale_factor=1, causal_fix=None):
257257
keyframe_idxs, _ = get_keyframe_idxs(cond)
258258
_, latent_coords = cls.PATCHIFIER.patchify(guiding_latent)
259-
pixel_coords = latent_to_pixel_coords(latent_coords, scale_factors, causal_fix=frame_idx == 0) # we need the causal fix only if we're placing the new latents at index 0
259+
if causal_fix is None:
260+
causal_fix = frame_idx == 0 or guiding_latent.shape[2] == 1
261+
pixel_coords = latent_to_pixel_coords(latent_coords, scale_factors, causal_fix=causal_fix)
260262
pixel_coords[:, 0] += frame_idx
261263

262264
# The following adjusts keyframe end positions for small grid IC-LoRA.
@@ -278,12 +280,12 @@ def add_keyframe_index(cls, cond, frame_idx, guiding_latent, scale_factors, late
278280
return node_helpers.conditioning_set_values(cond, {"keyframe_idxs": keyframe_idxs})
279281

280282
@classmethod
281-
def append_keyframe(cls, positive, negative, frame_idx, latent_image, noise_mask, guiding_latent, strength, scale_factors, guide_mask=None, in_channels=128, latent_downscale_factor=1):
283+
def append_keyframe(cls, positive, negative, frame_idx, latent_image, noise_mask, guiding_latent, strength, scale_factors, guide_mask=None, in_channels=128, latent_downscale_factor=1, causal_fix=None):
282284
if latent_image.shape[1] != in_channels or guiding_latent.shape[1] != in_channels:
283285
raise ValueError("Adding guide to a combined AV latent is not supported.")
284286

285-
positive = cls.add_keyframe_index(positive, frame_idx, guiding_latent, scale_factors, latent_downscale_factor)
286-
negative = cls.add_keyframe_index(negative, frame_idx, guiding_latent, scale_factors, latent_downscale_factor)
287+
positive = cls.add_keyframe_index(positive, frame_idx, guiding_latent, scale_factors, latent_downscale_factor, causal_fix=causal_fix)
288+
negative = cls.add_keyframe_index(negative, frame_idx, guiding_latent, scale_factors, latent_downscale_factor, causal_fix=causal_fix)
287289

288290
if guide_mask is not None:
289291
target_h = max(noise_mask.shape[3], guide_mask.shape[3])

0 commit comments

Comments
 (0)