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
Companion guard to 5637: images_spatial_crop must be a torch.Tensor or list; other types raise with the offending type in the message.
Source
Thrown at python/sglang/srt/models/unlimited_ocr.py:187
images_spatial_crop = kwargs.pop("images_spatial_crop", None)
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,
has_local_crops: Optional[List[bool]] = None,
) -> NestedTensors:View on GitHub (pinned to 0132848349)
Solutions
- Ensure the processor supplies images_spatial_crop as tensor/list alongside pixel_values
- Convert numpy inputs to torch tensors
- Use the standard sglang multimodal processor path instead of manual payloads
Example fix
# before spatial_crop=np.array([[2,2]]) # after spatial_crop=torch.tensor([[2,2]])
Defensive patterns
Strategy: type-guard
Validate before calling
assert images_spatial_crop is None or isinstance(images_spatial_crop, (torch.Tensor, list))
Type guard
def valid_spatial_crop(s):
return s is None or isinstance(s, (torch.Tensor, list)) Prevention
- Build all image fields through one processor call
- Type-check payloads in tests
When it happens
Trigger: Supplying images_spatial_crop as numpy array or omitted/wrong object while pixel_values is present.
Common situations: Custom request payloads lacking spatial crop metadata or providing numpy formats; processor version changes renaming the field.
Related errors
- {field_name} must be a tensor, list of tensors, list of sequ
- Incorrect type of pixel values. Got type: {type(pixel_values
- Incorrect type of image sizes. Got type: {type(images_spatia
- Incorrect type of image crop. Got type: {type(images_crop)}
- Incorrect type of pixel values. Got type: {type(pixel_values
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/38a23ceb3d10f55a.
Report an issue: GitHub.