{"record":{"id":"fc904b7cb5ac68db","repo":"PaddlePaddle/PaddleOCR","slug":"you-have-to-specify-either-decoder-input-ids-or-de","errorCode":null,"errorMessage":"You have to specify either decoder_input_ids or decoder_inputs_embeds","messagePattern":"You have to specify either decoder_input_ids or decoder_inputs_embeds","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/heads/rec_ppformulanet_head.py","lineNumber":457,"sourceCode":"        use_cache = use_cache if use_cache is not None else self.config.use_cache\n        return_dict = (\n            return_dict if return_dict is not None else self.config.use_return_dict\n        )\n\n        # retrieve input_ids and inputs_embeds\n        if input_ids is not None and inputs_embeds is not None:\n            raise ValueError(\n                \"You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time\"\n            )\n        elif input_ids is not None:\n            input = input_ids\n            input_shape = input.shape\n            input_ids = input_ids.reshape([-1, input_shape[-1]])\n        elif inputs_embeds is not None:\n            input_shape = inputs_embeds.shape[:-1]\n            input = inputs_embeds[:, :, -1]\n        else:\n            raise ValueError(\n                \"You have to specify either decoder_input_ids or decoder_inputs_embeds\"\n            )\n\n        # past_key_values_length\n        past_key_values_length = (\n            past_key_values[0][0].shape[2] if past_key_values is not None else 0\n        )\n\n        if inputs_embeds is None:\n            inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale\n\n        if self._use_flash_attention_2:\n            # 2d mask is passed through the layers\n            attention_mask = (\n                attention_mask\n                if (attention_mask is not None and 0 in attention_mask)\n                else None\n            )","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_ppformulanet_head.py#L439-L475","documentation":"Mirror of the both-inputs error: the decoder forward requires at least one of input_ids or inputs_embeds. If both are None the forward has no input to process and raises immediately.","triggerScenarios":"Calling the decoder forward with neither argument, usually because a wrapper defaulted both to None, a kwargs key was misspelled (input_id, inputs_embed), or generation code popped input_ids and failed to set inputs_embeds.","commonSituations":"Refactoring a generate() loop that pops keys off model_kwargs; typo in keyword argument names; conditional code paths where neither branch assigns the input under some config combination.","solutions":["Ensure exactly one of input_ids / inputs_embeds reaches the forward call; check for typos in the kwarg names","In custom generate loops, after popping input_ids make sure either the ids are passed back or the corresponding embeds are computed","Log the kwargs right before the decoder call in your wrapper to catch empty inputs early"],"exampleFix":"# before\nout = self.decoder(input_ids=None, inputs_embeds=None, **kwargs)\n# after\nout = self.decoder(input_ids=ids, **kwargs)","handlingStrategy":"validation","validationCode":"def require_one_input(**kw):\n    ids, emb = kw.get('input_ids'), kw.get('inputs_embeds')\n    if ids is None and emb is None:\n        raise ValueError('decoder forward requires input_ids or inputs_embeds')\n    return kw","typeGuard":"null","tryCatchPattern":"try:\n    out = decoder(**kwargs)\nexcept ValueError as e:\n    if 'have to specify either' in str(e):\n        raise ValueError(f'decoder got no input; kwargs keys: {sorted(kwargs)}') from e\n    raise","preventionTips":["Spell kwarg names exactly: input_ids, inputs_embeds","After popping ids in generation code, always assign ids or embeds back","Unit-test wrappers with empty kwargs to catch silent None paths"],"tags":["api-misuse","decoder-input","ppformulanet"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}