{"record":{"id":"1149ee2928ea852b","repo":"sgl-project/sglang","slug":"the-input-ids-input-ids-contains-values-greater","errorCode":null,"errorMessage":"The input_ids {input_ids} contains values greater than the vocab size ({vocab_size}).","messagePattern":"The input_ids (.+?) contains values greater than the vocab size \\((.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/tokenizer_manager.py","lineNumber":1333,"sourceCode":"                    f\"token_ids_logprob contains out-of-vocabulary token id \"\n                    f\"{token_id}; valid range is [0, {vocab_size}).\"\n                )\n\n    def _validate_input_ids_in_vocab(\n        self, input_ids: Union[List[int], List[List[int]]], vocab_size: int\n    ) -> None:\n        # Handle both single sequence and batch of sequences\n        if isinstance(input_ids[0], list):\n            # Batch of sequences\n            for seq in input_ids:\n                if any(id >= vocab_size for id in seq):\n                    raise ValueError(\n                        f\"The input_ids {seq} contains values greater than the vocab size ({vocab_size}).\"\n                    )\n        else:\n            # Single sequence\n            if any(id >= vocab_size for id in input_ids):\n                raise ValueError(\n                    f\"The input_ids {input_ids} contains values greater than the vocab size ({vocab_size}).\"\n                )\n\n    def _create_tokenized_object(\n        self,\n        obj: Union[GenerateReqInput, EmbeddingReqInput],\n        input_text: str,\n        input_ids: Optional[List[int]],\n        input_embeds: Optional[List[List[float]]] = None,\n        mm_inputs=None,\n        token_type_ids: Optional[List[int]] = None,\n    ) -> Union[TokenizedGenerateReqInput, TokenizedEmbeddingReqInput]:\n        \"\"\"Create a tokenized request object from common parameters.\"\"\"\n        input_ids_arr: Optional[array[int]] = (\n            array(\"q\", input_ids) if input_ids is not None else None\n        )\n        # Parse sampling parameters\n        # Note: if there are preferred sampling params, we use them if they are not","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/tokenizer_manager.py#L1315-L1351","documentation":"Raised by _validate_input_ids_in_vocab when a single pre-tokenized input_ids sequence contains an id >= vocab_size. Same guard as the batch path, applied to the flat list form.","triggerScenarios":"Sending GenerateReqInput(input_ids=[...]) where any id exceeds or equals the served model's vocab size (note: negative ids pass this check but typically fail earlier/elsewhere).","commonSituations":"Using input_ids produced by a different tokenizer version, manual id arithmetic overflowing, LoRA/merged-vocab mismatches.","solutions":["Verify ids against the served model: assert max(input_ids) < vocab_size","Re-encode the original text with the current tokenizer","Avoid copying token ids between models"],"exampleFix":"# before\nresp = client.generate(input_ids=[131072, 11], sampling_params={...})\n# after\nresp = client.generate(input_ids=tokenizer.encode(prompt), sampling_params={...})","handlingStrategy":"validation","validationCode":"assert max(input_ids, default=0) < vocab_size, f'{max(input_ids)} >= {vocab_size}'","typeGuard":"def ids_in_vocab(ids, vocab): return all(0 <= i < vocab for i in ids)","tryCatchPattern":"except ValueError as e: if 'vocab size' in str(e): re-encode text and retry","preventionTips":["Never copy ids across models/tokenizers","Assert max id < vocab before submit"],"tags":["sglang","input-ids","vocab","validation"],"backgroundTag":"token-id-out-of-vocabulary","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}