Comfy-Org/ComfyUI · error · ValueError
SeedVR2 expected an even text-conditioning batch, got shape
Error message
SeedVR2 expected an even text-conditioning batch, got shape {tuple(context.shape)} What it means
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.
Source
Thrown at comfy/ldm/seedvr/model.py:1246
self.vid_out_ada = ada(
dim=vid_dim,
emb_dim=emb_dim,
layers=["out"],
modes=["in"],
device=device, dtype=dtype
)
def _resolve_text_conditioning(self, context, cond_or_uncond=None):
if context is None or context.numel() == 0:
context = self.positive_conditioning
return flatten([context])
if NaDiT._seedvr2_is_single_conditioning_branch(cond_or_uncond):
if context.shape[0] == 1:
context = context.squeeze(0)
return flatten([context])
return flatten(context.unbind(0))
if context.shape[0] % 2 != 0:
raise ValueError(f"SeedVR2 expected an even text-conditioning batch, got shape {tuple(context.shape)}")
neg_cond, pos_cond = context.chunk(2, dim=0)
if pos_cond.shape[0] == 1:
pos_cond, neg_cond = pos_cond.squeeze(0), neg_cond.squeeze(0)
return flatten([pos_cond, neg_cond])
return flatten((*pos_cond.unbind(0), *neg_cond.unbind(0)))
@staticmethod
def _seedvr2_is_single_conditioning_branch(cond_or_uncond):
if cond_or_uncond is None or len(cond_or_uncond) == 0:
return False
first = cond_or_uncond[0]
return all(entry == first for entry in cond_or_uncond)
@staticmethod
def _check_seedvr2_video_latent(x, channels, name):
if x.ndim != 5:
raise ValueError(f"SeedVR2 expected {name} to be 5-D native latent, got shape {tuple(x.shape)}.")
if x.shape[1] != channels:View on GitHub (pinned to 1c6d8d45b3)
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.
Example fix
# before context = torch.cat([pos_a, pos_b, neg_a], 0) # odd batch, mixed # after context = torch.cat([pos_a, pos_b, neg_a, neg_b], 0) # even batch
Defensive patterns
Strategy: validation
Validate before calling
def validate_seedvr2_context(context, cond_or_uncond):
single = cond_or_uncond is not None and len(set(cond_or_uncond)) == 1
if not single and context.shape[0] % 2 != 0:
raise ValueError(f"mixed cond/uncond batch must be even, got {context.shape[0]}")
return context Type guard
def is_single_branch(cond_or_uncond) -> bool:
return cond_or_uncond is not None and len(cond_or_uncond) > 0 and len(set(cond_or_uncond)) == 1 Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SeedVR2 expected {name} channels to be {channels}, got shape
- SeedVR2 requires conditioning latents from the SeedVR2Condit
- SeedVR2 conditioning shape must match latent batch/temporal/
- Need at least {require_count} hooks to combine, but only had
- PixDiT_T2I requires context (text embeddings) of shape [B, L
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/b77250b76034f841.
Report an issue: GitHub.