{"record":{"id":"005df15781cb72dc","repo":"sgl-project/sglang","slug":"incorrect-type-of-pixel-values-got-type-type-pi","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/deepseek_ocr.py","lineNumber":1604,"sourceCode":"\n    def _parse_and_validate_image_input(self, **kwargs: object):\n\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\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\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\n            return [pixel_values, images_crop, images_spatial_crop]\n\n        raise AssertionError(\"This line should be unreachable.\")\n","sourceCodeStart":1586,"sourceCodeEnd":1622,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/deepseek_ocr.py#L1586-L1622","documentation":"Raised by DeepseekOCRModel._parse_and_validate_image_input when the pixel_values field of the multimodal input items is neither a torch.Tensor nor a list. The model's vision encoder requires pixel tensors produced by the processor, and any other Python type indicates the input payload was assembled incorrectly.","triggerScenarios":"Calling get_multimodal_embeddings (or a serving path that routes through it) with mm_item_kwargs/imaging data whose pixel_values key holds a numpy array, PIL Image, string, dict, or None mixed with non-empty content, so the isinstance((torch.Tensor, list)) check fails.","commonSituations":"Passing raw numpy arrays instead of tensors, building multimodal prompts by hand instead of using the HF processor output, feeding an incompatible processor version, or a custom client serializing images to lists of lists that get decoded into dicts.","solutions":["Convert pixel_values with torch.as_tensor(pixel_values, dtype=torch.bfloat16/torch.float32) before calling the API","Generate inputs via the model's processor (processor(images=..., return_tensors='pt')) so pixel_values is already a torch.Tensor","If passing a list, ensure it is a flat list of per-image tensors, not nested Python lists of numbers or dicts","Check that pixel_values was not double-wrapped (e.g. {'pixel_values': {'pixel_values': ...}}) by an extra payload layer"],"exampleFix":"// before\nmm_kwargs = {\"pixel_values\": np.asarray(img)}  # numpy -> ValueError\n\n// after\nmm_kwargs = {\"pixel_values\": torch.from_numpy(np.asarray(img))}","handlingStrategy":"type-guard","validationCode":"pv = mm_kwargs.get(\"pixel_values\")\nassert isinstance(pv, (torch.Tensor, list)) and pv is not None, \"pixel_values must be tensor/list\"","typeGuard":"def is_valid_pixel_values(v) -> bool:\n    return isinstance(v, (torch.Tensor, list)) and (\n        isinstance(v, torch.Tensor) or all(isinstance(t, torch.Tensor) for t in v)\n    )","tryCatchPattern":null,"preventionTips":["Always derive multimodal inputs from the model's processor(...) output","Run an isinstance check on pixel_values before calling get_multimodal_embeddings"],"tags":["multimodal","vision","type-validation","deepseek-ocr"],"backgroundTag":"input-type-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}