{"record":{"id":"b77250b76034f841","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-expected-an-even-text-conditioning-batch","errorCode":null,"errorMessage":"SeedVR2 expected an even text-conditioning batch, got shape {tuple(context.shape)}","messagePattern":"SeedVR2 expected an even text-conditioning batch, got shape (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/model.py","lineNumber":1246,"sourceCode":"            self.vid_out_ada = ada(\n                dim=vid_dim,\n                emb_dim=emb_dim,\n                layers=[\"out\"],\n                modes=[\"in\"],\n                device=device, dtype=dtype\n            )\n\n    def _resolve_text_conditioning(self, context, cond_or_uncond=None):\n        if context is None or context.numel() == 0:\n            context = self.positive_conditioning\n            return flatten([context])\n        if NaDiT._seedvr2_is_single_conditioning_branch(cond_or_uncond):\n            if context.shape[0] == 1:\n                context = context.squeeze(0)\n                return flatten([context])\n            return flatten(context.unbind(0))\n        if context.shape[0] % 2 != 0:\n            raise ValueError(f\"SeedVR2 expected an even text-conditioning batch, got shape {tuple(context.shape)}\")\n        neg_cond, pos_cond = context.chunk(2, dim=0)\n        if pos_cond.shape[0] == 1:\n            pos_cond, neg_cond = pos_cond.squeeze(0), neg_cond.squeeze(0)\n            return flatten([pos_cond, neg_cond])\n        return flatten((*pos_cond.unbind(0), *neg_cond.unbind(0)))\n\n    @staticmethod\n    def _seedvr2_is_single_conditioning_branch(cond_or_uncond):\n        if cond_or_uncond is None or len(cond_or_uncond) == 0:\n            return False\n        first = cond_or_uncond[0]\n        return all(entry == first for entry in cond_or_uncond)\n\n    @staticmethod\n    def _check_seedvr2_video_latent(x, channels, name):\n        if x.ndim != 5:\n            raise ValueError(f\"SeedVR2 expected {name} to be 5-D native latent, got shape {tuple(x.shape)}.\")\n        if x.shape[1] != channels:","sourceCodeStart":1228,"sourceCodeEnd":1264,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/model.py#L1228-L1264","documentation":"SeedVR2 packs positive and negative text conditioning into a single flattened stream by chunking the context batch in half (neg/pos). When cond_or_uncond indicates a mixed batch, the leading batch dimension must be even; an odd batch raises this ValueError. Single-branch batches (all cond or all uncond) are exempt via _seedvr2_is_single_conditioning_branch.","triggerScenarios":"Calling NaDiT forward with a context tensor whose shape[0] is odd while transformer_options['cond_or_uncond'] contains mixed entries (e.g. [0,1]); custom samplers that concatenate cond/uncond embeddings asymmetrically; a batch of 3 where 2 are cond and 1 is uncond.","commonSituations":"Custom sampling loops that build conditioning batches by hand; a node that duplicates one conditioning but not its negative counterpart; partial batching where the last batch has an odd count but cond_or_uncond was not marked single-branch.","solutions":["Ensure cond and uncond counts are equal so context.shape[0] is even in mixed batches.","When running a single branch only, pass the correct cond_or_uncond (all zeros or all ones) so the single-branch fast path applies.","Batch symmetrically: for each positive embedding include its negative counterpart before calling forward.","In custom samplers, mirror ComfyUI's calc_cond_batch ordering and cond_or_uncond flags."],"exampleFix":"# before\ncontext = torch.cat([pos_a, pos_b, neg_a], 0)  # odd batch, mixed\n# after\ncontext = torch.cat([pos_a, pos_b, neg_a, neg_b], 0)  # even batch","handlingStrategy":"validation","validationCode":"def validate_seedvr2_context(context, cond_or_uncond):\n    single = cond_or_uncond is not None and len(set(cond_or_uncond)) == 1\n    if not single and context.shape[0] % 2 != 0:\n        raise ValueError(f\"mixed cond/uncond batch must be even, got {context.shape[0]}\")\n    return context","typeGuard":"def is_single_branch(cond_or_uncond) -> bool:\n    return cond_or_uncond is not None and len(cond_or_uncond) > 0 and len(set(cond_or_uncond)) == 1","tryCatchPattern":null,"preventionTips":["Always batch cond and uncond embeddings in equal counts.","Pass accurate cond_or_uncond flags in transformer_options for single-branch runs.","Mirror ComfyUI's calc_cond_batch ordering in custom samplers."],"tags":["seedvr2","conditioning","batching","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}