lllyasviel/Fooocus · error · ValueError

You cannot specify both input_ids and inputs_embeds at the…

Error message

You cannot specify both input_ids and inputs_embeds at the same time

What it means

BertEmbeddings/BertModel forward refuses calls that supply both input_ids and inputs_embeds, since they are two alternative ways to provide the input sequence (token IDs vs precomputed embeddings) and both would define the same sequence ambiguously.

Solutions

  1. Provide exactly one of input_ids / inputs_embeds / encoder_embeds; drop the unused argument from the call
  2. In wrapper code, explicitly pop conflicting kwargs before forwarding: kwargs.pop('input_ids', None) when using inputs_embeds
  3. For image-conditioned BLIP text encoding, pass encoder_embeds=image_embeds instead of inputs_embeds

Example fix

// before
out = model(input_ids=ids, inputs_embeds=emb)

// after
out = model(inputs_embeds=emb)
# or
out = model(input_ids=ids)
Defensive patterns

Strategy: validation

Validate before calling

def forward_inputs(**kw):
    sources = [k for k in ('input_ids', 'inputs_embeds', 'encoder_embeds') if kw.get(k) is not None]
    assert len(sources) == 1, f'exactly one input source required, got {sources}'
    return {k: v for k, v in kw.items() if not (k in ("input_ids", "inputs_embeds") and k != sources[0])}

Prevention

When it happens

Trigger: model(input_ids=ids, inputs_embeds=emb, ...) with both non-None; often happens when a wrapper forwards **kwargs from an outer API that includes both keys, or when switching code from IDs to embeddings without removing the old argument.

Common situations: Adapting HF BERT code to BLIP's MED model where encoder_embeds is also accepted; kwargs-progressive forwarding that accidentally carries input_ids alongside inputs_embeds; defaults in data collators that always set input_ids.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/a5ae14fea6d8e97a. Report an issue: GitHub.

Appendix: source

Thrown at extras/BLIP/models/med.py:718

            (those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)`
            instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`.
        use_cache (:obj:`bool`, `optional`):
            If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up
            decoding (see :obj:`past_key_values`).
        """
        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
        )
        return_dict = return_dict if return_dict is not None else self.config.use_return_dict

        if is_decoder:
            use_cache = use_cache if use_cache is not None else self.config.use_cache
        else:
            use_cache = False

        if input_ids is not None and inputs_embeds is not None:
            raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
        elif input_ids is not None:
            input_shape = input_ids.size()
            batch_size, seq_length = input_shape
            device = input_ids.device
        elif inputs_embeds is not None:
            input_shape = inputs_embeds.size()[:-1]
            batch_size, seq_length = input_shape
            device = inputs_embeds.device
        elif encoder_embeds is not None:    
            input_shape = encoder_embeds.size()[:-1]
            batch_size, seq_length = input_shape 
            device = encoder_embeds.device
        else:
            raise ValueError("You have to specify either input_ids or inputs_embeds or encoder_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

View on GitHub (pinned to ae05379cc9)