huggingface/transformers · error · ValueError

`inputs`: {inputs}` were passed alongside {input_name} which

Error message

`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...

What it means

ValueError from GenerationMixin._prepare_model_inputs: you passed a positional `inputs` tensor AND the model's main input name (input_ids, or pixel_values etc. for multimodal) as a keyword argument in model_kwargs. The two routes for the same input are mutually exclusive; generate refuses to guess which one wins.

Source

Thrown at src/transformers/generation/utils.py:670

        """
        This function extracts the model-specific `inputs` for generation.
        """
        # 1. retrieve all kwargs that are non-None or non-model input related.
        # some encoder-decoder models have different names for model and encoder
        if (
            self.config.is_encoder_decoder
            and hasattr(self, "encoder")
            and self.encoder.main_input_name != self.main_input_name
        ):
            input_name = self.encoder.main_input_name
        else:
            input_name = self.main_input_name

        # 2. check whether model_input_name is passed as kwarg
        # if yes and `inputs` is None use kwarg inputs
        inputs_kwarg = model_kwargs.pop(input_name, None)
        if inputs_kwarg is not None and inputs is not None:
            raise ValueError(
                f"`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. "
                f"Make sure to either pass {inputs} or {input_name}=..."
            )
        elif inputs_kwarg is not None:
            inputs = inputs_kwarg

        # 3. In the presence of `inputs_embeds` for text models:
        # - decoder-only models should complain if the user attempts to pass `inputs_embeds`, but the model
        # doesn't have its forwarding implemented. `inputs_embeds` is kept in `model_kwargs` and can coexist with
        # input_ids (`inputs_embeds` will be used in the 1st generation step, as opposed to `input_ids`)
        # - encoder-decoder models should complain if the user attempts to pass `inputs_embeds` and `input_ids`, and
        # pull the former to inputs. It will be used in place of `input_ids` to get the encoder hidden states.
        if input_name == "input_ids" and "inputs_embeds" in model_kwargs:
            if model_kwargs["inputs_embeds"] is None:
                model_kwargs.pop("inputs_embeds")
            elif not self.config.is_encoder_decoder:
                has_inputs_embeds_forwarding = "inputs_embeds" in set(
                    inspect.signature(self.prepare_inputs_for_generation).parameters.keys()

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass the tensor once — either positionally or as the keyword — and drop the other.
  2. Audit the kwargs dict before generate: kwargs.pop(model.main_input_name, None) if you already pass it positionally.
  3. For multimodal models, pass the non-text main input (e.g. pixel_values) as `inputs` and keep input_ids in kwargs.

Example fix

# before
out = model.generate(inputs.input_ids, **inputs)  # inputs already has input_ids

# after
out = model.generate(**inputs)
Defensive patterns

Strategy: validation

Validate before calling

main_name = model.main_input_name
if inputs is not None and main_name in model_kwargs:
    model_kwargs.pop(main_name)  # keep the positional `inputs`
# or: inputs = None

Prevention

When it happens

Trigger: model.generate(input_ids, input_ids=input_ids); multimodal: model.generate(pixel_values, pixel_values=pixel_values, input_ids=...); forwarding **inputs and also inputs['input_ids']=... explicitly; spreading a dict into generate() that already contains the main input name while also passing it positionally.

Common situations: Refactors that pass both a tensor and **model_kwargs; helper functions that accept inputs and then blindly merge a kwargs dict containing input_ids.

Related errors


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