PaddlePaddle/PaddleOCR · error · ValueError

You cannot specify both decoder_input_ids and decoder_inputs

Error message

You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time

What it means

The decoder in the UniMERNet head accepts token ids (decoder_input_ids) or continuous embeddings (decoder_inputs_embeds) as input, but not both at once, since it would be ambiguous which to embed. The forward method raises this ValueError immediately when both are non-None.

Source

Thrown at ppocr/modeling/heads/rec_unimernet_head.py:1038

    ):

        output_attentions = (
            output_attentions
            if output_attentions is not None
            else self.config.output_attentions
        )
        output_hidden_states = (
            output_hidden_states
            if output_hidden_states is not None
            else self.config.output_hidden_states
        )
        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
        )

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Pass only input_ids and let the decoder embed them via embed_tokens
  2. Or pass only inputs_embeds (pre-embedded inputs) and set input_ids=None

Example fix

# before
outputs = decoder(input_ids=ids, inputs_embeds=embs)
# after
outputs = decoder(input_ids=ids)  # embeddings computed internally
Defensive patterns

Strategy: validation

Validate before calling

assert not (input_ids is not None and inputs_embeds is not None), 'pass input_ids OR inputs_embeds, not both'

Type guard

def has_single_decoder_input(input_ids, inputs_embeds) -> bool:
    return (input_ids is not None) ^ (inputs_embeds is not None)

Prevention

When it happens

Trigger: Calling forward (directly or via generate) with both input_ids and inputs_embeds set; often happens when a wrapper pre-computes embeddings but still forwards the raw ids.

Common situations: Adapting generation code that supplies inputs_embeds for prompt conditioning while the model wrapper also forwards input_ids; copy-paste from a pipeline that fills all optional kwargs.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/776a62a29738cc97. Report an issue: GitHub.