{"record":{"id":"8d5bfe6790e493dd","repo":"sgl-project/sglang","slug":"incorrect-type-of-pixel-values-got-type-type-pi-8d5bfe","errorCode":null,"errorMessage":"Incorrect type of pixel values. Got type: {type(pixel_values)}","messagePattern":"Incorrect type of pixel values\\. Got type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/unlimited_ocr.py","lineNumber":183,"sourceCode":"\n    def _parse_and_validate_image_input(self, **kwargs: object):\n        \"\"\"Parse and validate pixel values, spatial crops, and image crops.\"\"\"\n        pixel_values = kwargs.pop(\"pixel_values\", None)\n        images_spatial_crop = kwargs.pop(\"images_spatial_crop\", None)\n        images_crop = kwargs.pop(\"images_crop\", None)\n        has_images = kwargs.pop(\"has_images\", None)\n\n        if pixel_values is None:\n            return None\n        if has_images is not None:\n            if not has_images:\n                return None\n        elif torch.sum(pixel_values).item() == 0:\n            return None\n\n        if pixel_values is not None:\n            if not isinstance(pixel_values, (torch.Tensor, list)):\n                raise ValueError(\n                    \"Incorrect type of pixel values. \" f\"Got type: {type(pixel_values)}\"\n                )\n            if not isinstance(images_spatial_crop, (torch.Tensor, list)):\n                raise ValueError(\n                    \"Incorrect type of image sizes. \"\n                    f\"Got type: {type(images_spatial_crop)}\"\n                )\n            if not isinstance(images_crop, (torch.Tensor, list)):\n                raise ValueError(\n                    \"Incorrect type of image crop. \" f\"Got type: {type(images_crop)}\"\n                )\n            return [pixel_values, images_crop, images_spatial_crop]\n\n        raise AssertionError(\"This line should be unreachable.\")\n\n    def _pixel_values_to_embedding(\n        self,\n        pixel_values: torch.Tensor,","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/unlimited_ocr.py#L165-L201","documentation":"_parse_and_validate_image_input requires pixel_values to be a torch.Tensor or list; anything else (numpy array, None-with-flag, string) is rejected before encoding.","triggerScenarios":"Passing pixel_values as np.ndarray or another type into get_multimodal_embeddings of UnlimitedOCR.","commonSituations":"Feeders/preprocessors producing numpy arrays; intermediate layers forwarding the wrong field; None handled by earlier branches so unexpected types slip through.","solutions":["Convert numpy arrays with torch.from_numpy(...).to(device) before calling","Pass None when there are no images so the earlier branch skips encoding","Ensure the input dict keys match what the scheduler provides"],"exampleFix":"# before\nmodel.get_multimodal_embeddings(pixel_values=np_imgs, ...)\n# after\nmodel.get_multimodal_embeddings(pixel_values=torch.from_numpy(np_imgs), ...)","handlingStrategy":"type-guard","validationCode":"assert pixel_values is None or isinstance(pixel_values, (torch.Tensor, list)), type(pixel_values)","typeGuard":"def valid_pixels(p):\n    return p is None or isinstance(p, (torch.Tensor, list))","tryCatchPattern":null,"preventionTips":["Convert numpy to torch at the preprocessing boundary","Use the built-in multimodal processor"],"tags":["type-validation","multimodal","pixel-values"],"backgroundTag":"invalid-input-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}