{"record":{"id":"da9e03d6d1f1a60b","repo":"Comfy-Org/ComfyUI","slug":"audio-latent-cannot-be-fitted-to","errorCode":null,"errorMessage":"audio latent {} cannot be fitted to {}","messagePattern":"audio latent (.+?) cannot be fitted to (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_lt.py","lineNumber":775,"sourceCode":"                io.Latent.Input(\"audio_latent\"),\n            ],\n            outputs=[\n                io.Latent.Output(display_name=\"latent\"),\n            ],\n        )\n\n    @staticmethod\n    def fit_audio(reference, audio, noise_mask):\n        \"\"\"Trim or zero-pad the audio stream to the length of the one it replaces.\n\n        The padded tail is left unmasked so the model generates it, which is what a\n        clip shorter than the video should do.\n        \"\"\"\n        dims = [i for i in range(reference.ndim) if reference.shape[i] != audio.shape[i]]\n        if len(dims) == 0:\n            return audio, noise_mask\n        if len(dims) > 1 or dims[0] < 2:\n            raise ValueError(\"audio latent {} cannot be fitted to {}\".format(tuple(audio.shape), tuple(reference.shape)))\n\n        dim, length = dims[0], reference.shape[dims[0]]\n        if noise_mask is not None:  # masks carry their own shape until sampling resizes them\n            noise_mask = comfy.utils.reshape_mask(noise_mask, audio.shape)\n\n        if audio.shape[dim] > length:\n            audio = audio.narrow(dim, 0, length)\n            if noise_mask is not None:\n                noise_mask = noise_mask.narrow(dim, 0, length)\n        else:\n            pad = torch.zeros_like(audio.narrow(dim, 0, 1)).repeat(\n                [length - audio.shape[dim] if i == dim else 1 for i in range(audio.ndim)])\n            audio = torch.cat([audio, pad], dim=dim)\n            if noise_mask is not None:\n                noise_mask = torch.cat([noise_mask, torch.ones_like(pad)], dim=dim)\n        return audio, noise_mask\n\n    @classmethod","sourceCodeStart":757,"sourceCodeEnd":793,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_lt.py#L757-L793","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Match batch sizes: audio latent batch must equal the video latent batch.","If re-using a stored reference latent, re-encode it with the current VAE."],"exampleFix":"# before\nref = old_vae.encode_audio(ref_audio)   # channels differ from new VAE\nfit_audio(ref, new_audio_latent, mask)   # raises\n\n# after\nref = new_vae.encode_audio(ref_audio)    # same VAE as audio latent","handlingStrategy":"validation","validationCode":"diff = [i for i in range(reference.ndim) if reference.shape[i] != audio.shape[i]]\nassert len(diff) <= 1 and (not diff or diff[0] >= 2), (\n    f\"audio latent {tuple(audio.shape)} incompatible with reference {tuple(reference.shape)}; \"\n    \"only the time axis may differ\")","typeGuard":"def audio_fits(reference, audio) -> bool:\n    return all(a == r or i >= 2 for i, (a, r) in enumerate(zip(audio.shape, reference.shape)))","tryCatchPattern":"try:\n    audio, mask = fit_audio(reference, audio, noise_mask)\nexcept ValueError as e:\n    if \"cannot be fitted\" in str(e):\n        raise ValueError(\"Re-encode audio with the same VAE/batch as the video latent\") from e\n    raise","preventionTips":["Always encode reference and replacement audio with the same VAE and version.","Match batch sizes between audio and video latents.","Validate shapes differ only along the time axis before calling fit."],"tags":["ltx","audio","latent","shape","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}