Comfy-Org/ComfyUI · error · ValueError

PixDiT_T2I requires context (text embeddings) of shape [B, L

Error message

PixDiT_T2I requires context (text embeddings) of shape [B, L, D]

What it means

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.

Source

Thrown at comfy/ldm/pixeldit/model.py:217

    def _pre_pixel_blocks(self, s, **kwargs):
        return s

    def _forward(self, x, timesteps, context=None, attention_mask=None, transformer_options={}, **kwargs):
        H_orig, W_orig = x.shape[2], x.shape[3]
        x = comfy.ldm.common_dit.pad_to_patch_size(x, (self.patch_size, self.patch_size))
        B, _, H, W = x.shape
        Hs = H // self.patch_size
        Ws = W // self.patch_size
        L = Hs * Ws

        pos_img = self._fetch_patch_pos(Hs, Ws, x.device, x.dtype, **(transformer_options.get("rope_options") or {}))
        x_patches = F.unfold(x, kernel_size=self.patch_size, stride=self.patch_size).transpose(1, 2)

        t_emb = self.t_embedder(timesteps.view(-1), x.dtype).view(B, -1, self.hidden_size)

        if context is None or context.dim() != 3:
            raise ValueError("PixDiT_T2I requires context (text embeddings) of shape [B, L, D]")
        Ltxt = min(context.shape[1], self.txt_max_length)
        y = context[:, :Ltxt, :]
        y_emb = self.y_embedder(y).view(B, Ltxt, self.hidden_size)
        y_emb = y_emb + self.y_pos_embedding[:, :Ltxt, :].to(y_emb) # y_pos_embedding is a raw nn.Parameter

        condition = F.silu(t_emb)
        pos_txt = self._fetch_text_pos(Ltxt, x.device, x.dtype) if self.use_text_rope else None

        s = self.s_embedder(x_patches)
        for i, blk in enumerate(self.patch_blocks):
            s = self._pre_patch_block(s, i, **kwargs)
            s, y_emb = blk(s, y_emb, condition, pos_img, pos_txt, None, transformer_options=transformer_options)
        s = F.silu(t_emb + s)

        s = self._pre_pixel_blocks(s, **kwargs)
        s_cond = s.view(B * L, self.hidden_size)
        x_pixels = self.pixel_embedder(x, patch_size=self.patch_size)
        for blk in self.pixel_blocks:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Route text embeddings through the proper PixDiT text encoder/conditioning node so the model receives a [B, L, D] float tensor.
  2. If you build context yourself, ensure it is 3-D: context = embeddings.unsqueeze(0) when you have a single unbatched [L, D] tensor.
  3. 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.
  4. If you intended class-conditional or unconditional generation, that path is not supported by PixDiT_T2I; use the text-conditioned path.

Example fix

# before
emb = clip_tokens  # shape [L, D]
noise_pred = model(x, t, context=emb)
# after
emb = clip_tokens.unsqueeze(0)  # [1, L, D]
noise_pred = model(x, t, context=emb)
Defensive patterns

Strategy: validation

Validate before calling

def validate_pixdit_context(context, batch_size=None):
    if context is None:
        raise ValueError("PixDiT_T2I needs text embeddings; connect a text conditioning input")
    if context.dim() != 3:
        raise ValueError(f"context must be [B, L, D], got {tuple(context.shape)}")
    if batch_size is not None and context.shape[0] != batch_size:
        raise ValueError(f"context batch {context.shape[0]} != latent batch {batch_size}")
    return context

Type guard

def is_pixdit_context(x) -> bool:
    import torch
    return torch.is_tensor(x) and x.dim() == 3 and x.is_floating_point()

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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