sgl-project/sglang · error · ValueError
Incorrect type of pixel values. Got type: {type(pixel_values
Error message
Incorrect type of pixel values. Got type: {type(pixel_values)} What it means
_parse_and_validate_image_input requires pixel_values to be a torch.Tensor or list; anything else (numpy array, None-with-flag, string) is rejected before encoding.
Source
Thrown at python/sglang/srt/models/unlimited_ocr.py:183
def _parse_and_validate_image_input(self, **kwargs: object):
"""Parse and validate pixel values, spatial crops, and image crops."""
pixel_values = kwargs.pop("pixel_values", None)
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,View on GitHub (pinned to 0132848349)
Solutions
- Convert numpy arrays with torch.from_numpy(...).to(device) before calling
- Pass None when there are no images so the earlier branch skips encoding
- Ensure the input dict keys match what the scheduler provides
Example fix
# before model.get_multimodal_embeddings(pixel_values=np_imgs, ...) # after model.get_multimodal_embeddings(pixel_values=torch.from_numpy(np_imgs), ...)
Defensive patterns
Strategy: type-guard
Validate before calling
assert pixel_values is None or isinstance(pixel_values, (torch.Tensor, list)), type(pixel_values)
Type guard
def valid_pixels(p):
return p is None or isinstance(p, (torch.Tensor, list)) Prevention
- Convert numpy to torch at the preprocessing boundary
- Use the built-in multimodal processor
When it happens
Trigger: Passing pixel_values as np.ndarray or another type into get_multimodal_embeddings of UnlimitedOCR.
Common situations: Feeders/preprocessors producing numpy arrays; intermediate layers forwarding the wrong field; None handled by earlier branches so unexpected types slip through.
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 image sizes. Got type: {type(images_spatia
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/8d5bfe6790e493dd.
Report an issue: GitHub.