sgl-project/sglang · error · ValueError
pixel_values_videos and video_grid_thw must be given togethe
Error message
pixel_values_videos and video_grid_thw must be given together
What it means
Same pairing rule as images but for video: pixel_values_videos and video_grid_thw must be given together or both omitted. Video patch interpretation needs the grid tensor.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py:343
)
return BaseEncoderOutput(last_hidden_state=outputs.last_hidden_state)
@torch.no_grad()
def encode_ids(
self,
input_ids: torch.Tensor,
*,
pixel_values: torch.Tensor | None = None,
image_grid_thw: torch.Tensor | None = None,
pixel_values_videos: torch.Tensor | None = None,
video_grid_thw: torch.Tensor | None = None,
) -> torch.Tensor:
if input_ids.dim() != 1:
raise ValueError(f"input_ids must be 1-D, got {list(input_ids.shape)}")
if (pixel_values is None) != (image_grid_thw is None):
raise ValueError("pixel_values and image_grid_thw must be given together")
if (pixel_values_videos is None) != (video_grid_thw is None):
raise ValueError(
"pixel_values_videos and video_grid_thw must be given together"
)
host_ids = input_ids.to(device="cpu", dtype=torch.long)[None]
host_image_grid_thw = (
image_grid_thw.to(device="cpu", dtype=torch.long)
if image_grid_thw is not None
else None
)
host_video_grid_thw = (
video_grid_thw.to(device="cpu", dtype=torch.long)
if video_grid_thw is not None
else None
)
position_ids = None
if host_image_grid_thw is not None or host_video_grid_thw is not None:
position_ids, _ = self.model.get_rope_index(
host_ids,View on GitHub (pinned to 0132848349)
Solutions
- Pass video_grid_thw together with pixel_values_videos from the processor output
- Omit both when the sequence has no video
Example fix
# before hidden = enc.encode_ids(ids, pixel_values_videos=pvv) # after hidden = enc.encode_ids(ids, pixel_values_videos=pvv, video_grid_thw=video_thw)
Defensive patterns
Strategy: validation
Validate before calling
assert (pixel_values_videos is None) == (video_grid_thw is None)
Prevention
- Pass processor outputs wholesale rather than cherry-picking tensors
- Cover video paths in unit tests to catch dropped grid tensors
When it happens
Trigger: encode_ids(..., pixel_values_videos=v) without video_grid_thw, or vice versa.
Common situations: Video-only or mixed image/video call sites where one of the two processor outputs was dropped during refactoring.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- pixel_values and image_grid_thw must be given together
- input_ids must be 1-D, got {list(input_ids.shape)}
- unexpected hidden shape {list(hidden.shape)}, expected {expe
- conditions[{index}]: video references are not supported in v
- fl2va requires first_frame, last_frame, or both
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/ee823f12f2c429bc.
Report an issue: GitHub.