Skip to content

Commit 0c4e02c

Browse files
guybrush1984claude
andcommitted
Backport inference fixes from upstream PRs QwenLM#234 and QwenLM#126
- QwenLM#234: Fix sample loss in chunked_decode — the context removal logic over-trims audio at chunk boundaries, causing shorter output and audible pops. Take expected sample count from the end instead of trimming a fixed amount from the front. - QwenLM#126: Fix tuple item assignment in _normalize_audio_inputs — mutating a tuple element silently fails, breaking stereo-to-mono conversion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ecda9b commit 0c4e02c

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

qwen_tts/core/tokenizer_12hz/modeling_qwen3_tts_tokenizer_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ def chunked_decode(self, codes, chunk_size=300, left_context_size=25):
891891
context_size = left_context_size if start_index - left_context_size > 0 else start_index
892892
codes_chunk = codes[..., start_index - context_size : end_index]
893893
wav_chunk = self(codes_chunk)
894-
wavs.append(wav_chunk[..., context_size * self.total_upsample :])
894+
sample_count = min((end_index - start_index) * self.total_upsample, wav_chunk.shape[-1])
895+
wavs.append(wav_chunk[..., -sample_count:])
895896
start_index = end_index
896897
return torch.cat(wavs, dim=-1)
897898

qwen_tts/inference/qwen3_tts_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ def _normalize_audio_inputs(self, audios: Union[AudioLike, List[AudioLike]]) ->
259259
raise TypeError(f"Unsupported audio input type: {type(a)}")
260260
for i, a in enumerate(out):
261261
if a[0].ndim > 1:
262-
a[0] = np.mean(a[0], axis=-1).astype(np.float32)
263-
out[i] = (a[0], a[1])
262+
a_s = np.mean(a[0], axis=-1).astype(np.float32)
263+
out[i] = (a_s, a[1])
264264
return out
265265

266266
def _ensure_list(self, x: MaybeList) -> List[Any]:

0 commit comments

Comments
 (0)