fix: Qwen3-TTS incorrect loss handling#9752
Open
FelysNeko wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the loss calculation for the Qwen TTS model. The computation of the sub-talker loss and the total loss is moved from the template's compute_sft_loss method directly into the model's tts_forward method. This simplifies the template code and centralizes the loss computation within the model's forward pass. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Jintao-Huang
approved these changes
Jul 17, 2026
Collaborator
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
总共包含了两个修复和一处代码简化。
sub_talker_loss 没有被传下去
现象:Loss 极低(从 1 开始下降),但是完全无法克隆声音:no_sub_talker_loss.mp3。
原代码把 sub_talker_loss 作为动态属性挂在
ModelOutput上,再由 compute_sft_loss 用getattr读取:动态属性被
@can_return_tuple/ 模型封装在跨边界时剥离,getattr恒为None,又被静默兜底成纯 talker loss,code_predictor 整个训练零梯度。修复:把损失合并移进
tts_forward内部。标签 shift 错位
现象:在修复了上一条后,Loss 极高(sub_talker_loss 大约是 11),输出噪音,模型崩溃:double_shift.mp3。
上游代码中
forward_sub_talker_finetune内部调用 code_predictor.forward_finetune,传入的的labels是已经预移位一位过的codec_ids[:, 1:],forward_finetune中的实现会调用ForCausalLMLoss再次 shift,导致双重 shift 的情况。修复:参考 QwenLM/Qwen3-TTS#278 ,但直接取
sub_talker_logits手动计算 Loss。移除手动计算 talker_loss
依然参考 QwenLM/Qwen3-TTS#278 ,并不需要手动计算 talker_loss。
Experiment results
Paste your experiment result here(if needed).
成功复刻昔涟:it_works.mp3。
并且额外尝试了 examples/models/qwen3_tts/train.sh,能听得出来是芙宁娜:furina.mp3。