fix: remove double label-shifting in finetuning that caused speech speed-up

The HF ForCausalLMLoss already shifts labels internally, but sft_12hz.py
was also manually shifting before passing to model.talker(), causing
double-shifting and progressively faster audio with more epochs.

Additionally, the sub-talker forward_finetune used ForCausalLMLoss on
already-aligned logits/labels, adding another unwanted shift. Replaced
with direct cross_entropy.

See: https://github.com/QwenLM/Qwen3-TTS/issues/179#issuecomment-3870059313
This commit is contained in:
Kedara Studios
2026-02-09 19:46:43 +01:00
parent a48510a58d
commit 32c00eb088
2 changed files with 11 additions and 6 deletions
+6 -5
View File
@@ -93,15 +93,16 @@ def train():
input_embeddings = input_text_embedding + input_codec_embedding
outputs = model.talker(
inputs_embeds=input_embeddings[:, :-1, :],
attention_mask=attention_mask[:, :-1],
labels=codec_0_labels[:, 1:],
inputs_embeds=input_embeddings,
attention_mask=attention_mask,
labels=codec_0_labels,
output_hidden_states=True
)
hidden_states = outputs.hidden_states[0][-1]
talker_hidden_states = hidden_states[codec_mask[:, 1:]]
talker_codec_ids = codec_ids[codec_mask]
target_codec_mask = codec_mask[:, 1:]
talker_hidden_states = hidden_states[:, :-1][target_codec_mask]
talker_codec_ids = codec_ids[:, 1:][target_codec_mask]
sub_talker_logits, sub_talker_loss = model.talker.forward_sub_talker_finetune(talker_codec_ids, talker_hidden_states)
+5 -1
View File
@@ -1321,7 +1321,11 @@ class Qwen3TTSTalkerCodePredictorModelForConditionalGeneration(Qwen3TTSPreTraine
loss = None
if labels is not None:
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
loss = torch.nn.functional.cross_entropy(
logits.reshape(-1, self.config.vocab_size),
labels.reshape(-1),
ignore_index=-100,
)
return Qwen3TTSTalkerCodePredictorOutputWithPast(
loss=loss,