{"record":{"id":"cc998910df843d30","repo":"Comfy-Org/ComfyUI","slug":"input-txt-tensors-must-have-3-dimensions","errorCode":null,"errorMessage":"Input txt tensors must have 3 dimensions.","messagePattern":"Input txt tensors must have 3 dimensions\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"comfy/ldm/chroma_radiance/model.py","lineNumber":309,"sourceCode":"        return (noisy - predicted) / (timesteps.view(-1,1,1,1) + eps)\n\n    def _forward(\n        self,\n        x: Tensor,\n        timestep: Tensor,\n        context: Tensor,\n        guidance: Optional[Tensor],\n        control: Optional[dict]=None,\n        transformer_options: dict={},\n        **kwargs: dict,\n    ) -> Tensor:\n        bs, c, h, w = x.shape\n        img = comfy.ldm.common_dit.pad_to_patch_size(x, (self.patch_size, self.patch_size))\n\n        if img.ndim != 4:\n            raise ValueError(\"Input img tensor must be in [B, C, H, W] format.\")\n        if context.ndim != 3:\n            raise ValueError(\"Input txt tensors must have 3 dimensions.\")\n\n        params = self.radiance_get_override_params(transformer_options.get(\"chroma_radiance_options\", {}))\n\n        h_len = (img.shape[-2] // self.patch_size)\n        w_len = (img.shape[-1] // self.patch_size)\n\n        img_ids = torch.zeros((h_len, w_len, 3), device=x.device, dtype=x.dtype)\n        img_ids[:, :, 1] = img_ids[:, :, 1] + torch.linspace(0, h_len - 1, steps=h_len, device=x.device, dtype=x.dtype).unsqueeze(1)\n        img_ids[:, :, 2] = img_ids[:, :, 2] + torch.linspace(0, w_len - 1, steps=w_len, device=x.device, dtype=x.dtype).unsqueeze(0)\n        img_ids = repeat(img_ids, \"h w c -> b (h w) c\", b=bs)\n        txt_ids = torch.zeros((bs, context.shape[1], 3), device=x.device, dtype=x.dtype)\n        # Radiance after 2026-05-22 uses sequential txt_ids instead of zeros\n        if params.use_sequential_txt_ids:\n            txt_ids[:, :, 0] = torch.arange(context.shape[1], device=x.device, dtype=x.dtype).unsqueeze(0).expand(bs, -1)\n\n        img_out = self.forward_orig(\n            img,\n            img_ids,","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/chroma_radiance/model.py#L291-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Stack/batch the context to [B, S, D]: context = context.unsqueeze(0) for a single prompt","torch.stack per-sample embeddings along dim 0 when each view has its own caption","Let the standard ComfyUI conditioning path produce the context tensor"],"exampleFix":"# before\ncontext = encode_text(prompt)  # [S, D]\nout = model(x, t, context=context)\n\n# after\ncontext = encode_text(prompt).unsqueeze(0)  # [1, S, D]\nout = model(x, t, context=context)","handlingStrategy":"validation","validationCode":"if context.ndim == 2:\n    context = context.unsqueeze(0)\nif context.ndim == 4:  # accidental image-shaped conditioning\n    raise ValueError(\"context must be [B, S, D] text embeddings\")","typeGuard":"def is_bsd(t) -> bool:\n    return isinstance(t, torch.Tensor) and t.ndim == 3","tryCatchPattern":null,"preventionTips":["Batch text embeddings with torch.stack/unsqueeze before forward","Keep one caption tensor per batch, not per-view lists, unless stacking"],"tags":["chroma-radiance","conditioning","tensor-shape","forward"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}