{"record":{"id":"57ac9b1b0928bedb","repo":"Comfy-Org/ComfyUI","slug":"hidreamo1transformer-requires-input-ids-and-positi","errorCode":null,"errorMessage":"HiDreamO1Transformer requires input_ids and position_ids in conditioning","messagePattern":"HiDreamO1Transformer requires input_ids and position_ids in conditioning","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"comfy/ldm/hidream_o1/model.py","lineNumber":148,"sourceCode":"        self._kv_cache_entries = []\n\n    def clear_kv_cache(self):\n        self._kv_cache_entries = []\n        self._visual_cache = None\n\n    def forward(self, x, timesteps, context=None, transformer_options={}, **kwargs):\n        return comfy.patcher_extension.WrapperExecutor.new_class_executor(\n            self._forward,\n            self,\n            comfy.patcher_extension.get_all_wrappers(comfy.patcher_extension.WrappersMP.DIFFUSION_MODEL, transformer_options)\n        ).execute(x, timesteps, context, transformer_options, **kwargs)\n\n    def _forward(self, x, timesteps, context=None, transformer_options={}, input_ids=None, attention_mask=None, position_ids=None,\n                 vinput_mask=None, ar_len=None, ref_pixel_values=None, ref_image_grid_thw=None, ref_patches=None, **kwargs):\n        \"\"\"Returns flow-match velocity (x - x_pred) / sigma\"\"\"\n\n        if input_ids is None or position_ids is None:\n            raise ValueError(\"HiDreamO1Transformer requires input_ids and position_ids in conditioning\")\n\n        B, _, H, W = x.shape\n        h_p, w_p = H // self.patch_size, W // self.patch_size\n        tgt_image_len = h_p * w_p\n\n        z = einops.rearrange(\n            x, 'B C (H p1) (W p2) -> B (H W) (C p1 p2)',\n            p1=self.patch_size, p2=self.patch_size,\n        )\n        vinputs = torch.cat([z, ref_patches.to(z.dtype)], dim=1) if ref_patches is not None else z\n\n        inputs_embeds = self.language_model.embed_tokens(input_ids).to(x.dtype)\n\n        if ref_pixel_values is not None and ref_image_grid_thw is not None:\n            # ViT output is constant across sampling steps within a generation\n            # identity-key by the input tensor so refs don't recompute every step.\n            cached = self._visual_cache\n            if cached is not None and cached[0] is ref_pixel_values:","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/hidream_o1/model.py#L130-L166","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the model through the stock HiDream-O1 text-encoder/conditioning nodes so input_ids and position_ids are produced and forwarded.","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).","Check for None before the call and fail with a clear message about which conditioning key is missing."],"exampleFix":"# before\nout = model(x, t, context=embeddings)  # ids dropped\n\n# after\nout = model(x, t, context=embeddings, input_ids=ids, position_ids=pos)","handlingStrategy":"validation","validationCode":"missing = [k for k in (\"input_ids\", \"position_ids\") if k not in cond or cond[k] is None]\nif missing:\n    raise ValueError(f\"conditioning missing required keys: {missing}\")","typeGuard":"def has_hidream_o1_token_conditioning(cond: dict) -> bool:\n    return cond.get(\"input_ids\") is not None and cond.get(\"position_ids\") is not None","tryCatchPattern":null,"preventionTips":["Always run HiDream-O1 with its matching text-encoder frontend so ids are produced.","Forward the full conditioning dict as **kwargs so input_ids/position_ids reach _forward.","Check for required conditioning keys before invoking the model."],"tags":["hidream-o1","conditioning","input-validation","forward"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}