Comfy-Org/ComfyUI · critical · ValueError

Input txt tensors must have 3 dimensions.

Error message

Input txt tensors must have 3 dimensions.

What it means

ChromaRadiance._forward requires the text context tensor to be 3-D ([B, seq_txt, dim]) so it can build matching txt_ids of shape [bs, seq_txt, 3] and run sequential/radiance text position ids. A 2-D unbatched embedding or a 4-D tensor raises immediately. This is the radiance twin of Chroma's combined img/txt check at chroma/model.py:284, split here into two separate errors.

Source

Thrown at comfy/ldm/chroma_radiance/model.py:309

        return (noisy - predicted) / (timesteps.view(-1,1,1,1) + eps)

    def _forward(
        self,
        x: Tensor,
        timestep: Tensor,
        context: Tensor,
        guidance: Optional[Tensor],
        control: Optional[dict]=None,
        transformer_options: dict={},
        **kwargs: dict,
    ) -> Tensor:
        bs, c, h, w = x.shape
        img = comfy.ldm.common_dit.pad_to_patch_size(x, (self.patch_size, self.patch_size))

        if img.ndim != 4:
            raise ValueError("Input img tensor must be in [B, C, H, W] format.")
        if context.ndim != 3:
            raise ValueError("Input txt tensors must have 3 dimensions.")

        params = self.radiance_get_override_params(transformer_options.get("chroma_radiance_options", {}))

        h_len = (img.shape[-2] // self.patch_size)
        w_len = (img.shape[-1] // self.patch_size)

        img_ids = torch.zeros((h_len, w_len, 3), device=x.device, dtype=x.dtype)
        img_ids[:, :, 1] = img_ids[:, :, 1] + torch.linspace(0, h_len - 1, steps=h_len, device=x.device, dtype=x.dtype).unsqueeze(1)
        img_ids[:, :, 2] = img_ids[:, :, 2] + torch.linspace(0, w_len - 1, steps=w_len, device=x.device, dtype=x.dtype).unsqueeze(0)
        img_ids = repeat(img_ids, "h w c -> b (h w) c", b=bs)
        txt_ids = torch.zeros((bs, context.shape[1], 3), device=x.device, dtype=x.dtype)
        # Radiance after 2026-05-22 uses sequential txt_ids instead of zeros
        if params.use_sequential_txt_ids:
            txt_ids[:, :, 0] = torch.arange(context.shape[1], device=x.device, dtype=x.dtype).unsqueeze(0).expand(bs, -1)

        img_out = self.forward_orig(
            img,
            img_ids,

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Stack/batch the context to [B, S, D]: context = context.unsqueeze(0) for a single prompt
  2. torch.stack per-sample embeddings along dim 0 when each view has its own caption
  3. Let the standard ComfyUI conditioning path produce the context tensor

Example fix

# before
context = encode_text(prompt)  # [S, D]
out = model(x, t, context=context)

# after
context = encode_text(prompt).unsqueeze(0)  # [1, S, D]
out = model(x, t, context=context)
Defensive patterns

Strategy: validation

Validate before calling

if context.ndim == 2:
    context = context.unsqueeze(0)
if context.ndim == 4:  # accidental image-shaped conditioning
    raise ValueError("context must be [B, S, D] text embeddings")

Type guard

def is_bsd(t) -> bool:
    return isinstance(t, torch.Tensor) and t.ndim == 3

Prevention

When it happens

Trigger: Calling _forward with context of shape [seq, dim] (single unbatched text embedding) or with a list of per-sample embeddings instead of a stacked tensor; txt_ids construction on the next lines indexes context.shape[1], so the check fires first.

Common situations: Custom conditioning pipelines that keep per-prompt embeddings separate; using Qwen/CLIP encode outputs directly without batching; radiance workflows where each view gets its own caption tensor.

Related errors


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