Comfy-Org/ComfyUI · error · ValueError

audio latent {} cannot be fitted to {}

Error message

audio latent {} cannot be fitted to {}

What it means

Raised by LTX audio fit_audio(): it can trim or zero-pad the audio latent along exactly one dimension (the time axis) to match a reference. If the two latents differ in zero dimensions nothing happens (early return), but if they differ in more than one dimension, or only in batch/channel dims (dim index < 2), the shapes are incompatible and fitting is refused rather than silently corrupting the audio.

Source

Thrown at comfy_extras/nodes_lt.py:775

                io.Latent.Input("audio_latent"),
            ],
            outputs=[
                io.Latent.Output(display_name="latent"),
            ],
        )

    @staticmethod
    def fit_audio(reference, audio, noise_mask):
        """Trim or zero-pad the audio stream to the length of the one it replaces.

        The padded tail is left unmasked so the model generates it, which is what a
        clip shorter than the video should do.
        """
        dims = [i for i in range(reference.ndim) if reference.shape[i] != audio.shape[i]]
        if len(dims) == 0:
            return audio, noise_mask
        if len(dims) > 1 or dims[0] < 2:
            raise ValueError("audio latent {} cannot be fitted to {}".format(tuple(audio.shape), tuple(reference.shape)))

        dim, length = dims[0], reference.shape[dims[0]]
        if noise_mask is not None:  # masks carry their own shape until sampling resizes them
            noise_mask = comfy.utils.reshape_mask(noise_mask, audio.shape)

        if audio.shape[dim] > length:
            audio = audio.narrow(dim, 0, length)
            if noise_mask is not None:
                noise_mask = noise_mask.narrow(dim, 0, length)
        else:
            pad = torch.zeros_like(audio.narrow(dim, 0, 1)).repeat(
                [length - audio.shape[dim] if i == dim else 1 for i in range(audio.ndim)])
            audio = torch.cat([audio, pad], dim=dim)
            if noise_mask is not None:
                noise_mask = torch.cat([noise_mask, torch.ones_like(pad)], dim=dim)
        return audio, noise_mask

    @classmethod

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Encode audio with the same VAE and settings used for the reference so batch, channel and feature dims match, leaving only the time axis different.
  2. Match batch sizes: audio latent batch must equal the video latent batch.
  3. If re-using a stored reference latent, re-encode it with the current VAE.

Example fix

# before
ref = old_vae.encode_audio(ref_audio)   # channels differ from new VAE
fit_audio(ref, new_audio_latent, mask)   # raises

# after
ref = new_vae.encode_audio(ref_audio)    # same VAE as audio latent
Defensive patterns

Strategy: validation

Validate before calling

diff = [i for i in range(reference.ndim) if reference.shape[i] != audio.shape[i]]
assert len(diff) <= 1 and (not diff or diff[0] >= 2), (
    f"audio latent {tuple(audio.shape)} incompatible with reference {tuple(reference.shape)}; "
    "only the time axis may differ")

Type guard

def audio_fits(reference, audio) -> bool:
    return all(a == r or i >= 2 for i, (a, r) in enumerate(zip(audio.shape, reference.shape)))

Try / catch

try:
    audio, mask = fit_audio(reference, audio, noise_mask)
except ValueError as e:
    if "cannot be fitted" in str(e):
        raise ValueError("Re-encode audio with the same VAE/batch as the video latent") from e
    raise

Prevention

When it happens

Trigger: Replacing audio in a video latent whose channel count differs (audio encoded with a different VAE or version, channels mismatch); batch sizes differing between audio and video latents; latents from different-resolution encodes passed as reference/audio.

Common situations: LTX A/V workflows where the audio VAE latent layout changed between model versions; feeding an audio latent batch of 2 into a video latent batch of 1.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/da9e03d6d1f1a60b. Report an issue: GitHub.