2noise/ChatTTS · error · ValueError
The lengths of prompts and prompt_token_ids must be the same
Error message
The lengths of prompts and prompt_token_ids must be the same.
What it means
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.
Source
Thrown at ChatTTS/model/velocity/llm.py:157
prompt_token_ids: A list of token IDs for the prompts. If None, we
use the tokenizer to convert the prompts to token IDs.
use_tqdm: Whether to use tqdm to display the progress bar.
Returns:
A list of `RequestOutput` objects containing the generated
completions in the same order as the input prompts.
"""
if prompts is None and prompt_token_ids is None:
raise ValueError("Either prompts or prompt_token_ids must be " "provided.")
if isinstance(prompts, str):
# Convert a single prompt to a list.
prompts = [prompts]
if (
prompts is not None
and prompt_token_ids is not None
and len(prompts) != len(prompt_token_ids)
):
raise ValueError(
"The lengths of prompts and prompt_token_ids " "must be the same."
)
if sampling_params is None:
# Use default sampling params.
sampling_params = SamplingParams()
# Add requests to the engine.
num_requests = len(prompts) if prompts is not None else len(prompt_token_ids)
for i in range(num_requests):
prompt = prompts[i] if prompts is not None else None
token_ids = None if prompt_token_ids is None else prompt_token_ids[i]
self._add_request(prompt, sampling_params, token_ids)
rtns = self._run_engine(use_tqdm)
for i, rtn in enumerate(rtns):
token_ids = rtn.outputs[0].token_ids
for j, token_id in enumerate(token_ids):
if len(token_id) == 1:View on GitHub (pinned to 77b89ee281)
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.
Example fix
# before prompts = [p for p in prompts if p] # length shrinks out = llm.generate(prompts, prompt_token_ids) # token_ids unchanged -> mismatch # after keep = [i for i, p in enumerate(prompts) if p] out = llm.generate([prompts[i] for i in keep], [prompt_token_ids[i] for i in keep])
Defensive patterns
Strategy: validation
Validate before calling
def aligned_prompts(prompts, prompt_token_ids):
if prompts is not None and prompt_token_ids is not None:
assert len(prompts) == len(prompt_token_ids), (
f'{len(prompts)} prompts vs {len(prompt_token_ids)} token-id lists')
return prompts, prompt_token_ids Try / catch
try:
out = llm.generate(prompts, prompt_token_ids)
except ValueError as e:
if 'must be the same' in str(e):
out = llm.generate(prompt_token_ids=prompt_token_ids) # drop unaligned prompts
else:
raise Prevention
- Build (prompt, ids) pairs together so they can't diverge.
- Apply any dedup/filter to both lists with the same indices.
When it happens
Trigger: llm.generate(prompts=['a','b','c'], prompt_token_ids=[[1],[2]]) - lists of different lengths, typically after zipping/misaligning two separately built lists.
Common situations: 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.
Related errors
AI-assisted analysis of 2noise/ChatTTS@77b89ee281 (2026-08-26).
Data as JSON: /api/errors/c1246a98b6b1317f.
Report an issue: GitHub.