{"record":{"id":"2a979f33d469c116","repo":"oobabooga/textgen","slug":"tfs-has-to-be-a-float-0-and-1-but-is-tfs","errorCode":null,"errorMessage":"`tfs` has to be a float >= 0 and <= 1, but is {tfs}","messagePattern":"`tfs` has to be a float >= 0 and <= 1, but is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/sampler_hijack.py","lineNumber":136,"sourceCode":"        diff = scores - max_logit\n        k = (3 - self.smoothing_curve) / 2\n        s = (self.smoothing_curve - 1) / 2\n\n        # Apply transformation to non-negative infinity values\n        transformed_logits = torch.where(\n            scores != float('-inf'),\n            -(k * self.smoothing_factor * diff**2) + (s * self.smoothing_factor * diff**3) + max_logit,\n            scores\n        )\n\n        return transformed_logits\n\n\nclass TailFreeLogitsWarper(LogitsProcessor):\n    def __init__(self, tfs: float, filter_value: float = -float(\"Inf\"), min_tokens_to_keep: int = 1):\n        tfs = float(tfs)\n        if tfs < 0 or tfs > 1.0:\n            raise ValueError(f\"`tfs` has to be a float >= 0 and <= 1, but is {tfs}\")\n        self.tfs = tfs\n        self.filter_value = filter_value\n        self.min_tokens_to_keep = min_tokens_to_keep\n\n    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:\n        sorted_logits, sorted_indices = torch.sort(scores, descending=True)\n        probs = sorted_logits.softmax(dim=-1)\n\n        # Compute second derivative normalized CDF\n        d2 = probs.diff().diff().abs()\n        normalized_d2 = d2 / d2.sum(dim=-1, keepdim=True)\n        normalized_d2_cdf = normalized_d2.cumsum(dim=-1)\n\n        # Remove tokens with CDF value above the threshold (token with 0 are kept)\n        sorted_indices_to_remove = normalized_d2_cdf > self.tfs\n\n        # Centre the distribution around the cutoff as in the original implementation of the algorithm\n        sorted_indices_to_remove = torch.cat(","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/sampler_hijack.py#L118-L154","documentation":"Error \"`tfs` has to be a float >= 0 and <= 1, but is {tfs}\" thrown in oobabooga/textgen.","triggerScenarios":"Raised during sampler validation when the `tfs` (tail-free sampling) parameter is outside the range [0, 1]. Triggers when tfs is set negative or greater than 1 in generation settings.","commonSituations":"See trigger scenarios.","solutions":["Set tfs (tail free sampling) to a float between 0 and 1 inclusive; use 1.0 to disable it."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}