{"record":{"id":"a5ae14fea6d8e97a","repo":"lllyasviel/Fooocus","slug":"you-cannot-specify-both-input-ids-and-inputs-embed","errorCode":null,"errorMessage":"You cannot specify both input_ids and inputs_embeds at the same time","messagePattern":"You cannot specify both input_ids and inputs_embeds at the same time","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"extras/BLIP/models/med.py","lineNumber":718,"sourceCode":"            (those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)`\n            instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`.\n        use_cache (:obj:`bool`, `optional`):\n            If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up\n            decoding (see :obj:`past_key_values`).\n        \"\"\"\n        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions\n        output_hidden_states = (\n            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states\n        )\n        return_dict = return_dict if return_dict is not None else self.config.use_return_dict\n\n        if is_decoder:\n            use_cache = use_cache if use_cache is not None else self.config.use_cache\n        else:\n            use_cache = False\n\n        if input_ids is not None and inputs_embeds is not None:\n            raise ValueError(\"You cannot specify both input_ids and inputs_embeds at the same time\")\n        elif input_ids is not None:\n            input_shape = input_ids.size()\n            batch_size, seq_length = input_shape\n            device = input_ids.device\n        elif inputs_embeds is not None:\n            input_shape = inputs_embeds.size()[:-1]\n            batch_size, seq_length = input_shape\n            device = inputs_embeds.device\n        elif encoder_embeds is not None:    \n            input_shape = encoder_embeds.size()[:-1]\n            batch_size, seq_length = input_shape \n            device = encoder_embeds.device\n        else:\n            raise ValueError(\"You have to specify either input_ids or inputs_embeds or encoder_embeds\")\n\n        # past_key_values_length\n        past_key_values_length = past_key_values[0][0].shape[2] if past_key_values is not None else 0\n","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/extras/BLIP/models/med.py#L700-L736","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide exactly one of input_ids / inputs_embeds / encoder_embeds; drop the unused argument from the call","In wrapper code, explicitly pop conflicting kwargs before forwarding: kwargs.pop('input_ids', None) when using inputs_embeds","For image-conditioned BLIP text encoding, pass encoder_embeds=image_embeds instead of inputs_embeds"],"exampleFix":"// before\nout = model(input_ids=ids, inputs_embeds=emb)\n\n// after\nout = model(inputs_embeds=emb)\n# or\nout = model(input_ids=ids)","handlingStrategy":"validation","validationCode":"def forward_inputs(**kw):\n    sources = [k for k in ('input_ids', 'inputs_embeds', 'encoder_embeds') if kw.get(k) is not None]\n    assert len(sources) == 1, f'exactly one input source required, got {sources}'\n    return {k: v for k, v in kw.items() if not (k in (\"input_ids\", \"inputs_embeds\") and k != sources[0])}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never forward raw **kwargs into MED forward without filtering","Pick one input convention (IDs or embeddings) per code path and enforce it","Write a smoke test calling forward each supported way"],"tags":["blip","bert","input-validation","kwargs"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}