mirror of
https://github.com/Nighthawk42/Qwen3-TTS-streaming.git
synced 2026-08-30 08:52:27 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user