sgl-project/sglang · error · ValueError
input_ids must be 1-D, got {list(input_ids.shape)}
Error message
input_ids must be 1-D, got {list(input_ids.shape)} What it means
encode_ids requires a 1-D input_ids tensor (a single flattened sequence). Passing batched (2-D) or higher-rank token id tensors raises this immediately.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py:339
output_hidden_states=False,
return_dict=True,
use_cache=False,
**kwargs,
)
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
)View on GitHub (pinned to 0132848349)
Solutions
- Squeeze/flatten: input_ids = input_ids.reshape(-1) or input_ids[0] before calling encode_ids
- Loop over the batch, calling encode_ids once per sequence
Example fix
# before out = encoder.encode_ids(tokenizer(...)["input_ids"]) # shape [1, N] # after ids = tokenizer(...)["input_ids"].reshape(-1) out = encoder.encode_ids(ids)
Defensive patterns
Strategy: type-guard
Validate before calling
assert input_ids.dim() == 1, f"need 1-D ids, got {tuple(input_ids.shape)}" Type guard
def is_flat_ids(t: torch.Tensor) -> bool:
return isinstance(t, torch.Tensor) and t.dim() == 1 Prevention
- Standardize on flattened ids at your call boundary (reshape(-1))
- Wrap tokenizer outputs with a squeeze helper
When it happens
Trigger: Calling encode_ids(input_ids) with input_ids.dim() != 1, e.g. a [1, seq_len] batched tensor straight from a tokenizer with return_tensors='pt'.
Common situations: Feeding tokenizer output shaped (batch, seq) without squeezing; adapting code from batched encoders like Qwen3VLForConditionalGeneration which use 2-D inputs.
Related errors
- x must be [1, S, C], got {list(x.shape)}
- pixel_values and image_grid_thw must be given together
- pixel_values_videos and video_grid_thw must be given togethe
- unexpected hidden shape {list(hidden.shape)}, expected {expe
- fl2va requires first_frame, last_frame, or both
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/65b799c2af9b2400.
Report an issue: GitHub.