{"record":{"id":"74107b2978be3720","repo":"sgl-project/sglang","slug":"you-must-specify-exactly-one-of-input-ids-or-input-74107b","errorCode":null,"errorMessage":"You must specify exactly one of input_ids or inputs_embeds","messagePattern":"You must specify exactly one of input_ids or inputs_embeds","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/encoders/mistral_3.py","lineNumber":432,"sourceCode":"        self.norm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)\n        self.rotary_emb = MistralRotaryEmbedding(config=config)\n        self.gradient_checkpointing = False\n        self.post_init()\n\n    def forward(\n        self,\n        input_ids: Optional[torch.LongTensor] = None,\n        attention_mask: Optional[torch.Tensor] = None,\n        position_ids: Optional[torch.LongTensor] = None,\n        past_key_values: Optional[Cache] = None,\n        inputs_embeds: Optional[torch.FloatTensor] = None,\n        use_cache: Optional[bool] = None,\n        cache_position: Optional[torch.LongTensor] = None,\n        output_hidden_states: Optional[bool] = None,\n        **kwargs,\n    ) -> BaseModelOutputWithPast:\n        if (input_ids is None) ^ (inputs_embeds is not None):\n            raise ValueError(\n                \"You must specify exactly one of input_ids or inputs_embeds\"\n            )\n\n        if inputs_embeds is None:\n            inputs_embeds = self.embed_tokens(input_ids)\n\n        if use_cache and past_key_values is None:\n            past_key_values = DynamicCache(config=self.config)\n\n        if cache_position is None:\n            past_seen_tokens = (\n                past_key_values.get_seq_length() if past_key_values is not None else 0\n            )\n            cache_position = torch.arange(\n                past_seen_tokens,\n                past_seen_tokens + inputs_embeds.shape[1],\n                device=inputs_embeds.device,\n            )","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/encoders/mistral_3.py#L414-L450","documentation":"The Mistral3 text model forward requires exactly one of input_ids or inputs_embeds. The XOR check rejects both being None (nothing to embed) and both being set (ambiguous input).","triggerScenarios":"Calling Mistral3TextModel.forward with input_ids=None and inputs_embeds=None, or with both provided simultaneously.","commonSituations":"Adapters that always pass embedded inputs while also forwarding the original ids; multimodal wrappers forgetting to clear input_ids after merging pixel embeddings; None-propagation from upstream preprocessing.","solutions":["Pass exactly one: either input_ids (ids get embedded internally) or inputs_embeds","In multimodal paths, set input_ids=None when supplying merged inputs_embeds"],"exampleFix":"# before\nout = model(input_ids=ids, inputs_embeds=embeds)\n# after\nout = model(inputs_embeds=embeds)  # input_ids omitted","handlingStrategy":"type-guard","validationCode":"assert (input_ids is None) != (inputs_embeds is None), \"pass exactly one of input_ids/inputs_embeds\"","typeGuard":"def has_exactly_one_input(ids, embeds) -> bool:\n    return (ids is None) ^ (embeds is None)","tryCatchPattern":null,"preventionTips":["Set input_ids=None explicitly when passing merged multimodal embeddings","Add a shared precondition helper for text-model forwards"],"tags":["mistral-3","forward","mutually-exclusive-args","input-validation"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}