(
self, vae, positive, negative, latent, guiding_latent, latent_idx, strength
)
| 432 | DESCRIPTION = "Adds a keyframe or a video segment at a specific frame index." |
| 433 | |
| 434 | def generate( |
| 435 | self, vae, positive, negative, latent, guiding_latent, latent_idx, strength |
| 436 | ): |
| 437 | noise_mask = nodes_lt.get_noise_mask(latent) |
| 438 | latent = latent["samples"] |
| 439 | guide = guiding_latent["samples"] |
| 440 | |
| 441 | # Record original (pre-dilation) guide latent shape for spatial mask downsampling |
| 442 | guide_orig_shape = list(guide.shape[2:]) # [F, H_small, W_small] |
| 443 | |
| 444 | assert ( |
| 445 | latent.shape[4] % guide.shape[4] == 0 |
| 446 | and latent.shape[3] % guide.shape[3] == 0 |
| 447 | ), "The ratio of the height and width of the latents and optional_guiding_latents must be an integer" |
| 448 | |
| 449 | guiding_latent = LTXVDilateLatent().dilate_latent( |
| 450 | guiding_latent, |
| 451 | horizontal_scale=latent.shape[4] // guide.shape[4], |
| 452 | vertical_scale=latent.shape[3] // guide.shape[3], |
| 453 | )[0] |
| 454 | |
| 455 | guide = guiding_latent["samples"] |
| 456 | guide_mask = guiding_latent.get("noise_mask", None) |
| 457 | |
| 458 | # Pre-filter token count = product of dilated spatial dims |
| 459 | # (before grid_mask filtering removes padding positions) |
| 460 | iclora_tokens_added = guide.shape[2] * guide.shape[3] * guide.shape[4] |
| 461 | |
| 462 | scale_factors = vae.downscale_index_formula |
| 463 | |
| 464 | if latent_idx <= 0: |
| 465 | frame_idx = latent_idx * scale_factors[0] |
| 466 | else: |
| 467 | frame_idx = 1 + (latent_idx - 1) * scale_factors[0] |
| 468 | |
| 469 | positive, negative, latent, noise_mask = nodes_lt.LTXVAddGuide.append_keyframe( |
| 470 | positive=positive, |
| 471 | negative=negative, |
| 472 | frame_idx=frame_idx, |
| 473 | latent_image=latent, |
| 474 | noise_mask=noise_mask, |
| 475 | guiding_latent=guide, |
| 476 | strength=strength, |
| 477 | scale_factors=scale_factors, |
| 478 | guide_mask=guide_mask, |
| 479 | ) |
| 480 | |
| 481 | # Track this guide in guide_attention_entries for per-reference attention control. |
| 482 | from .iclora_attention import append_guide_attention_entry |
| 483 | |
| 484 | positive = append_guide_attention_entry( |
| 485 | positive, iclora_tokens_added, guide_orig_shape |
| 486 | ) |
| 487 | negative = append_guide_attention_entry( |
| 488 | negative, iclora_tokens_added, guide_orig_shape |
| 489 | ) |
| 490 | |
| 491 | return ( |
no test coverage detected