sgl-project/sglang · error · ValueError

Incorrect type of image crop. Got type: {type(images_crop)}

Error message

Incorrect type of image crop. Got type: {type(images_crop)}

What it means

Third guard in the same validation chain: images_crop must be a torch.Tensor or list, otherwise the input is rejected.

Source

Thrown at python/sglang/srt/models/unlimited_ocr.py:192

            return None
        if has_images is not None:
            if not has_images:
                return None
        elif torch.sum(pixel_values).item() == 0:
            return None

        if pixel_values is not None:
            if not isinstance(pixel_values, (torch.Tensor, list)):
                raise ValueError(
                    "Incorrect type of pixel values. " f"Got type: {type(pixel_values)}"
                )
            if not isinstance(images_spatial_crop, (torch.Tensor, list)):
                raise ValueError(
                    "Incorrect type of image sizes. "
                    f"Got type: {type(images_spatial_crop)}"
                )
            if not isinstance(images_crop, (torch.Tensor, list)):
                raise ValueError(
                    "Incorrect type of image crop. " f"Got type: {type(images_crop)}"
                )
            return [pixel_values, images_crop, images_spatial_crop]

        raise AssertionError("This line should be unreachable.")

    def _pixel_values_to_embedding(
        self,
        pixel_values: torch.Tensor,
        images_crop: torch.Tensor,
        images_spatial_crop: torch.Tensor,
        has_local_crops: Optional[List[bool]] = None,
    ) -> NestedTensors:
        """Encode pixel values into per-image embedding sequences."""
        images_in_this_batch = []

        with torch.no_grad():
            for jdx in range(images_spatial_crop.size(0)):

View on GitHub (pinned to 0132848349)

Solutions

  1. Convert images_crop to a torch tensor or list before calling
  2. Rely on the built-in multimodal processor to build all three fields consistently
  3. Validate the whole image-input dict before forwarding

Example fix

# before
images_crop=np_crops
# after
images_crop=torch.from_numpy(np_crops)
Defensive patterns

Strategy: type-guard

Validate before calling

assert images_crop is None or isinstance(images_crop, (torch.Tensor, list))

Type guard

def valid_crop(c):
    return c is None or isinstance(c, (torch.Tensor, list))

Prevention

When it happens

Trigger: Passing images_crop of an unsupported type (e.g. numpy) with image inputs to UnlimitedOCR's get_multimodal_embeddings.

Common situations: Manual multimodal input construction bypassing the processor; format drift between preprocessing and serving layers.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/61b433f3bf6677cc. Report an issue: GitHub.