{"record":{"id":"bb47ea0fc6890110","repo":"huggingface/transformers","slug":"arg-name-has-to-be-a-positive-integer-but-is","errorCode":null,"errorMessage":"`{arg_name}` has to be a positive integer, but is {arg_value}","messagePattern":"`(.+?)` has to be a positive integer, but is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":215,"sourceCode":"    A number: one thousand\n    ```\n    \"\"\"\n\n    supports_continuous_batching = False\n\n    def __init__(\n        self,\n        prompt_length_to_skip: int,\n        min_new_tokens: int,\n        eos_token_id: int | list[int] | torch.Tensor,\n        device: str = \"cpu\",\n    ):\n        for arg_name, arg_value in [\n            (\"prompt_length_to_skip\", prompt_length_to_skip),\n            (\"min_new_tokens\", min_new_tokens),\n        ]:\n            if not isinstance(arg_value, int) or arg_value < 0:\n                raise ValueError(f\"`{arg_name}` has to be a positive integer, but is {arg_value}\")\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\n        self.prompt_length_to_skip = prompt_length_to_skip\n        self.min_new_tokens = min_new_tokens\n        self.eos_token_id = 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        new_tokens_length = input_ids.shape[-1] - self.prompt_length_to_skip\n        scores_processed = scores.clone()\n        vocab_tensor = torch.arange(scores.shape[-1], device=scores.device)\n        eos_token_mask = torch.isin(vocab_tensor, self.eos_token_id)\n        if new_tokens_length < self.min_new_tokens:\n            scores_processed = torch.where(eos_token_mask, -math.inf, scores)","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L197-L233","documentation":"MinNewTokensLengthLogitsProcessor.__init__ validates prompt_length_to_skip and min_new_tokens: each must be an int and >= 0 (the message says 'positive integer' but the check allows 0 — a minor wording inconsistency in the library). Non-int or negative values are rejected.","triggerScenarios":"Passing min_new_tokens=5.0 (float), prompt_length_to_skip=-1, or string values from config files. prompt_length_to_skip is normally len(prompt_ids) computed by callers; a computed length of -1 from a malformed input_ids slice triggers it.","commonSituations":"argparse/JSON configs without type=int; slicing bugs producing negative lengths; note the message/error mismatch: 0 is actually accepted, so users hunting a 'positive' bug may be misled.","solutions":["Coerce to int: int(min_new_tokens), int(prompt_length_to_skip)","If prompt_length_to_skip is computed, assert it is >= 0 before constructing the processor","Report/ignore the wording: 0 passes; only negative or non-int values fail"],"exampleFix":"# before\nproc = MinNewTokensLengthLogitsProcessor(prompt_length_to_skip=len(ids)-1, min_new_tokens=5.0, eos_token_id=eos)\n\n# after\nproc = MinNewTokensLengthLogitsProcessor(prompt_length_to_skip=max(0, len(ids)), min_new_tokens=5, eos_token_id=eos)","handlingStrategy":"validation","validationCode":"for name, v in [('prompt_length_to_skip', prompt_len), ('min_new_tokens', min_new_tokens)]:\n    assert isinstance(v, int) and not isinstance(v, bool) and v >= 0, f'{name} must be a non-negative int, got {v!r}'","typeGuard":"def is_valid_nonneg_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 0","tryCatchPattern":null,"preventionTips":["Coerce computed lengths with max(0, int(x))","Note the message says 'positive' but 0 is accepted","Use type=int for CLI args"],"tags":["validation","logits-processor","types","error-message"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}