| 399 | |
| 400 | @comfy_node(name="LTXVAddLatentGuide") |
| 401 | class LTXVAddLatentGuide: |
| 402 | @classmethod |
| 403 | def INPUT_TYPES(s): |
| 404 | return { |
| 405 | "required": { |
| 406 | "vae": ("VAE",), |
| 407 | "positive": ("CONDITIONING",), |
| 408 | "negative": ("CONDITIONING",), |
| 409 | "latent": ("LATENT",), |
| 410 | "guiding_latent": ("LATENT",), |
| 411 | "latent_idx": ( |
| 412 | "INT", |
| 413 | { |
| 414 | "default": 0, |
| 415 | "min": -9999, |
| 416 | "max": 9999, |
| 417 | "step": 1, |
| 418 | "tooltip": "Latent index to start the conditioning at. Can be negative to" |
| 419 | "indicate that the conditioning is on the frames before the latent.", |
| 420 | }, |
| 421 | ), |
| 422 | "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0}), |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | RETURN_TYPES = ("CONDITIONING", "CONDITIONING", "LATENT") |
| 427 | RETURN_NAMES = ("positive", "negative", "latent") |
| 428 | |
| 429 | CATEGORY = "ltxtricks" |
| 430 | FUNCTION = "generate" |
| 431 | |
| 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 |