{"record":{"id":"7a9548f2c736d3d6","repo":"huggingface/transformers","slug":"epsilon-cutoff-has-to-be-a-float-0-and-1-bu","errorCode":null,"errorMessage":"`epsilon_cutoff` has to be a float > 0 and < 1, but is {epsilon}","messagePattern":"`epsilon_cutoff` has to be a float > 0 and < 1, but is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":911,"sourceCode":"    >>> outputs = model.generate(**inputs, do_sample=True)\n    >>> print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])\n    A sequence: 1, 2, 3 | < 4 (left-hand pointer) ;\n    <BLANKLINE>\n    <BLANKLINE>\n\n    >>> # With epsilon sampling, the output gets restricted to high-probability tokens. Note that this is similar to\n    >>> # Top P sampling, which restricts tokens based on their cumulative probability.\n    >>> # Pro tip: The paper recommends using `epsilon_cutoff` values between 3e-4 and 9e-4\n    >>> outputs = model.generate(**inputs, do_sample=True, epsilon_cutoff=0.1)\n    >>> print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])\n    A sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9\n    ```\n    \"\"\"\n\n    def __init__(self, epsilon: float, filter_value: float = -float(\"Inf\"), min_tokens_to_keep: int = 1):\n        epsilon = float(epsilon)\n        if epsilon <= 0 or epsilon >= 1:\n            raise ValueError(f\"`epsilon_cutoff` has to be a float > 0 and < 1, but is {epsilon}\")\n\n        min_tokens_to_keep = int(min_tokens_to_keep)\n        if min_tokens_to_keep < 1:\n            raise ValueError(\n                f\"`min_tokens_to_keep` has to be a strictly positive integer, but is {min_tokens_to_keep}\"\n            )\n\n        self.epsilon = epsilon\n        self.filter_value = filter_value\n        self.min_tokens_to_keep = min_tokens_to_keep\n\n    @add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        # Determine which indices to remove\n        probabilities = scores.softmax(dim=-1)\n        indices_to_remove = probabilities < self.epsilon\n\n        # Keep the words with the 'min_tokens_to_keep'-highest probabilities","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L893-L929","documentation":"Thrown by EpsilonLogitsWarper.__init__ when epsilon is <= 0 or >= 1. Epsilon sampling removes tokens whose probability is below an absolute threshold epsilon, so it must be strictly inside (0, 1). The constructor coerces with float(epsilon), so ints and numeric strings are accepted if in range.","triggerScenarios":"EpsilonLogitsWarper(0.0); epsilon=1.0; epsilon=-1e-4; model.generate(do_sample=True, epsilon_cutoff=0) where 0 was intended to disable it.","commonSituations":"Using 0 as an 'off' sentinel in configs (here it raises — omit the parameter instead); values outside the paper's recommended 3e-4–9e-4 range by mistake; percentage confusion.","solutions":["To disable epsilon sampling, remove epsilon_cutoff from the generate call / config","Otherwise pass a small float in (0, 1): epsilon_cutoff=3e-4 (recommended 3e-4 to 9e-4)","Validate 0 < epsilon_cutoff < 1 in config-loading code"],"exampleFix":"# before\nout = model.generate(**inputs, do_sample=True, epsilon_cutoff=0)  # 'disable' -> ValueError\n\n# after\nout = model.generate(**inputs, do_sample=True)  # disabled by omission\n# or a valid value:\nout = model.generate(**inputs, do_sample=True, epsilon_cutoff=9e-4)","handlingStrategy":"validation","validationCode":"def valid_epsilon(e):\n    return isinstance(e, (int, float)) and 0.0 < float(e) < 1.0","typeGuard":"def is_valid_epsilon(e) -> bool:\n    return isinstance(e, (int, float)) and 0.0 < e < 1.0","tryCatchPattern":"try:\n    proc = EpsilonLogitsWarper(float(e))\nexcept ValueError as e:\n    raise ValueError(f'epsilon_cutoff={e!r} must be in (0, 1); omit it to disable') from e","preventionTips":["Paper-recommended range is 3e-4 to 9e-4","0 is not an 'off' switch — omit epsilon_cutoff instead","Strictly inside the interval: both endpoints rejected"],"tags":["generation","epsilon-sampling","cutoff","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}