{"record":{"id":"5540308c959ed804","repo":"Comfy-Org/ComfyUI","slug":"number-of-latents-len-latents-does-not-match","errorCode":null,"errorMessage":"Number of latents ({len(latents)}) does not match number of conditions ({len(conditioning)}).","messagePattern":"Number of latents \\((.+?)\\) does not match number of conditions \\((.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_dataset.py","lineNumber":1792,"sourceCode":"                    is_output_list=True,\n                    tooltip=\"List of batched latent dicts, one per resolution bucket.\",\n                ),\n                io.Conditioning.Output(\n                    display_name=\"conditioning\",\n                    is_output_list=True,\n                    tooltip=\"List of condition lists, one per resolution bucket.\",\n                ),\n            ],\n        )\n\n    @classmethod\n    def execute(cls, latents, conditioning):\n        # latents: list[{\"samples\": tensor}] where tensor is (B, C, H, W), typically B=1\n        # conditioning: list[list[cond]]\n\n        # Validate lengths match\n        if len(latents) != len(conditioning):\n            raise ValueError(\n                f\"Number of latents ({len(latents)}) does not match number of conditions ({len(conditioning)}).\"\n            )\n\n        # Flatten latents and conditions to individual samples\n        flat_latents = []  # list of (C, H, W) tensors\n        flat_conditions = []  # list of condition lists\n\n        for latent_dict, cond in zip(latents, conditioning):\n            samples = latent_dict[\"samples\"]  # (B, C, H, W)\n            batch_size = samples.shape[0]\n\n            # cond is a list of conditions with length == batch_size\n            for i in range(batch_size):\n                flat_latents.append(samples[i])  # (C, H, W)\n                flat_conditions.append(cond[i])  # single condition\n\n        # Group by resolution (H, W)\n        buckets = {}  # (H, W) -> {\"latents\": list, \"conditions\": list}","sourceCodeStart":1774,"sourceCodeEnd":1810,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_dataset.py#L1774-L1810","documentation":"Thrown by the bucketed-training packing node when the list of latent dicts and the list of per-sample condition lists have different lengths. The node zips the two lists one-to-one after this check, so a length mismatch means the dataset is internally inconsistent and training data would be silently misaligned.","triggerScenarios":"Wiring a LatentBatch/list of N latents into 'latents' and M != N condition lists (from e.g. TextEncode per bucket) into 'conditioning'. Typical cause: one bucket produced latents but its conditioning branch was not generated, or conditioning was built for a different number of resolution buckets.","commonSituations":"Multi-resolution (bucketed) dataset preparation where images were added/removed but conditioning was not regenerated; mixing outputs of two different dataset-prep runs; miscounting buckets in a hand-built workflow.","solutions":["Count both inputs: add a debug/inspect node (or print in a wrapper) and confirm len(latents) == len(conditioning).","Regenerate the conditioning side with the same loader/bucket settings used for the latents.","Re-run the whole dataset-preparation chain from the same source images so both lists come from one pass."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert len(latents) == len(conditioning), (\n    f'latents={len(latents)} vs conditioning={len(conditioning)}; regenerate both from the same dataset pass')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Produce latents and conditioning in one workflow pass over the same bucketed image list.","Treat a length mismatch as an upstream data bug: fix the dataset, do not try/catch past it.","Add an inspect node that prints both list lengths before packing."],"tags":["comfyui","training","shape-mismatch","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}