[Bugfix][Model] Qwen3-TTS: don't collapse 2D ref_code list when estimating prompt length (#3940)

Signed-off-by: nperraud <nathanael.perraudin@gmail.com>
This commit is contained in:
nperraud authored and GitHub committed 2026-05-29 09:18:25 -06:00
1 parent f1c2caa3c7
commit 9fdb3bcb89
2 files changed
+141 -2

No files matched your search

@@ -1041,7 +1041,13 @@ class Qwen3TTSTalkerForConditionalGeneration(nn.Module):
if in_context_mode:
ref_code = None
if isinstance(voice_clone_prompt, dict):
ref_code = _first(voice_clone_prompt.get("ref_code"), None)
# Do NOT apply `_first(...)` here. `_first` unwraps the singleton-list
# batching convention used at the top level of `additional_information`;
# values inside `voice_clone_prompt` are per-item payloads. `ref_code`
# is a `[num_frames, num_codebooks]` 2D list, so `_first` would strip
# its outer dim and report `num_codebooks` (~8) instead of `num_frames`
# (~hundreds), silently truncating the prefill embeddings downstream.
ref_code = voice_clone_prompt.get("ref_code")
ref_code_len: int | None = None
if isinstance(ref_code, list):
@@ -1071,7 +1077,11 @@ class Qwen3TTSTalkerForConditionalGeneration(nn.Module):
# text_embed = ref_ids + text_ids + eos.
ref_ids = _first(info.get("ref_ids"), None)
if isinstance(voice_clone_prompt, dict) and ref_ids is None:
ref_ids = _first(voice_clone_prompt.get("ref_ids") or voice_clone_prompt.get("ref_id"), None)
# Same reasoning as ref_code above: values inside `voice_clone_prompt`
# are per-item payloads, not singleton-wrapped batches. Applying
# `_first` to a list-of-int `ref_ids` collapses it to an int and the
# branches below fall through to `ref_ids_len = 0`.
ref_ids = voice_clone_prompt.get("ref_ids") or voice_clone_prompt.get("ref_id")
if ref_ids is None:
ref_text = _first(info.get("ref_text"), "")