{"record":{"id":"70f9aa0bf859ce04","repo":"PaddlePaddle/PaddleOCR","slug":"you-have-to-specify-either-decoder-input-ids-or-de-70f9aa","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_unimernet_head.py","lineNumber":1049,"sourceCode":"        )\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        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[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            attention_mask = (\n                attention_mask\n                if (attention_mask is not None and 0 in attention_mask)\n                else None\n            )\n        else:\n            attention_mask = _prepare_4d_causal_attention_mask(","sourceCodeStart":1031,"sourceCodeEnd":1067,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/modeling/heads/rec_unimernet_head.py#L1031-L1067","documentation":"The decoder forward in the UniMERNet head requires exactly one input source: decoder_input_ids or decoder_inputs_embeds. If both are None there is nothing to decode, so the model raises this ValueError rather than producing a confusing downstream shape error.","triggerScenarios":"Calling the decoder/model forward with input_ids=None and inputs_embeds=None; typical when a generator fails to inject decoder_start_token_id or when a wrapper drops the argument.","commonSituations":"Custom generate() implementations that build model_kwargs but forget decoder_input_ids; encoder-decoder setups where the start token id is undefined so no ids are created.","solutions":["Pass decoder_input_ids (usually a [batch,1] start token) to the forward call","If using generate, ensure generation_config.decoder_start_token_id / bos_token_id is set so ids are prepared","Or pass inputs_embeds if you embed inputs yourself"],"exampleFix":"# before\nout = model_decoder(encoder_hidden_states=enc)  # no decoder input\n# after\nstart = paddle.full([bsz, 1], decoder_start_token_id, dtype='int64')\nout = model_decoder(input_ids=start, encoder_hidden_states=enc)","handlingStrategy":"validation","validationCode":"if input_ids is None and inputs_embeds is None:\n    input_ids = paddle.full([bsz, 1], decoder_start_token_id, dtype='int64')","typeGuard":"def has_decoder_input(input_ids, inputs_embeds) -> bool:\n    return input_ids is not None or inputs_embeds is not None","tryCatchPattern":null,"preventionTips":["Centralize decoder input creation (start token) in one helper","Log model_kwargs keys before generate to confirm decoder ids exist"],"tags":["paddle","decoder","missing-argument","api-misuse"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}