Comfy-Org/ComfyUI · critical · ValueError

HiDreamO1Transformer requires input_ids and position_ids in

Error message

HiDreamO1Transformer requires input_ids and position_ids in conditioning

What it means

HiDream-O1 is an autoregressive/flow hybrid whose forward requires token-level conditioning: input_ids and position_ids must be present in the kwargs (delivered from the conditioning dict). If either is None, forward raises ValueError before touching x. These ids drive the language-model embedder and KV layout, so there is no sane default.

Source

Thrown at comfy/ldm/hidream_o1/model.py:148

        self._kv_cache_entries = []

    def clear_kv_cache(self):
        self._kv_cache_entries = []
        self._visual_cache = None

    def forward(self, x, timesteps, context=None, transformer_options={}, **kwargs):
        return comfy.patcher_extension.WrapperExecutor.new_class_executor(
            self._forward,
            self,
            comfy.patcher_extension.get_all_wrappers(comfy.patcher_extension.WrappersMP.DIFFUSION_MODEL, transformer_options)
        ).execute(x, timesteps, context, transformer_options, **kwargs)

    def _forward(self, x, timesteps, context=None, transformer_options={}, input_ids=None, attention_mask=None, position_ids=None,
                 vinput_mask=None, ar_len=None, ref_pixel_values=None, ref_image_grid_thw=None, ref_patches=None, **kwargs):
        """Returns flow-match velocity (x - x_pred) / sigma"""

        if input_ids is None or position_ids is None:
            raise ValueError("HiDreamO1Transformer requires input_ids and position_ids in conditioning")

        B, _, H, W = x.shape
        h_p, w_p = H // self.patch_size, W // self.patch_size
        tgt_image_len = h_p * w_p

        z = einops.rearrange(
            x, 'B C (H p1) (W p2) -> B (H W) (C p1 p2)',
            p1=self.patch_size, p2=self.patch_size,
        )
        vinputs = torch.cat([z, ref_patches.to(z.dtype)], dim=1) if ref_patches is not None else z

        inputs_embeds = self.language_model.embed_tokens(input_ids).to(x.dtype)

        if ref_pixel_values is not None and ref_image_grid_thw is not None:
            # ViT output is constant across sampling steps within a generation
            # identity-key by the input tensor so refs don't recompute every step.
            cached = self._visual_cache
            if cached is not None and cached[0] is ref_pixel_values:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Run the model through the stock HiDream-O1 text-encoder/conditioning nodes so input_ids and position_ids are produced and forwarded.
  2. If calling _forward directly, ensure the conditioning dict's input_ids/position_ids keys are unpacked into the call (not swallowed by **kwargs on another parameter).
  3. Check for None before the call and fail with a clear message about which conditioning key is missing.

Example fix

# before
out = model(x, t, context=embeddings)  # ids dropped

# after
out = model(x, t, context=embeddings, input_ids=ids, position_ids=pos)
Defensive patterns

Strategy: validation

Validate before calling

missing = [k for k in ("input_ids", "position_ids") if k not in cond or cond[k] is None]
if missing:
    raise ValueError(f"conditioning missing required keys: {missing}")

Type guard

def has_hidream_o1_token_conditioning(cond: dict) -> bool:
    return cond.get("input_ids") is not None and cond.get("position_ids") is not None

Prevention

When it happens

Trigger: Running the HiDream-O1 transformer with conditioning that lacks the text token ids / position ids — e.g. a text encoder path that returned embeddings only, or a custom sampler that passes context= without forwarding the extra conditioning keys via **kwargs into _forward.

Common situations: Newly added model whose conditioning contract differs from other DiTs (most take only context embeddings); custom nodes or sampler loops that filter conditioning fields; using a checkpoint without its matching text-encoder frontend.

Related errors


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