sgl-project/sglang · error · ValueError

Incorrect type of image sizes. Got type: {type(images_spatia

Error message

Incorrect type of image sizes. Got type: {type(images_spatial_crop)}

What it means

Raised by _parse_and_validate_image_input in deepseek_ocr.py when images_spatial_crop (the per-image spatial crop/grid metadata) is not a torch.Tensor or list. DeepseekOCR needs the crop grid to slice the image patches, so a wrong type here is fatal.

Source

Thrown at python/sglang/srt/models/deepseek_ocr.py:1609

        images_crop = kwargs.pop("images_crop", None)
        has_images = kwargs.pop("has_images", None)

        if pixel_values is None:
            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,

View on GitHub (pinned to 0132848349)

Solutions

  1. Run the HF processor for the OCR model and pass its image_spatial_crop output unchanged
  2. If building manually, supply images_spatial_crop as a torch tensor or list matching one entry per image
  3. Verify processor and sglang versions are matched (the expected key names changed across releases)

Example fix

// before
inputs = {"pixel_values": pv}  # spatial crop missing -> becomes invalid type

// after
proc_out = processor(images=img, return_tensors="pt")
inputs = {"pixel_values": proc_out["pixel_values"],
          "images_spatial_crop": proc_out["image_spatial_crop"]}
Defensive patterns

Strategy: type-guard

Validate before calling

sc = mm_kwargs.get("images_spatial_crop")
assert isinstance(sc, (torch.Tensor, list)), "images_spatial_crop must be tensor/list"

Type guard

def is_valid_spatial_crop(v) -> bool:
    return isinstance(v, (torch.Tensor, list))

Prevention

When it happens

Trigger: Calling get_multimodal_embeddings with mm_item_kwargs that includes pixel_values but omits or corrupts images_spatial_crop — e.g. it is a numpy array, an int, a dict, or a tensor of wrong nesting — so the isinstance((torch.Tensor, list)) guard fails.

Common situations: Using a processor config that doesn't emit image_spatial_crop, version mismatch between the processor and sglang model code, or hand-built multimodal payloads that skip the crop metadata.

Related errors


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