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
Raised by DeepseekOCRModel._parse_and_validate_image_input when the pixel_values field of the multimodal input items is neither a torch.Tensor nor a list. The model's vision encoder requires pixel tensors produced by the processor, and any other Python type indicates the input payload was assembled incorrectly.
Source
Thrown at python/sglang/srt/models/deepseek_ocr.py:1604
def _parse_and_validate_image_input(self, **kwargs: object):
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.")
View on GitHub (pinned to 0132848349)
Solutions
- Convert pixel_values with torch.as_tensor(pixel_values, dtype=torch.bfloat16/torch.float32) before calling the API
- Generate inputs via the model's processor (processor(images=..., return_tensors='pt')) so pixel_values is already a torch.Tensor
- If passing a list, ensure it is a flat list of per-image tensors, not nested Python lists of numbers or dicts
- Check that pixel_values was not double-wrapped (e.g. {'pixel_values': {'pixel_values': ...}}) by an extra payload layer
Example fix
// before
mm_kwargs = {"pixel_values": np.asarray(img)} # numpy -> ValueError
// after
mm_kwargs = {"pixel_values": torch.from_numpy(np.asarray(img))} Defensive patterns
Strategy: type-guard
Validate before calling
pv = mm_kwargs.get("pixel_values")
assert isinstance(pv, (torch.Tensor, list)) and pv is not None, "pixel_values must be tensor/list" Type guard
def is_valid_pixel_values(v) -> bool:
return isinstance(v, (torch.Tensor, list)) and (
isinstance(v, torch.Tensor) or all(isinstance(t, torch.Tensor) for t in v)
) Prevention
- Always derive multimodal inputs from the model's processor(...) output
- Run an isinstance check on pixel_values before calling get_multimodal_embeddings
When it happens
Trigger: Calling get_multimodal_embeddings (or a serving path that routes through it) with mm_item_kwargs/imaging data whose pixel_values key holds a numpy array, PIL Image, string, dict, or None mixed with non-empty content, so the isinstance((torch.Tensor, list)) check fails.
Common situations: Passing raw numpy arrays instead of tensors, building multimodal prompts by hand instead of using the HF processor output, feeding an incompatible processor version, or a custom client serializing images to lists of lists that get decoded into dicts.
Related errors
- Incorrect type of image sizes. Got type: {type(images_spatia
- Incorrect type of image crop. Got type: {type(images_crop)}
- {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/005df15781cb72dc.
Report an issue: GitHub.