huggingface/transformers · error · ValueError

Need to specify either input_ids or inputs_embeds.

Error message

Need to specify either input_ids or inputs_embeds.

What it means

Error "Need to specify either input_ids or inputs_embeds." thrown in huggingface/transformers.

Source

Thrown at src/transformers/integrations/executorch.py:299

                cache_position=cache_position
            )
            ```

            Export with inputs_embeds:
            ```python
            # Prepare embeddings
            inputs_embeds = torch.randn(1, 3, 768, device=model.device)  # batch_size=1, seq_len=3, hidden_size=768
            cache_position = torch.arange(inputs_embeds.shape[1], dtype=torch.long, device=model.device)

            # Export
            exported = exportable_module.export(
                inputs_embeds=inputs_embeds,
                cache_position=cache_position
            )
            ```
        """
        if not (input_ids is None) ^ (inputs_embeds is None):
            raise ValueError("Need to specify either input_ids or inputs_embeds.")

        if hasattr(self.model, "base_model_prefix"):
            base = getattr(self.model, self.model.base_model_prefix, self.model)
            model_device = base.device
        elif hasattr(self.model, "model"):
            model_device = self.model.model.device
        else:
            model_device = "cpu"
            logging.warning(
                "TorchExportableModuleForDecoderOnlyLM.export Can't infer device from the model. Set to CPU by default."
            )

        if input_ids is not None:
            input_kwargs = {
                "input_ids": input_ids,
                "cache_position": cache_position
                if cache_position is not None
                else torch.arange(input_ids.shape[-1], dtype=torch.long, device=model_device),

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass either `input_ids` or `inputs_embeds` to the call.

When it happens

Trigger: Raised in ExecuTorch model wrapper when neither input_ids nor inputs_embeds is provided.

Common situations: Calling the exported ExecuTorch module without any token input.


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/d799008787b8fbd8. Report an issue: GitHub.