Skip to content

Fix: clone latent samples in LTXVImgToVideoConditionOnly to prevent in-place mutation across list/batch execution - #552

Open
kb999-coder wants to merge 1 commit into
Lightricks:masterfrom
kb999-coder:fix-imgtovideo-inplace-mutation
Open

Fix: clone latent samples in LTXVImgToVideoConditionOnly to prevent in-place mutation across list/batch execution#552
kb999-coder wants to merge 1 commit into
Lightricks:masterfrom
kb999-coder:fix-imgtovideo-inplace-mutation

Conversation

@kb999-coder

@kb999-coder kb999-coder commented Aug 22, 2026

Copy link
Copy Markdown

Bug: In-place mutation of shared latent tensor breaks batch/list execution

Description

LTXVImgToVideoConditionOnly.generate() mutates the input latent tensor in place instead of cloning it first:

samples = latent["samples"]                    # reference, not a copy
samples[:, :, : t.shape[2]] = t                 # in-place write

When this node is used inside a ComfyUI list-based batch workflow (e.g. generating one video per image from a folder via Image Batch to Image List), the latent input typically comes from EmptyLTXVLatentVideo. Since that node's inputs (width, height, length, batch_size) are fixed values — not part of the list — ComfyUI executes it only once and caches its output. The same tensor object is then reused across every iteration of the list.

Because LTXVImgToVideoConditionOnly writes into this shared tensor instead of a copy, each iteration overwrites the data written by the previous one. The net effect: every generated video ends up conditioned on the last image in the batch, regardless of which image was actually passed to that iteration — even though upstream nodes (image loading, preprocessing, sampler) all execute correctly and independently per list item.

How to reproduce

  1. Build a batch/list I2V workflow: Load Images (Path)Image Batch to Image List → (resize/preprocess) → LTXV Img To Video Condition Only → sampler → VAE decode → Save Video, with latent fed by a single EmptyLTXVLatentVideo node.
  2. Put 2+ different images in the input folder.
  3. Queue the prompt. The sampler correctly runs once per image, and distinct output video files are created.
  4. Compare the first frame of each output video: they are all identical, matching the last image in the folder — not the image that was supposed to condition that particular run.

Fix

Clone the tensor before writing to it:

samples = latent["samples"].clone()

This is a minimal, side-effect-free change: it only adds a copy before the in-place write, with no impact on single-image (non-list) usage, and negligible performance cost.

Testing

Verified locally: after applying .clone(), running the same batch workflow with 2–3 images now produces distinct output videos, each correctly conditioned on its corresponding source image.

Generated with Claude

…n-place mutation of cached tensor across list iterations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant