{"record":{"id":"2a11868d1b2579f6","repo":"huggingface/transformers","slug":"eos-token-id-has-to-be-a-list-of-positive-intege","errorCode":null,"errorMessage":"`eos_token_id` has to be a list of positive integers, but is {eos_token_id}","messagePattern":"`eos_token_id` has to be a list of positive integers, but is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":1645,"sourceCode":"\n    >>> # `forced_eos_token_id` ensures the generation ends with a EOS token\n    >>> outputs = model.generate(**inputs, max_new_tokens=10, forced_eos_token_id=tokenizer.eos_token_id)\n    >>> print(tokenizer.batch_decode(outputs)[0])\n    A sequence: 1, 2, 3, 4, 5, 6, 7,<|endoftext|>\n    ```\n    \"\"\"\n\n    def __init__(self, max_length: int, eos_token_id: int | list[int] | torch.Tensor, device: str = \"cpu\"):\n        self.max_length = max_length\n\n        if not isinstance(eos_token_id, torch.Tensor):\n            if isinstance(eos_token_id, int):\n                eos_token_id = [eos_token_id]\n            eos_token_id = torch.tensor(eos_token_id, device=device)\n        self.eos_token_id = eos_token_id\n\n        if torch.is_floating_point(eos_token_id) or (eos_token_id < 0).any():\n            raise ValueError(f\"`eos_token_id` has to be a list of positive integers, but is {eos_token_id}\")\n\n    @add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        cur_len = input_ids.shape[-1]\n        scores_processed = scores\n        if cur_len == self.max_length - 1:\n            scores_processed = torch.full_like(scores, -math.inf)\n            scores_processed[:, self.eos_token_id] = 0\n        return scores_processed\n\n\nclass InfNanRemoveLogitsProcessor(LogitsProcessor):\n    r\"\"\"\n    [`LogitsProcessor`] that removes all `nan` and `inf` values to avoid the generation method to fail. Note that using\n    the logits processor should only be used if necessary since it can slow down the generation method.\n\n    This logits processor has no `generate` example, as there shouldn't be a correct combination of flags that warrants\n    its use.","sourceCodeStart":1627,"sourceCodeEnd":1663,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L1627-L1663","documentation":"Error \"`eos_token_id` has to be a list of positive integers, but is {eos_token_id}\" thrown in huggingface/transformers.","triggerScenarios":"Raised in ForcedEOSTokenLogitsProcessor.__init__ when eos_token_id is not a positive integer or list of positive integers.","commonSituations":"Passing eos_token_id=None, a negative id, or an unparsed string id when forcing EOS at max_length.","solutions":["Pass `eos_token_id` as a list of positive integers, e.g. `[tokenizer.eos_token_id]`.","Use `generation_config.eos_token_id` which is normalized to a list automatically."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}