sgl-project/sglang · error · ValueError

You have to specify input_ids

Error message

You have to specify input_ids

What it means

Thrown by CLIPTextModel.forward when input_ids is None. The text transformer requires token IDs to build embeddings; unlike some HF models this implementation does not accept inputs_embeds as an alternative, so calling forward without input_ids is invalid.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/encoders/clip.py:81

        # For `pooled_output` computation
        self.eos_token_id = config.eos_token_id

    def forward(
        self,
        input_ids: torch.Tensor | None,
        position_ids: torch.Tensor | None = None,
        attention_mask: torch.Tensor | None = None,
        inputs_embeds: torch.Tensor | None = None,
        output_hidden_states: bool | None = None,
    ) -> BaseEncoderOutput:
        output_hidden_states = (
            output_hidden_states
            if output_hidden_states is not None
            else self.config.output_hidden_states
        )

        if input_ids is None:
            raise ValueError("You have to specify input_ids")

        input_shape = input_ids.size()
        input_ids = input_ids.view(-1, input_shape[-1])

        hidden_states = self.embeddings(input_ids=input_ids, position_ids=position_ids)

        attention_mask = prepare_clip_attention_mask(
            input_shape,
            hidden_states.dtype,
            hidden_states.device,
            attention_mask,
        )

        encoder_outputs = self.encoder(
            inputs_embeds=hidden_states,
            return_all_hidden_states=output_hidden_states,
            attention_mask=attention_mask,
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass a valid input_ids tensor of shape (batch, seq_len) to forward()
  2. If you have precomputed embeddings, add them to inputs_embeds handling yourself or subclass to skip the embedding step
  3. Check caller kwargs for typos/misrouting that leave input_ids unset

Example fix

# before
out = model(attention_mask=mask)
# after
out = model(input_ids=token_ids, attention_mask=mask)
Defensive patterns

Strategy: validation

Validate before calling

assert input_ids is not None and input_ids.dim() >= 2, "input_ids required with shape (batch, seq_len)"

Type guard

def has_input_ids(kwargs) -> bool:
    return isinstance(kwargs.get("input_ids"), torch.Tensor)

Try / catch

try:
    out = model(input_ids=ids)
except ValueError as e:
    if "input_ids" in str(e):
        raise ValueError(f"Missing token ids for batch: {e}") from e
    raise

Prevention

When it happens

Trigger: Calling encoder forward (directly or via a pipeline) with input_ids=None, e.g. passing only attention_mask or pixel_values; forwarding **kwargs that swallow input_ids due to a misnamed key.

Common situations: Adapting CLIP for multimodal pipelines where embeddings were precomputed upstream; refactoring from HF CLIPTextModel which accepts inputs_embeds; key typos like input_ids vs input_id in caller code.

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


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/7364d7fda715d7e0. Report an issue: GitHub.