lllyasviel/Fooocus · error · ValueError

You have to specify either input_ids or inputs_embeds or enc

Error message

You have to specify either input_ids or inputs_embeds or encoder_embeds

What it means

The MED BertModel forward requires at least one input source — input_ids, inputs_embeds, or encoder_embeds — to determine batch_size/seq_length/device. If all three are None it cannot infer the input shape and raises this ValueError before doing any compute.

Source

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

        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

        if attention_mask is None:
            attention_mask = torch.ones(((batch_size, seq_length + past_key_values_length)), device=device)
            
        # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
        # ourselves in which case we just need to make it broadcastable to all heads.
        extended_attention_mask: torch.Tensor = self.get_extended_attention_mask(attention_mask, input_shape, 
                                                                                 device, is_decoder)

        # If a 2D or 3D attention mask is provided for the cross-attention
        # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
        if encoder_hidden_states is not None:
            if type(encoder_hidden_states) == list:
                encoder_batch_size, encoder_sequence_length, _ = encoder_hidden_states[0].size()
            else:

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Pass one of input_ids, inputs_embeds, or encoder_embeds explicitly
  2. If calling the BLIP image-grounded path, pass the projected image features as encoder_embeds
  3. Add an assert before forward: assert input_ids is not None or inputs_embeds is not None or encoder_embeds is not None to catch upstream None early

Example fix

// before
out = text_encoder(attention_mask=mask)  # inputs all None

// after
out = text_encoder(input_ids=ids, attention_mask=mask)
# BLIP image branch:
# out = text_encoder(encoder_embeds=image_embeds, attention_mask=mask)
Defensive patterns

Strategy: validation

Validate before calling

assert any(x is not None for x in (input_ids, inputs_embeds, encoder_embeds)), \
    'must pass input_ids, inputs_embeds, or encoder_embeds'

Prevention

When it happens

Trigger: model() or model(attention_mask=mask, ...) with none of input_ids/inputs_embeds/encoder_embeds set; commonly when a caller intended to pass encoder_embeds (BLIP's image branch) but named it inputs_embeds in an outdated signature, or when a required tensor is accidentally None from an upstream bug.

Common situations: Version drift where the argument expected by caller code was renamed/added; generation wrappers that pass only past_key_values; None returned by a dataloader or preprocessing step silently propagated.

Related errors


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