{"record":{"id":"ee424eff3e7c855d","repo":"2noise/ChatTTS","slug":"n-must-be-at-least-1-got-self-n","errorCode":null,"errorMessage":"n must be at least 1, got {self.n}.","messagePattern":"n must be at least 1, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ChatTTS/model/velocity/sampling_params.py","lineNumber":182,"sourceCode":"        self.skip_special_tokens = skip_special_tokens\n        self.spaces_between_special_tokens = spaces_between_special_tokens\n        self.logits_processors = logits_processors\n        self.include_stop_str_in_output = include_stop_str_in_output\n        self._verify_args()\n        if self.use_beam_search:\n            self._verify_beam_search()\n        else:\n            self._verify_non_beam_search()\n            # if self.temperature < _SAMPLING_EPS:\n            #     # Zero temperature means greedy sampling.\n            #     self.top_p = 1.0\n            #     self.top_k = -1\n            #     self.min_p = 0.0\n            #     self._verify_greedy_sampling()\n\n    def _verify_args(self) -> None:\n        if self.n < 1:\n            raise ValueError(f\"n must be at least 1, got {self.n}.\")\n        if self.best_of < self.n:\n            raise ValueError(\n                f\"best_of must be greater than or equal to n, \"\n                f\"got n={self.n} and best_of={self.best_of}.\"\n            )\n        if not -2.0 <= self.presence_penalty <= 2.0:\n            raise ValueError(\n                \"presence_penalty must be in [-2, 2], got \" f\"{self.presence_penalty}.\"\n            )\n        if not -2.0 <= self.frequency_penalty <= 2.0:\n            raise ValueError(\n                \"frequency_penalty must be in [-2, 2], got \"\n                f\"{self.frequency_penalty}.\"\n            )\n        if not 0.0 < self.repetition_penalty <= 2.0:\n            raise ValueError(\n                \"repetition_penalty must be in (0, 2], got \"\n                f\"{self.repetition_penalty}.\"","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/2noise/ChatTTS/blob/77b89ee281cd479f5b1a787ada330dc975ca1f2a/ChatTTS/model/velocity/sampling_params.py#L164-L200","documentation":"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.","triggerScenarios":"Constructing SamplingParams with n=0, a negative n, or a value that compares below 1 (e.g. n=0.5 via typo).","commonSituations":"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.","solutions":["Pass n=1 (the minimum) or higher","If n is derived from user/config input, clamp or validate it before constructing SamplingParams"],"exampleFix":"# before\nparams = SamplingParams(n=0)\n\n# after\nparams = SamplingParams(n=1)","handlingStrategy":"validation","validationCode":"def valid_n(n) -> bool:\n    return isinstance(n, int) and n >= 1","typeGuard":"def is_valid_n(n) -> bool:\n    return isinstance(n, int) and not isinstance(n, bool) and n >= 1","tryCatchPattern":null,"preventionTips":["Default n to 1 in configs","Validate n >= 1 at the API boundary before building SamplingParams"],"tags":["sampling-params","validation","llm-generation","constructor"],"backgroundTag":"invalid-sampling-parameter","analyzedSha":"77b89ee281cd479f5b1a787ada330dc975ca1f2a","analyzedAt":"2026-08-26T17:48:24.233Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}