2noise/ChatTTS · error · ValueError

n must be at least 1, got {self.n}.

Error message

n must be at least 1, got {self.n}.

What it means

SamplingParams._verify_args, run from __init__, rejects n < 1. n is the number of output sequences to generate per prompt; it must be a positive integer.

Source

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

        self.skip_special_tokens = skip_special_tokens
        self.spaces_between_special_tokens = spaces_between_special_tokens
        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}."

View on GitHub (pinned to 77b89ee281)

Solutions

  1. Pass n=1 (the minimum) or higher
  2. If n is derived from user/config input, clamp or validate it before constructing SamplingParams

Example fix

# before
params = SamplingParams(n=0)

# after
params = SamplingParams(n=1)
Defensive patterns

Strategy: validation

Validate before calling

def valid_n(n) -> bool:
    return isinstance(n, int) and n >= 1

Type guard

def is_valid_n(n) -> bool:
    return isinstance(n, int) and not isinstance(n, bool) and n >= 1

Prevention

When it happens

Trigger: Constructing SamplingParams with n=0, a negative n, or a value that compares below 1 (e.g. n=0.5 via typo).

Common situations: Computing n from user input or a loop counter that can be 0; passing num_return_sequences=0 through from a config; defaulting n to 0 instead of 1.

Related errors


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