2noise/ChatTTS · error · ValueError

frequency_penalty must be in [-2, 2], got {self.frequency_pe

Error message

frequency_penalty must be in [-2, 2], got {self.frequency_penalty}.

What it means

SamplingParams._verify_args enforces frequency_penalty in the inclusive range [-2, 2], mirroring the OpenAI API. frequency_penalty penalizes tokens proportionally to how often they already occurred.

Source

Thrown at ChatTTS/model/velocity/sampling_params.py:193

            #     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:
        #     raise ValueError(
        #         f"temperature must be non-negative, got {self.temperature}.")
        if not 0.0 < self.top_p <= 1.0:
            raise ValueError(f"top_p must be in (0, 1], got {self.top_p}.")
        if self.top_k < -1 or self.top_k == 0:
            raise ValueError(
                f"top_k must be -1 (disable), or at least 1, " f"got {self.top_k}."
            )
        if not 0.0 <= self.min_p <= 1.0:

View on GitHub (pinned to 77b89ee281)

Solutions

  1. Clamp frequency_penalty to [-2, 2] before constructing SamplingParams
  2. Validate the value at your API/config boundary

Example fix

# before
params = SamplingParams(frequency_penalty=5.0)

# after
params = SamplingParams(frequency_penalty=1.5)
Defensive patterns

Strategy: validation

Validate before calling

def clamp_penalty(v: float) -> float:
    return min(max(float(v), -2.0), 2.0)

Type guard

def is_valid_penalty(v) -> bool:
    return isinstance(v, (int, float)) and -2.0 <= v <= 2.0

Prevention

When it happens

Trigger: Constructing SamplingParams with frequency_penalty outside [-2.0, 2.0], e.g. 5.0, -2.1, or a value read unvalidated from config.

Common situations: Same shape as presence_penalty: unvalidated request payloads, config typos, porting penalties from libraries with different ranges.

Related errors


AI-assisted analysis of 2noise/ChatTTS@77b89ee281 (2026-08-26). Data as JSON: /api/errors/cb6caab271cd7d8a. Report an issue: GitHub.