sgl-project/sglang · error · ValueError
You have to specify pixel_values or pixel_embeds
Error message
You have to specify pixel_values or pixel_embeds
What it means
InternVL vision model forward requires exactly one of pixel_values or pixel_embeds. Passing neither leaves the vision tower with no input, so it fails fast with this HF-transformers-style check.
Source
Thrown at python/sglang/srt/models/internvl.py:473
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
pixel_embeds: Optional[torch.FloatTensor] = None,
) -> Union[Tuple, BaseModelOutputWithPooling]:
pixel_values = pixel_values.to(device=self.device, dtype=self.dtype)
output_hidden_states = (
output_hidden_states
if output_hidden_states is not None
else self.config.output_hidden_states
)
return_dict = (
return_dict if return_dict is not None else self.config.use_return_dict
)
if pixel_values is None and pixel_embeds is None:
raise ValueError("You have to specify pixel_values or pixel_embeds")
if pixel_embeds is not None:
hidden_states = pixel_embeds
else:
if len(pixel_values.shape) == 4:
hidden_states = self.embeddings(pixel_values)
else:
raise ValueError(f"wrong pixel_values size: {pixel_values.shape}")
if self.use_data_parallel:
encoder_outputs = run_dp_sharded_vision_model(hidden_states, self.encoder)
last_hidden_state = encoder_outputs
else:
encoder_outputs = self.encoder(
inputs_embeds=hidden_states,
output_hidden_states=output_hidden_states,
return_dict=return_dict,
)View on GitHub (pinned to 0132848349)
Solutions
- Ensure the request actually carries an image and that pixel_values is produced by the processor
- Skip the vision tower entirely for text-only batches
- If you already have embedded features, pass pixel_embeds instead
Example fix
# before
outputs = model.vision_model(pixel_values=None, pixel_embeds=None)
# after
if pixel_values is None and pixel_embeds is None:
return None # text-only path
outputs = model.vision_model(pixel_values=pixel_values) Defensive patterns
Strategy: type-guard
Validate before calling
if pixel_values is None and pixel_embeds is None:
raise SKIP("text-only request; skip vision tower") Type guard
def has_vision_input(pixel_values, pixel_embeds) -> bool:
return pixel_values is not None or pixel_embeds is not None Try / catch
try:
out = vision.forward(pixel_values=pv, pixel_embeds=pe)
except ValueError as e:
if "pixel_values or pixel_embeds" in str(e):
return None # degrade to text-only
raise Prevention
- Route text-only requests around the multimodal branch
- Verify processor output is non-empty before calling the vision model
When it happens
Trigger: InternVisionModel.forward(pixel_values=None, pixel_embeds=None) — calling the vision tower with only attention_mask or empty multimodal inputs.
Common situations: Text-only requests routed to the multimodal path, missing image preprocessing, or custom pipelines calling the encoder directly without checking inputs.
Related errors
- 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)}
- Image aspect ratio must be smaller than 200
- wrong pixel_values size: {pixel_values.shape}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/c4cd8950e68cb6dc.
Report an issue: GitHub.