Compare commits

...

3 Commits

Author SHA1 Message Date
Dustin
6ef92f9d90
Merge 0388ac4309 into 65045730a6 2026-05-08 16:24:59 -04:00
Dustin
0388ac4309
Defensively truncate/pad nested noise components to match latent
When noise.is_nested with a different number of components than
latent_image, truncate extras or pad missing components with
torch.zeros_like, mirroring the denoise_mask handling pattern below.

Addresses CodeRabbit nitpick on #13318.
2026-05-03 23:52:08 -04:00
Dustin
2beca418ad
Fix noise/latent tensor mismatch when latent is nested but noise is not
When using LTXAV (audio+video) workflows, latent_image is a NestedTensor
but noise may be a regular tensor. Calling unbind() on non-nested noise
splits along dim=0 (channels), producing a shape mismatch at noise_scaling.

Check whether noise is nested before unbinding. If not, pad with zero-noise
for additional components (e.g. audio), which is semantically correct since
those components don't need denoising in the video sampler.
2026-04-07 06:07:26 -04:00

View File

@ -1006,8 +1006,19 @@ class CFGGuider:
return latent_image
if latent_image.is_nested:
latent_image, latent_shapes = comfy.utils.pack_latents(latent_image.unbind())
noise, _ = comfy.utils.pack_latents(noise.unbind())
li_tensors = latent_image.unbind()
if noise.is_nested:
# Truncate extra noise components, pad missing ones with zeros
n_tensors = list(noise.unbind()[:len(li_tensors)])
for i in range(len(n_tensors), len(li_tensors)):
n_tensors.append(torch.zeros_like(li_tensors[i]))
else:
# Noise only covers video -- pad remaining components (audio) with zeros
n_tensors = [noise]
for i in range(1, len(li_tensors)):
n_tensors.append(torch.zeros_like(li_tensors[i]))
latent_image, latent_shapes = comfy.utils.pack_latents(li_tensors)
noise, _ = comfy.utils.pack_latents(n_tensors)
else:
latent_shapes = [latent_image.shape]