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

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.

Source

Thrown at ppocr/modeling/heads/rec_ppformulanet_head.py:457

        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
        )

        # retrieve input_ids and inputs_embeds
        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_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:
            # 2d mask is passed through the layers
            attention_mask = (
                attention_mask
                if (attention_mask is not None and 0 in attention_mask)
                else None
            )

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Ensure exactly one of input_ids / inputs_embeds reaches the forward call; check for typos in the kwarg names
  2. In custom generate loops, after popping input_ids make sure either the ids are passed back or the corresponding embeds are computed
  3. Log the kwargs right before the decoder call in your wrapper to catch empty inputs early

Example fix

# before
out = self.decoder(input_ids=None, inputs_embeds=None, **kwargs)
# after
out = self.decoder(input_ids=ids, **kwargs)
Defensive patterns

Strategy: validation

Validate before calling

def require_one_input(**kw):
    ids, emb = kw.get('input_ids'), kw.get('inputs_embeds')
    if ids is None and emb is None:
        raise ValueError('decoder forward requires input_ids or inputs_embeds')
    return kw

Type guard

null

Try / catch

try:
    out = decoder(**kwargs)
except ValueError as e:
    if 'have to specify either' in str(e):
        raise ValueError(f'decoder got no input; kwargs keys: {sorted(kwargs)}') from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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