2noise/ChatTTS · error · ValueError
best_of must be greater than or equal to n, got n={self.n} a
Error message
best_of must be greater than or equal to n, got n={self.n} and best_of={self.best_of}. What it means
SamplingParams._verify_args requires best_of >= n. best_of is the total number of sequences to generate (the top n of which are returned), so it cannot be smaller than the number of returned sequences.
Source
Thrown at ChatTTS/model/velocity/sampling_params.py:184
self.logits_processors = logits_processors
self.include_stop_str_in_output = include_stop_str_in_output
self._verify_args()
if self.use_beam_search:
self._verify_beam_search()
else:
self._verify_non_beam_search()
# if self.temperature < _SAMPLING_EPS:
# # Zero temperature means greedy sampling.
# self.top_p = 1.0
# self.top_k = -1
# self.min_p = 0.0
# self._verify_greedy_sampling()
def _verify_args(self) -> None:
if self.n < 1:
raise ValueError(f"n must be at least 1, got {self.n}.")
if self.best_of < self.n:
raise ValueError(
f"best_of must be greater than or equal to n, "
f"got n={self.n} and best_of={self.best_of}."
)
if not -2.0 <= self.presence_penalty <= 2.0:
raise ValueError(
"presence_penalty must be in [-2, 2], got " f"{self.presence_penalty}."
)
if not -2.0 <= self.frequency_penalty <= 2.0:
raise ValueError(
"frequency_penalty must be in [-2, 2], got "
f"{self.frequency_penalty}."
)
if not 0.0 < self.repetition_penalty <= 2.0:
raise ValueError(
"repetition_penalty must be in (0, 2], got "
f"{self.repetition_penalty}."
)
# if self.temperature < 0.0:View on GitHub (pinned to 77b89ee281)
Solutions
- Set best_of equal to or greater than n (or omit best_of — it defaults to n)
- If you only want n sequences returned, drop best_of entirely
Example fix
# before params = SamplingParams(n=4, best_of=2) # after params = SamplingParams(n=4) # best_of defaults to n
Defensive patterns
Strategy: validation
Validate before calling
def normalize(best_of, n):
return max(best_of, n) if best_of is not None else n Prevention
- Omit best_of unless you specifically need extra candidates
- Assert best_of >= n before constructing params
When it happens
Trigger: Constructing SamplingParams with best_of less than n, e.g. SamplingParams(n=4, best_of=2). Note best_of defaults to n, so this only fires when best_of is set explicitly below n.
Common situations: Copying OpenAI-style params where best_of/n semantics differ; tuning configs and shrinking best_of while forgetting n; swapping the two arguments.
Related errors
- n must be at least 1, got {self.n}.
- presence_penalty must be in [-2, 2], got {self.presence_pena
- frequency_penalty must be in [-2, 2], got {self.frequency_pe
- repetition_penalty must be in (0, 2], got {self.repetition_p
- top_k must be -1 (disable), or at least 1, got {self.top_k}.
AI-assisted analysis of 2noise/ChatTTS@77b89ee281 (2026-08-26).
Data as JSON: /api/errors/770bf8496f4aa44a.
Report an issue: GitHub.