{"record":{"id":"f7da0707ceea9b37","repo":"sgl-project/sglang","slug":"sequence-length-seq-length-exceeds-the-maximum","errorCode":null,"errorMessage":"Sequence length {seq_length} exceeds the maximum {max_positions}.","messagePattern":"Sequence length (.+?) exceeds the maximum (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/clip.py","lineNumber":127,"sourceCode":"            persistent=False,\n        )\n\n    def forward(\n        self,\n        input_ids: Optional[torch.LongTensor] = None,\n        position_ids: Optional[torch.LongTensor] = None,\n        inputs_embeds: Optional[torch.FloatTensor] = None,\n    ) -> torch.Tensor:\n        if input_ids is not None:\n            seq_length = input_ids.shape[-1]\n        elif inputs_embeds is not None:\n            seq_length = inputs_embeds.shape[-2]\n        else:\n            raise ValueError(\"Either input_ids or inputs_embeds must be provided.\")\n\n        max_positions = self.position_embedding.weight.shape[0]\n        if seq_length > max_positions:\n            raise ValueError(\n                f\"Sequence length {seq_length} exceeds the maximum {max_positions}.\"\n            )\n\n        if position_ids is None:\n            position_ids = self.position_ids[:, :seq_length]\n\n        if inputs_embeds is None:\n            inputs_embeds = self.token_embedding(input_ids)\n\n        position_embeddings = self.position_embedding(position_ids)\n        embeddings = inputs_embeds + position_embeddings\n\n        return embeddings\n\n\nclass CLIPMLP(nn.Module):\n\n    def __init__(","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/clip.py#L109-L145","documentation":"CLIP checks the requested sequence length against the position embedding table size (max_position_embeddings). Sequences longer than the learned position table cannot be embedded and are rejected.","triggerScenarios":"Feeding images/text whose token count exceeds config.max_position_embeddings of the CLIP model (e.g. 77 for CLIP text encoders).","commonSituations":"Long prompts or high-resolution patches producing more tokens than the encoder supports; chunking/preprocessing omitted.","solutions":["Truncate/chunk the input so seq_length <= max_positions","Use a model with a larger max_position_embeddings (e.g. Long-CLIP style checkpoint) for long inputs"],"exampleFix":"# before\nemb.forward(input_ids=ids)  # len(ids)=120, max=77\n# after\nemb.forward(input_ids=ids[:77])","handlingStrategy":"validation","validationCode":"assert seq_len <= model.position_embedding.weight.shape[0], \"seq exceeds CLIP max positions\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Truncate inputs to max_position_embeddings before the encoder","Choose long-context CLIP variants for long inputs"],"tags":["clip","sequence-length","input-validation"],"backgroundTag":"input-length-exceeds-limit","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}