{"record":{"id":"f17e807d50140266","repo":"PaddlePaddle/PaddleOCR","slug":"you-cannot-specify-both-decoder-input-ids-and-deco","errorCode":null,"errorMessage":"You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time","messagePattern":"You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/modeling/heads/rec_ppformulanet_head.py","lineNumber":446,"sourceCode":"\n        output_attentions = (\n            output_attentions\n            if output_attentions is not None\n            else self.config.output_attentions\n        )\n        output_hidden_states = (\n            output_hidden_states\n            if output_hidden_states is not None\n            else self.config.output_hidden_states\n        )\n        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        )","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_ppformulanet_head.py#L428-L464","documentation":"The decoder forward rejects calls that supply both input_ids and inputs_embeds. They are two mutually exclusive ways to provide the input sequence (token ids vs pre-computed embeddings); giving both makes the input ambiguous.","triggerScenarios":"Calling the PP-FormulaNet decoder forward (or a wrapper that forwards **kwargs into it) with both input_ids=... and inputs_embeds=... non-None, e.g. when a caller pre-embeds tokens but forgets to drop input_ids from kwargs.","commonSituations":"Adapting generation code that always passes input_ids while adding embedding injection for prompt/prefix tuning; kwargs plumbing where model_kwargs retains input_ids and the caller also sets inputs_embeds; copying HF Bart-like code into this ported decoder.","solutions":["Pass exactly one of the two: input_ids OR inputs_embeds","When injecting embeddings, pop input_ids from the kwargs dict first (input_ids = kwargs.pop('input_ids', None) before setting inputs_embeds)","Add an assert in your wrapper that not (input_ids is not None and inputs_embeds is not None) to fail with your own message"],"exampleFix":"# before\nout = decoder(input_ids=ids, inputs_embeds=emb, ...)\n# after\nout = decoder(inputs_embeds=emb, ...)  # ids dropped","handlingStrategy":"validation","validationCode":"def exclusive_inputs(**kw):\n    ids, emb = kw.get('input_ids'), kw.get('inputs_embeds')\n    if ids is not None and emb is not None:\n        raise ValueError('pass input_ids or inputs_embeds, not both')\n    return kw\n# forward(**exclusive_inputs(input_ids=ids, inputs_embeds=emb))","typeGuard":"null","tryCatchPattern":"try:\n    out = decoder(input_ids=ids, inputs_embeds=emb)\nexcept ValueError as e:\n    if 'cannot specify both' in str(e):\n        out = decoder(inputs_embeds=emb)\n    else:\n        raise","preventionTips":["pop mutually exclusive keys from kwargs before forwarding","Wrap the decoder once in a helper enforcing the either/or contract","When injecting embeds, delete input_ids from the request dict explicitly"],"tags":["api-misuse","decoder-input","ppformulanet"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}