{"record":{"id":"c1246a98b6b1317f","repo":"2noise/ChatTTS","slug":"the-lengths-of-prompts-and-prompt-token-ids-must-b","errorCode":null,"errorMessage":"The lengths of prompts and prompt_token_ids must be the same.","messagePattern":"The lengths of prompts and prompt_token_ids must be the same\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ChatTTS/model/velocity/llm.py","lineNumber":157,"sourceCode":"            prompt_token_ids: A list of token IDs for the prompts. If None, we\n                use the tokenizer to convert the prompts to token IDs.\n            use_tqdm: Whether to use tqdm to display the progress bar.\n\n        Returns:\n            A list of `RequestOutput` objects containing the generated\n            completions in the same order as the input prompts.\n        \"\"\"\n        if prompts is None and prompt_token_ids is None:\n            raise ValueError(\"Either prompts or prompt_token_ids must be \" \"provided.\")\n        if isinstance(prompts, str):\n            # Convert a single prompt to a list.\n            prompts = [prompts]\n        if (\n            prompts is not None\n            and prompt_token_ids is not None\n            and len(prompts) != len(prompt_token_ids)\n        ):\n            raise ValueError(\n                \"The lengths of prompts and prompt_token_ids \" \"must be the same.\"\n            )\n        if sampling_params is None:\n            # Use default sampling params.\n            sampling_params = SamplingParams()\n\n        # Add requests to the engine.\n        num_requests = len(prompts) if prompts is not None else len(prompt_token_ids)\n        for i in range(num_requests):\n            prompt = prompts[i] if prompts is not None else None\n            token_ids = None if prompt_token_ids is None else prompt_token_ids[i]\n            self._add_request(prompt, sampling_params, token_ids)\n\n        rtns = self._run_engine(use_tqdm)\n        for i, rtn in enumerate(rtns):\n            token_ids = rtn.outputs[0].token_ids\n            for j, token_id in enumerate(token_ids):\n                if len(token_id) == 1:","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/2noise/ChatTTS/blob/77b89ee281cd479f5b1a787ada330dc975ca1f2a/ChatTTS/model/velocity/llm.py#L139-L175","documentation":"When both prompts and prompt_token_ids are supplied, generate() uses them in parallel (prompts[i] is only used for display, token ids are taken from prompt_token_ids[i]). Their lengths must match or the request pairing is ambiguous, so the engine raises before submitting anything.","triggerScenarios":"llm.generate(prompts=['a','b','c'], prompt_token_ids=[[1],[2]]) - lists of different lengths, typically after zipping/misaligning two separately built lists.","commonSituations":"Deduplicating prompts but not token ids (or vice versa); one list truncated by a batching bug; appending to one list in a loop but not the other.","solutions":["Make both lists the same length: len(prompts) == len(prompt_token_ids).","If you deduplicated prompts, deduplicate token ids with the same filter so indices stay aligned.","Simpler: pass only prompt_token_ids (prompts=None) if you don't need display strings - then no pairing exists to break."],"exampleFix":"# before\nprompts = [p for p in prompts if p]          # length shrinks\nout = llm.generate(prompts, prompt_token_ids)  # token_ids unchanged -> mismatch\n\n# after\nkeep = [i for i, p in enumerate(prompts) if p]\nout = llm.generate([prompts[i] for i in keep], [prompt_token_ids[i] for i in keep])","handlingStrategy":"validation","validationCode":"def aligned_prompts(prompts, prompt_token_ids):\n    if prompts is not None and prompt_token_ids is not None:\n        assert len(prompts) == len(prompt_token_ids), (\n            f'{len(prompts)} prompts vs {len(prompt_token_ids)} token-id lists')\n    return prompts, prompt_token_ids","typeGuard":null,"tryCatchPattern":"try:\n    out = llm.generate(prompts, prompt_token_ids)\nexcept ValueError as e:\n    if 'must be the same' in str(e):\n        out = llm.generate(prompt_token_ids=prompt_token_ids)  # drop unaligned prompts\n    else:\n        raise","preventionTips":["Build (prompt, ids) pairs together so they can't diverge.","Apply any dedup/filter to both lists with the same indices."],"tags":["api-misuse","input-validation","length-mismatch"],"backgroundTag":"argument-length-mismatch","analyzedSha":"77b89ee281cd479f5b1a787ada330dc975ca1f2a","analyzedAt":"2026-08-26T17:48:24.233Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}