{"record":{"id":"7364d7fda715d7e0","repo":"sgl-project/sglang","slug":"you-have-to-specify-input-ids","errorCode":null,"errorMessage":"You have to specify input_ids","messagePattern":"You have to specify input_ids","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/encoders/clip.py","lineNumber":81,"sourceCode":"        # For `pooled_output` computation\n        self.eos_token_id = config.eos_token_id\n\n    def forward(\n        self,\n        input_ids: torch.Tensor | None,\n        position_ids: torch.Tensor | None = None,\n        attention_mask: torch.Tensor | None = None,\n        inputs_embeds: torch.Tensor | None = None,\n        output_hidden_states: bool | None = None,\n    ) -> BaseEncoderOutput:\n        output_hidden_states = (\n            output_hidden_states\n            if output_hidden_states is not None\n            else self.config.output_hidden_states\n        )\n\n        if input_ids is None:\n            raise ValueError(\"You have to specify input_ids\")\n\n        input_shape = input_ids.size()\n        input_ids = input_ids.view(-1, input_shape[-1])\n\n        hidden_states = self.embeddings(input_ids=input_ids, position_ids=position_ids)\n\n        attention_mask = prepare_clip_attention_mask(\n            input_shape,\n            hidden_states.dtype,\n            hidden_states.device,\n            attention_mask,\n        )\n\n        encoder_outputs = self.encoder(\n            inputs_embeds=hidden_states,\n            return_all_hidden_states=output_hidden_states,\n            attention_mask=attention_mask,\n        )","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/encoders/clip.py#L63-L99","documentation":"Thrown by CLIPTextModel.forward when input_ids is None. The text transformer requires token IDs to build embeddings; unlike some HF models this implementation does not accept inputs_embeds as an alternative, so calling forward without input_ids is invalid.","triggerScenarios":"Calling encoder forward (directly or via a pipeline) with input_ids=None, e.g. passing only attention_mask or pixel_values; forwarding **kwargs that swallow input_ids due to a misnamed key.","commonSituations":"Adapting CLIP for multimodal pipelines where embeddings were precomputed upstream; refactoring from HF CLIPTextModel which accepts inputs_embeds; key typos like input_ids vs input_id in caller code.","solutions":["Pass a valid input_ids tensor of shape (batch, seq_len) to forward()","If you have precomputed embeddings, add them to inputs_embeds handling yourself or subclass to skip the embedding step","Check caller kwargs for typos/misrouting that leave input_ids unset"],"exampleFix":"# before\nout = model(attention_mask=mask)\n# after\nout = model(input_ids=token_ids, attention_mask=mask)","handlingStrategy":"validation","validationCode":"assert input_ids is not None and input_ids.dim() >= 2, \"input_ids required with shape (batch, seq_len)\"","typeGuard":"def has_input_ids(kwargs) -> bool:\n    return isinstance(kwargs.get(\"input_ids\"), torch.Tensor)","tryCatchPattern":"try:\n    out = model(input_ids=ids)\nexcept ValueError as e:\n    if \"input_ids\" in str(e):\n        raise ValueError(f\"Missing token ids for batch: {e}\") from e\n    raise","preventionTips":["Always construct token ids before calling the encoder","Log kwargs keys before forward in multimodal pipelines"],"tags":["clip","text-encoder","input-validation","multimodal"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}