{"record":{"id":"1272f97e6cc4086f","repo":"2noise/ChatTTS","slug":"max-tokens-must-be-at-least-1-got-self-max-token","errorCode":null,"errorMessage":"max_tokens must be at least 1, got {self.max_tokens}.","messagePattern":"max_tokens must be at least 1, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ChatTTS/model/velocity/sampling_params.py","lineNumber":214,"sourceCode":"            )\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}.\"\n            )\n        # if self.temperature < 0.0:\n        #     raise ValueError(\n        #         f\"temperature must be non-negative, got {self.temperature}.\")\n        if not 0.0 < self.top_p <= 1.0:\n            raise ValueError(f\"top_p must be in (0, 1], got {self.top_p}.\")\n        if self.top_k < -1 or self.top_k == 0:\n            raise ValueError(\n                f\"top_k must be -1 (disable), or at least 1, \" f\"got {self.top_k}.\"\n            )\n        if not 0.0 <= self.min_p <= 1.0:\n            raise ValueError(\"min_p must be in [0, 1], got \" f\"{self.min_p}.\")\n        if self.max_tokens < 1:\n            raise ValueError(f\"max_tokens must be at least 1, got {self.max_tokens}.\")\n        if self.logprobs is not None and self.logprobs < 0:\n            raise ValueError(f\"logprobs must be non-negative, got {self.logprobs}.\")\n        if self.prompt_logprobs is not None and self.prompt_logprobs < 0:\n            raise ValueError(\n                f\"prompt_logprobs must be non-negative, got \" f\"{self.prompt_logprobs}.\"\n            )\n\n    def _verify_beam_search(self) -> None:\n        if self.best_of == 1:\n            raise ValueError(\n                \"best_of must be greater than 1 when using beam \"\n                f\"search. Got {self.best_of}.\"\n            )\n        if self.temperature > _SAMPLING_EPS:\n            raise ValueError(\"temperature must be 0 when using beam search.\")\n        if self.top_p < 1.0 - _SAMPLING_EPS:\n            raise ValueError(\"top_p must be 1 when using beam search.\")\n        if self.top_k != -1:","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/2noise/ChatTTS/blob/77b89ee281cd479f5b1a787ada330dc975ca1f2a/ChatTTS/model/velocity/sampling_params.py#L196-L232","documentation":"SamplingParams._verify_args enforces max_tokens >= 1. max_tokens is the maximum number of tokens to generate per completion; zero or negative lengths are rejected.","triggerScenarios":"Constructing SamplingParams with max_tokens=0 or a negative value, e.g. computed as context_window - prompt_length when the prompt fills the whole window.","commonSituations":"Computing max_tokens from context-length arithmetic that can reach 0 for long prompts; passing max_tokens=0 meaning \"no limit\" (there is no unlimited setting — pick a real budget); config typos.","solutions":["Set max_tokens to at least 1; size it as context_length - prompt_tokens, clamped to >= 1","Reject prompts longer than the context window before computing max_tokens instead of letting it go to 0"],"exampleFix":"# before\nmax_tokens = context_len - len(prompt_ids)  # can be 0 or negative\nparams = SamplingParams(max_tokens=max_tokens)\n\n# after\nmax_tokens = max(1, context_len - len(prompt_ids))\nparams = SamplingParams(max_tokens=max_tokens)","handlingStrategy":"validation","validationCode":"def safe_max_tokens(context_len: int, prompt_ids: list) -> int:\n    return max(1, context_len - len(prompt_ids))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute max_tokens as max(1, context_len - prompt_tokens)","Reject over-length prompts explicitly instead of letting max_tokens hit 0"],"tags":["sampling-params","validation","max-tokens","llm-generation"],"backgroundTag":"invalid-sampling-parameter","analyzedSha":"77b89ee281cd479f5b1a787ada330dc975ca1f2a","analyzedAt":"2026-08-26T17:48:24.233Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}