{"record":{"id":"9984ba25f3aac570","repo":"sgl-project/sglang","slug":"incorrect-type-of-image-crop-got-type-type-imag","errorCode":null,"errorMessage":"Incorrect type of image crop. Got type: {type(images_crop)}","messagePattern":"Incorrect type of image crop\\. Got type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/deepseek_ocr.py","lineNumber":1615,"sourceCode":"            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\n    def _pixel_values_to_embedding(\n        self,\n        pixel_values: torch.Tensor,\n        images_crop: torch.Tensor,\n        images_spatial_crop: torch.Tensor,\n        has_local_crops: Optional[List[bool]] = None,\n    ) -> NestedTensors:\n\n        # Pixel_values (global view): [n_image, batch_size, 3, height, width]\n        # images_spatial_crop: [n_image, batch_size, [num_tiles_w, num_tiles_h]]\n        # images_crop (local view): [n_image, batch_size, num_pathes, 3, h, w]","sourceCodeStart":1597,"sourceCodeEnd":1633,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/deepseek_ocr.py#L1597-L1633","documentation":"Raised by _parse_and_validate_image_input in deepseek_ocr.py when images_crop (the crop-region tensor) is neither torch.Tensor nor list. The three-part validation (pixel_values, images_crop, images_spatial_crop) must all pass before the encoder runs.","triggerScenarios":"get_multimodal_embeddings is called with images_crop set to an unexpected type — numpy array, dict from an unserialized processor output, string, or a scalar — failing the isinstance((torch.Tensor, list)) check at deepseek_ocr.py:1615.","commonSituations":"Processor/model version drift where the crop tensor key is absent and defaults to a placeholder, JSON-serialized multimodal payloads that decode crops as dicts/lists-of-dicts, or custom OCR clients that only populate pixel data.","solutions":["Pass processor-generated images_crop as a tensor/list","Ensure the whole multimodal kwargs dict comes from one processor(...) call rather than being assembled piecemeal","Upgrade/downgrade the processor to the version paired with the sglang model implementation"],"exampleFix":"// before\ninputs = {\"pixel_values\": pv, \"images_spatial_crop\": sc, \"images_crop\": crop_dict}\n\n// after\ninputs = {\"pixel_values\": pv, \"images_spatial_crop\": sc,\n          \"images_crop\": torch.tensor(crop_dict[\"boxes\"])}","handlingStrategy":"type-guard","validationCode":"crop = mm_kwargs.get(\"images_crop\")\nassert isinstance(crop, (torch.Tensor, list)), \"images_crop must be tensor/list\"","typeGuard":"def is_valid_images_crop(v) -> bool:\n    return isinstance(v, (torch.Tensor, list))","tryCatchPattern":null,"preventionTips":["Validate all three fields (pixel_values, images_crop, images_spatial_crop) together before the call"],"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"}