{"record":{"id":"962119dcd15defb5","repo":"huggingface/transformers","slug":"eta-cutoff-has-to-be-a-float-0-and-1-but-is","errorCode":null,"errorMessage":"`eta_cutoff` has to be a float > 0 and < 1, but is {epsilon}","messagePattern":"`eta_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":994,"sourceCode":"    A sequence: 1, 2, 3 | < 4 (left-hand pointer) ;\n    <BLANKLINE>\n    <BLANKLINE>\n\n    >>> # With eta sampling, the output gets restricted to high-probability tokens. You can see it as a dynamic form of\n    >>> # epsilon sampling that adapts its cutoff probability based on the entropy (high entropy = lower cutoff).\n    >>> # Pro tip: The paper recommends using `eta_cutoff` values between 3e-4 to 4e-3\n    >>> outputs = model.generate(**inputs, do_sample=True, eta_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__(\n        self, epsilon: float, filter_value: float = -float(\"Inf\"), min_tokens_to_keep: int = 1, device: str = \"cpu\"\n    ):\n        epsilon = float(epsilon)\n        if epsilon <= 0 or epsilon >= 1:\n            raise ValueError(f\"`eta_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 = torch.tensor(epsilon, device=device)\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        probabilities = scores.softmax(dim=-1)\n        entropy = torch.distributions.Categorical(logits=scores).entropy()\n        eta = torch.min(self.epsilon, torch.sqrt(self.epsilon) * torch.exp(-entropy))[..., None]\n        indices_to_remove = probabilities < eta\n","sourceCodeStart":976,"sourceCodeEnd":1012,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L976-L1012","documentation":"Thrown by EtaLogitsWarper.__init__ when epsilon is <= 0 or >= 1. Eta sampling sets a dynamic probability floor min(epsilon, sqrt(epsilon)*exp(-entropy)), so the parameter must be strictly inside (0, 1). It is coerced with float() and stored as a torch tensor on the given device.","triggerScenarios":"EtaLogitsWarper(0.0); eta_cutoff=1.0; model.generate(do_sample=True, eta_cutoff=0) intending 'disabled' (recommended practical range is 3e-4 to 4e-3).","commonSituations":"Using 0 as an 'off' sentinel (raises here — omit the parameter instead); configs ported from epsilon_cutoff with out-of-range values; percentage-style input.","solutions":["To disable eta sampling, remove eta_cutoff from the generate call / generation config","Otherwise pass a small float in (0, 1): eta_cutoff=3e-4","Validate 0 < eta_cutoff < 1 before generate()"],"exampleFix":"# before\nout = model.generate(**inputs, do_sample=True, eta_cutoff=0)  # ValueError\n\n# after\nout = model.generate(**inputs, do_sample=True)  # disabled by omission\n# or:\nout = model.generate(**inputs, do_sample=True, eta_cutoff=3e-4)","handlingStrategy":"validation","validationCode":"def valid_eta(e):\n    return isinstance(e, (int, float)) and 0.0 < float(e) < 1.0","typeGuard":"def is_valid_eta(e) -> bool:\n    return isinstance(e, (int, float)) and 0.0 < e < 1.0","tryCatchPattern":"try:\n    proc = EtaLogitsWarper(float(e), device=inputs['input_ids'].device.type)\nexcept ValueError as e:\n    raise ValueError(f'eta_cutoff={e!r} must be in (0, 1); omit it to disable') from e","preventionTips":["Recommended range is 3e-4 to 4e-3","Omit eta_cutoff to disable — 0 and 1 both raise","Pass the generation device when constructing directly"],"tags":["generation","eta-sampling","cutoff","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}