sgl-project/sglang · error · ValueError
Either input_ids or inputs_embeds must be provided.
Error message
Either input_ids or inputs_embeds must be provided.
What it means
CLIP text/position embedding forward requires exactly one of input_ids or inputs_embeds to compute the sequence length. Passing None for both is invalid.
Source
Thrown at python/sglang/srt/models/clip.py:123
# position_ids (1, len position emb) is contiguous in memory and exported when serialized
self.register_buffer(
"position_ids",
torch.arange(config.max_position_embeddings).expand((1, -1)),
persistent=False,
)
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
) -> torch.Tensor:
if input_ids is not None:
seq_length = input_ids.shape[-1]
elif inputs_embeds is not None:
seq_length = inputs_embeds.shape[-2]
else:
raise ValueError("Either input_ids or inputs_embeds must be provided.")
max_positions = self.position_embedding.weight.shape[0]
if seq_length > max_positions:
raise ValueError(
f"Sequence length {seq_length} exceeds the maximum {max_positions}."
)
if position_ids is None:
position_ids = self.position_ids[:, :seq_length]
if inputs_embeds is None:
inputs_embeds = self.token_embedding(input_ids)
position_embeddings = self.position_embedding(position_ids)
embeddings = inputs_embeds + position_embeddings
return embeddings
View on GitHub (pinned to 0132848349)
Solutions
- Pass input_ids (token ids) or precomputed inputs_embeds, never neither
- Fix the upstream caller that failed to supply one of the two tensors
Example fix
# before emb.forward(None, None) # after emb.forward(input_ids=input_ids)
Defensive patterns
Strategy: type-guard
Validate before calling
assert input_ids is not None or inputs_embeds is not None
Type guard
def has_embed_input(ids, embeds) -> bool:
return ids is not None or embeds is not None Try / catch
try: emb.forward(input_ids, inputs_embeds) except ValueError as e: raise UserInputError(str(e))
Prevention
- Always pass token ids through the embedding stage
When it happens
Trigger: Calling CLIPEmbeddings.forward(input_ids=None, inputs_embeds=None).
Common situations: Wrapping CLIP in a custom pipeline where the embedder is skipped and ids are dropped; a bug upstream leaves both None.
Related errors
- You have to specify input_ids
- Sequence length {seq_length} exceeds the maximum {max_positi
- unsupported input for causal Conv3D cat/pad CUDA
- unsupported input for usp_merge_heads CUDA
- unsupported input for modulate_scale_shift CUDA
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/c29e28e310e09167.
Report an issue: GitHub.