{"record":{"id":"c4cd8950e68cb6dc","repo":"sgl-project/sglang","slug":"you-have-to-specify-pixel-values-or-pixel-embeds","errorCode":null,"errorMessage":"You have to specify pixel_values or pixel_embeds","messagePattern":"You have to specify pixel_values or pixel_embeds","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/internvl.py","lineNumber":473,"sourceCode":"    def forward(\n        self,\n        pixel_values: Optional[torch.FloatTensor] = None,\n        output_hidden_states: Optional[bool] = None,\n        return_dict: Optional[bool] = None,\n        pixel_embeds: Optional[torch.FloatTensor] = None,\n    ) -> Union[Tuple, BaseModelOutputWithPooling]:\n        pixel_values = pixel_values.to(device=self.device, dtype=self.dtype)\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        return_dict = (\n            return_dict if return_dict is not None else self.config.use_return_dict\n        )\n\n        if pixel_values is None and pixel_embeds is None:\n            raise ValueError(\"You have to specify pixel_values or pixel_embeds\")\n\n        if pixel_embeds is not None:\n            hidden_states = pixel_embeds\n        else:\n            if len(pixel_values.shape) == 4:\n                hidden_states = self.embeddings(pixel_values)\n            else:\n                raise ValueError(f\"wrong pixel_values size: {pixel_values.shape}\")\n\n        if self.use_data_parallel:\n            encoder_outputs = run_dp_sharded_vision_model(hidden_states, self.encoder)\n            last_hidden_state = encoder_outputs\n        else:\n            encoder_outputs = self.encoder(\n                inputs_embeds=hidden_states,\n                output_hidden_states=output_hidden_states,\n                return_dict=return_dict,\n            )","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/internvl.py#L455-L491","documentation":"InternVL vision model forward requires exactly one of pixel_values or pixel_embeds. Passing neither leaves the vision tower with no input, so it fails fast with this HF-transformers-style check.","triggerScenarios":"InternVisionModel.forward(pixel_values=None, pixel_embeds=None) — calling the vision tower with only attention_mask or empty multimodal inputs.","commonSituations":"Text-only requests routed to the multimodal path, missing image preprocessing, or custom pipelines calling the encoder directly without checking inputs.","solutions":["Ensure the request actually carries an image and that pixel_values is produced by the processor","Skip the vision tower entirely for text-only batches","If you already have embedded features, pass pixel_embeds instead"],"exampleFix":"# before\noutputs = model.vision_model(pixel_values=None, pixel_embeds=None)\n\n# after\nif pixel_values is None and pixel_embeds is None:\n    return None  # text-only path\noutputs = model.vision_model(pixel_values=pixel_values)","handlingStrategy":"type-guard","validationCode":"if pixel_values is None and pixel_embeds is None:\n    raise SKIP(\"text-only request; skip vision tower\")","typeGuard":"def has_vision_input(pixel_values, pixel_embeds) -> bool:\n    return pixel_values is not None or pixel_embeds is not None","tryCatchPattern":"try:\n    out = vision.forward(pixel_values=pv, pixel_embeds=pe)\nexcept ValueError as e:\n    if \"pixel_values or pixel_embeds\" in str(e):\n        return None  # degrade to text-only\n    raise","preventionTips":["Route text-only requests around the multimodal branch","Verify processor output is non-empty before calling the vision model"],"tags":["multimodal","vision","missing-input"],"backgroundTag":"missing-required-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}