oobabooga/textgen · error · ValueError
`tfs` has to be a float >= 0 and <= 1, but is {tfs}
Error message
`tfs` has to be a float >= 0 and <= 1, but is {tfs} What it means
Error "`tfs` has to be a float >= 0 and <= 1, but is {tfs}" thrown in oobabooga/textgen.
Source
Thrown at modules/sampler_hijack.py:136
diff = scores - max_logit
k = (3 - self.smoothing_curve) / 2
s = (self.smoothing_curve - 1) / 2
# Apply transformation to non-negative infinity values
transformed_logits = torch.where(
scores != float('-inf'),
-(k * self.smoothing_factor * diff**2) + (s * self.smoothing_factor * diff**3) + max_logit,
scores
)
return transformed_logits
class TailFreeLogitsWarper(LogitsProcessor):
def __init__(self, tfs: float, filter_value: float = -float("Inf"), min_tokens_to_keep: int = 1):
tfs = float(tfs)
if tfs < 0 or tfs > 1.0:
raise ValueError(f"`tfs` has to be a float >= 0 and <= 1, but is {tfs}")
self.tfs = tfs
self.filter_value = filter_value
self.min_tokens_to_keep = min_tokens_to_keep
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
sorted_logits, sorted_indices = torch.sort(scores, descending=True)
probs = sorted_logits.softmax(dim=-1)
# Compute second derivative normalized CDF
d2 = probs.diff().diff().abs()
normalized_d2 = d2 / d2.sum(dim=-1, keepdim=True)
normalized_d2_cdf = normalized_d2.cumsum(dim=-1)
# Remove tokens with CDF value above the threshold (token with 0 are kept)
sorted_indices_to_remove = normalized_d2_cdf > self.tfs
# Centre the distribution around the cutoff as in the original implementation of the algorithm
sorted_indices_to_remove = torch.cat(View on GitHub (pinned to ed888c71f2)
Solutions
- Set tfs (tail free sampling) to a float between 0 and 1 inclusive; use 1.0 to disable it.
When it happens
Trigger: 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.
Common situations: See trigger scenarios.
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/2a979f33d469c116.
Report an issue: GitHub.