{"record":{"id":"13c029361695ebba","repo":"2noise/ChatTTS","slug":"top-k-must-be-1-disable-or-at-least-1-got-se","errorCode":null,"errorMessage":"top_k must be -1 (disable), or at least 1, got {self.top_k}.","messagePattern":"top_k must be -1 \\(disable\\), or at least 1, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ChatTTS/model/velocity/sampling_params.py","lineNumber":208,"sourceCode":"                \"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}.\"\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}.\"","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/2noise/ChatTTS/blob/77b89ee281cd479f5b1a787ada330dc975ca1f2a/ChatTTS/model/velocity/sampling_params.py#L190-L226","documentation":"SamplingParams._verify_args enforces top_k == -1 (which disables top-k filtering) or top_k >= 1. Zero and values below -1 are rejected because top-k selects the k most likely tokens and k=0 selects nothing.","triggerScenarios":"Constructing SamplingParams with top_k=0, top_k=-2, or a non-integer value that fails the comparison.","commonSituations":"Trying to disable top-k by setting 0 instead of -1; passing num_candidates=0 from an empty config; off-by-one when computing top_k dynamically.","solutions":["Use top_k=-1 to disable top-k filtering","Use top_k=1 (with temperature 0) for greedy decoding","Clamp computed top_k values to >= 1 or exactly -1"],"exampleFix":"# before\nparams = SamplingParams(top_k=0)  # trying to disable\n\n# after\nparams = SamplingParams(top_k=-1)  # disabled","handlingStrategy":"validation","validationCode":"def normalize_top_k(k):\n    k = int(k)\n    if k == 0:\n        return -1  # caller meant \"disabled\"\n    return k if k >= 1 else -1","typeGuard":"def is_valid_top_k(k) -> bool:\n    return isinstance(k, int) and (k == -1 or k >= 1)","tryCatchPattern":null,"preventionTips":["Use -1 to disable top-k, not 0","Validate top_k is -1 or >= 1 before constructing params"],"tags":["sampling-params","validation","top-k","llm-generation"],"backgroundTag":"invalid-sampling-parameter","analyzedSha":"77b89ee281cd479f5b1a787ada330dc975ca1f2a","analyzedAt":"2026-08-26T17:48:24.233Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}