PaddlePaddle/PaddleOCR · error · ValueError
You have to specify either decoder_input_ids or decoder_inpu
Error message
You have to specify either decoder_input_ids or decoder_inputs_embeds
What it means
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.
Source
Thrown at ppocr/modeling/heads/rec_unimernet_head.py:1049
)
use_cache = use_cache if use_cache is not None else self.config.use_cache
return_dict = (
return_dict if return_dict is not None else self.config.use_return_dict
)
if input_ids is not None and inputs_embeds is not None:
raise ValueError(
"You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time"
)
elif input_ids is not None:
input = input_ids
input_shape = input.shape
input_ids = input_ids.reshape([-1, input_shape[-1]])
elif inputs_embeds is not None:
input_shape = inputs_embeds.shape[:-1]
input = inputs_embeds[:, :, -1]
else:
raise ValueError(
"You have to specify either decoder_input_ids or decoder_inputs_embeds"
)
past_key_values_length = (
past_key_values[0][0].shape[2] if past_key_values is not None else 0
)
if inputs_embeds is None:
inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale
if self._use_flash_attention_2:
attention_mask = (
attention_mask
if (attention_mask is not None and 0 in attention_mask)
else None
)
else:
attention_mask = _prepare_4d_causal_attention_mask(View on GitHub (pinned to 2661c7c0ef)
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
Example fix
# before out = model_decoder(encoder_hidden_states=enc) # no decoder input # after start = paddle.full([bsz, 1], decoder_start_token_id, dtype='int64') out = model_decoder(input_ids=start, encoder_hidden_states=enc)
Defensive patterns
Strategy: validation
Validate before calling
if input_ids is None and inputs_embeds is None:
input_ids = paddle.full([bsz, 1], decoder_start_token_id, dtype='int64') Type guard
def has_decoder_input(input_ids, inputs_embeds) -> bool:
return input_ids is not None or inputs_embeds is not None Prevention
- Centralize decoder input creation (start token) in one helper
- Log model_kwargs keys before generate to confirm decoder ids exist
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- You cannot specify both decoder_input_ids and decoder_inputs
- The `{mask_name}` should be specified for {len(self.layers)}
- Make sure that all the required parameters: {list(function_a
- `decoder_start_token_id` or `bos_token_id` has to be defined
- Please set inference model dir in Global.inference_model or
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/70f9aa0bf859ce04.
Report an issue: GitHub.