{"record":{"id":"4ebf4cee0b29d07a","repo":"Comfy-Org/ComfyUI","slug":"pixdit-t2i-requires-context-text-embeddings-of-s","errorCode":null,"errorMessage":"PixDiT_T2I requires context (text embeddings) of shape [B, L, D]","messagePattern":"PixDiT_T2I requires context \\(text embeddings\\) of shape \\[B, L, D\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/pixeldit/model.py","lineNumber":217,"sourceCode":"\n    def _pre_pixel_blocks(self, s, **kwargs):\n        return s\n\n    def _forward(self, x, timesteps, context=None, attention_mask=None, transformer_options={}, **kwargs):\n        H_orig, W_orig = x.shape[2], x.shape[3]\n        x = comfy.ldm.common_dit.pad_to_patch_size(x, (self.patch_size, self.patch_size))\n        B, _, H, W = x.shape\n        Hs = H // self.patch_size\n        Ws = W // self.patch_size\n        L = Hs * Ws\n\n        pos_img = self._fetch_patch_pos(Hs, Ws, x.device, x.dtype, **(transformer_options.get(\"rope_options\") or {}))\n        x_patches = F.unfold(x, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)\n\n        t_emb = self.t_embedder(timesteps.view(-1), x.dtype).view(B, -1, self.hidden_size)\n\n        if context is None or context.dim() != 3:\n            raise ValueError(\"PixDiT_T2I requires context (text embeddings) of shape [B, L, D]\")\n        Ltxt = min(context.shape[1], self.txt_max_length)\n        y = context[:, :Ltxt, :]\n        y_emb = self.y_embedder(y).view(B, Ltxt, self.hidden_size)\n        y_emb = y_emb + self.y_pos_embedding[:, :Ltxt, :].to(y_emb) # y_pos_embedding is a raw nn.Parameter\n\n        condition = F.silu(t_emb)\n        pos_txt = self._fetch_text_pos(Ltxt, x.device, x.dtype) if self.use_text_rope else None\n\n        s = self.s_embedder(x_patches)\n        for i, blk in enumerate(self.patch_blocks):\n            s = self._pre_patch_block(s, i, **kwargs)\n            s, y_emb = blk(s, y_emb, condition, pos_img, pos_txt, None, transformer_options=transformer_options)\n        s = F.silu(t_emb + s)\n\n        s = self._pre_pixel_blocks(s, **kwargs)\n        s_cond = s.view(B * L, self.hidden_size)\n        x_pixels = self.pixel_embedder(x, patch_size=self.patch_size)\n        for blk in self.pixel_blocks:","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/pixeldit/model.py#L199-L235","documentation":"PixDiT_T2I is a text-to-image DiT whose forward requires text embeddings ('context') of shape [B, L, D] (batch, sequence, hidden). The model raises ValueError when context is None or context.dim() != 3, because the y_embedder and text RoPE positions are built unconditionally from that tensor. This is a wiring error: the model was invoked without its text conditioning.","triggerScenarios":"Calling PixDiT_T2I._forward/forward with context=None (e.g. an unconditional/class-conditional path was fed in), or passing a 2-D tensor [L, D] or 4-D packed tensor instead of [B, L, D]. Also triggered by a custom node or sampler patch that drops the conditioning batch dimension before calling the model.","commonSituations":"A workflow that feeds PixDiT latents and timesteps but leaves the text-encoding input unconnected; converting CLIP output that is [L, D] (unbatched) and passing it through without unsqueeze(0); using a generic 'model forward' test harness that omits conditioning.","solutions":["Route text embeddings through the proper PixDiT text encoder/conditioning node so the model receives a [B, L, D] float tensor.","If you build context yourself, ensure it is 3-D: context = embeddings.unsqueeze(0) when you have a single unbatched [L, D] tensor.","Check that the conditioning pathway (e.g. COND input in the workflow) is actually connected to the KSampler/model call — an empty conditioning field commonly arrives as None.","If you intended class-conditional or unconditional generation, that path is not supported by PixDiT_T2I; use the text-conditioned path."],"exampleFix":"# before\nemb = clip_tokens  # shape [L, D]\nnoise_pred = model(x, t, context=emb)\n# after\nemb = clip_tokens.unsqueeze(0)  # [1, L, D]\nnoise_pred = model(x, t, context=emb)","handlingStrategy":"validation","validationCode":"def validate_pixdit_context(context, batch_size=None):\n    if context is None:\n        raise ValueError(\"PixDiT_T2I needs text embeddings; connect a text conditioning input\")\n    if context.dim() != 3:\n        raise ValueError(f\"context must be [B, L, D], got {tuple(context.shape)}\")\n    if batch_size is not None and context.shape[0] != batch_size:\n        raise ValueError(f\"context batch {context.shape[0]} != latent batch {batch_size}\")\n    return context","typeGuard":"def is_pixdit_context(x) -> bool:\n    import torch\n    return torch.is_tensor(x) and x.dim() == 3 and x.is_floating_point()","tryCatchPattern":null,"preventionTips":["Always wire text conditioning through the model's conditioning input in workflows.","When manipulating embeddings, keep three dims: unsqueeze(0) for unbatched [L, D] tensors.","Unit-test custom sampling code with an assert on context.dim() == 3 before calling the model."],"tags":["pixeldit","conditioning","shape-mismatch","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}