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
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.
Source
Thrown at python/sglang/srt/models/deepseek_ocr.py:1615
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:
# Pixel_values (global view): [n_image, batch_size, 3, height, width]
# images_spatial_crop: [n_image, batch_size, [num_tiles_w, num_tiles_h]]
# images_crop (local view): [n_image, batch_size, num_pathes, 3, h, w]View on GitHub (pinned to 0132848349)
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
Example fix
// before
inputs = {"pixel_values": pv, "images_spatial_crop": sc, "images_crop": crop_dict}
// after
inputs = {"pixel_values": pv, "images_spatial_crop": sc,
"images_crop": torch.tensor(crop_dict["boxes"])} Defensive patterns
Strategy: type-guard
Validate before calling
crop = mm_kwargs.get("images_crop")
assert isinstance(crop, (torch.Tensor, list)), "images_crop must be tensor/list" Type guard
def is_valid_images_crop(v) -> bool:
return isinstance(v, (torch.Tensor, list)) Prevention
- Validate all three fields (pixel_values, images_crop, images_spatial_crop) together before the call
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Incorrect type of pixel values. Got type: {type(pixel_values
- Incorrect type of image sizes. Got type: {type(images_spatia
- {field_name} must be a tensor, list of tensors, list of sequ
- Image aspect ratio must be smaller than 200
- You have to specify pixel_values or pixel_embeds
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/9984ba25f3aac570.
Report an issue: GitHub.