{"record":{"id":"c29e28e310e09167","repo":"sgl-project/sglang","slug":"either-input-ids-or-inputs-embeds-must-be-provided","errorCode":null,"errorMessage":"Either input_ids or inputs_embeds must be provided.","messagePattern":"Either input_ids or inputs_embeds must be provided\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/clip.py","lineNumber":123,"sourceCode":"        # position_ids (1, len position emb) is contiguous in memory and exported when serialized\n        self.register_buffer(\n            \"position_ids\",\n            torch.arange(config.max_position_embeddings).expand((1, -1)),\n            persistent=False,\n        )\n\n    def forward(\n        self,\n        input_ids: Optional[torch.LongTensor] = None,\n        position_ids: Optional[torch.LongTensor] = None,\n        inputs_embeds: Optional[torch.FloatTensor] = None,\n    ) -> torch.Tensor:\n        if input_ids is not None:\n            seq_length = input_ids.shape[-1]\n        elif inputs_embeds is not None:\n            seq_length = inputs_embeds.shape[-2]\n        else:\n            raise ValueError(\"Either input_ids or inputs_embeds must be provided.\")\n\n        max_positions = self.position_embedding.weight.shape[0]\n        if seq_length > max_positions:\n            raise ValueError(\n                f\"Sequence length {seq_length} exceeds the maximum {max_positions}.\"\n            )\n\n        if position_ids is None:\n            position_ids = self.position_ids[:, :seq_length]\n\n        if inputs_embeds is None:\n            inputs_embeds = self.token_embedding(input_ids)\n\n        position_embeddings = self.position_embedding(position_ids)\n        embeddings = inputs_embeds + position_embeddings\n\n        return embeddings\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/clip.py#L105-L141","documentation":"CLIP text/position embedding forward requires exactly one of input_ids or inputs_embeds to compute the sequence length. Passing None for both is invalid.","triggerScenarios":"Calling CLIPEmbeddings.forward(input_ids=None, inputs_embeds=None).","commonSituations":"Wrapping CLIP in a custom pipeline where the embedder is skipped and ids are dropped; a bug upstream leaves both None.","solutions":["Pass input_ids (token ids) or precomputed inputs_embeds, never neither","Fix the upstream caller that failed to supply one of the two tensors"],"exampleFix":"# before\nemb.forward(None, None)\n# after\nemb.forward(input_ids=input_ids)","handlingStrategy":"type-guard","validationCode":"assert input_ids is not None or inputs_embeds is not None","typeGuard":"def has_embed_input(ids, embeds) -> bool:\n    return ids is not None or embeds is not None","tryCatchPattern":"try: emb.forward(input_ids, inputs_embeds)\nexcept ValueError as e: raise UserInputError(str(e))","preventionTips":["Always pass token ids through the embedding stage"],"tags":["clip","input-validation","embeddings"],"backgroundTag":"missing-required-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}