Comfy-Org/ComfyUI · error · ValueError

Number of latents ({len(latents)}) does not match number of

Error message

Number of latents ({len(latents)}) does not match number of conditions ({len(conditioning)}).

What it means

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.

Source

Thrown at comfy_extras/nodes_dataset.py:1792

                    is_output_list=True,
                    tooltip="List of batched latent dicts, one per resolution bucket.",
                ),
                io.Conditioning.Output(
                    display_name="conditioning",
                    is_output_list=True,
                    tooltip="List of condition lists, one per resolution bucket.",
                ),
            ],
        )

    @classmethod
    def execute(cls, latents, conditioning):
        # latents: list[{"samples": tensor}] where tensor is (B, C, H, W), typically B=1
        # conditioning: list[list[cond]]

        # Validate lengths match
        if len(latents) != len(conditioning):
            raise ValueError(
                f"Number of latents ({len(latents)}) does not match number of conditions ({len(conditioning)})."
            )

        # Flatten latents and conditions to individual samples
        flat_latents = []  # list of (C, H, W) tensors
        flat_conditions = []  # list of condition lists

        for latent_dict, cond in zip(latents, conditioning):
            samples = latent_dict["samples"]  # (B, C, H, W)
            batch_size = samples.shape[0]

            # cond is a list of conditions with length == batch_size
            for i in range(batch_size):
                flat_latents.append(samples[i])  # (C, H, W)
                flat_conditions.append(cond[i])  # single condition

        # Group by resolution (H, W)
        buckets = {}  # (H, W) -> {"latents": list, "conditions": list}

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Count both inputs: add a debug/inspect node (or print in a wrapper) and confirm len(latents) == len(conditioning).
  2. Regenerate the conditioning side with the same loader/bucket settings used for the latents.
  3. Re-run the whole dataset-preparation chain from the same source images so both lists come from one pass.
Defensive patterns

Strategy: validation

Validate before calling

assert len(latents) == len(conditioning), (
    f'latents={len(latents)} vs conditioning={len(conditioning)}; regenerate both from the same dataset pass')

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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