modelscope / modelscope/twinkle
提案:为 Twinkle 新增 TTS 训练支持(多码本 Preprocessor + Loss)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 258
- Forks
- 50
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 11
Description
背景
Twinkle 现在支持文本 LLM 和多模态,但没有 TTS 训练支持(cookbook 里没 TTS 示例,模型支持表也没列 TTS 变体)。我想给它加上 TTS 的 LoRA SFT 能力,先发个方案对一下,如果没问题我会按工作项实现并提交PR。
目标
让 Twinkle 能跑这两类 TTS 模型的 LoRA SFT:
- 多码本 AR-LM(如 Qwen3-TTS-12Hz-1.7B-Base):输入"文本+参考音频",输出"目标音频的多码本 token"
- 非 AR 局部 Transformer(如 MOSS-TTS-Local-Transformer-v1.5)
两类架构不同,但 LoRA 都挂在 q/k/v 这些线性层,组件能复用。
设计
仿 cookbook/mm/fsdp2.py 里 LatexOCRProcessor 的范式(自定义 Preprocessor 子类 + Trajectory/Message),加两个组件:
TTSMultiCodebookProcessor(Preprocessor 子类)
把 manifest 里的多码本 audio_codes 组织成训练样本:
- 文本 + 参考音频部分:label 置 -100(不学)
- 目标音频部分:保留多码本 label(学)
- 输出形如
Trajectory(messages=[Message(role='user', content=text, audio=ref_codes), Message(role='assistant', audio_codes=target_codes)])
TTSMultiCodebookLoss(Loss 子类)
多码本 next-token 交叉熵:每个位置对每个码本算 CE 再求和,只在 label != -100 的位置算。多码本 loss 的写法参考 OpenMOSS 官方 MOSS-TTS 仓库 community/norwegian-lora/train_lora.py。
工作项拆解
- W1 调研多码本 token 在序列里怎么组织(多头输出 / flatten / 残差量化),看 Qwen3-TTS 官方 tokenizer 代码确认。这决定 Preprocessor 的 encode 逻辑。
- W2 设计
TTSMultiCodebookProcessor接口:仿LatexOCRProcessor,定preprocess(row) -> Trajectory的字段(Message要不要加audio_codes字段、参考音频怎么放)。 - W3 实现
TTSMultiCodebookProcessor+ 单测:用极小 manifest 跑通 encode,断言 input_ids/labels 的 shape 和 -100 位置正确。 - W4 设计+实现
TTSMultiCodebookLoss:多码本 CE,仿现成causal_lm的接口风格,加task='multi_codebook_lm'。 - W5 加 cookbook 示例
cookbook/tts/qwen3_tts_lora.py:单卡 + LoRA + bf16,仿cookbook/transformers/fsdp2.py结构。 - W6 MOSS-TTS-Local-Transformer 适配:非 AR 局部 Transformer 训练格式不同,可能要再写个 Preprocessor 变体(W1-W5 跑通后再碰)。
- W7 文档:README 教程表加 TTS 行、docs 加一节"TTS 训练"。
不在范围内
- vocoder / codec 本身训练(冻结用官方训好的)
- 全量 SFT(先做 LoRA,全量以后再说)
想确认的几点
Message类要不要扩展支持audio_codes字段?还是复用现成的images之类?- 多码本 loss 是写个新 Loss 类,还是给现成 CE 加个 multi-codebook 模式?
task='multi_codebook_lm'这个 task 名合不合适?要不要走现成 task 机制?- cookbook 放
cookbook/tts/还是cookbook/transformers/下?
硬件
我在昇腾 NPU 单卡上做(bf16 LoRA),但组件本身不绑死硬件,CUDA 也能跑。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with cookbook/mm/fsdp2.py and its LatexOCRProcessor pattern, then inspect the Qwen3-TTS tokenizer code to determine how multi-codebook tokens are organized. Read community/norwegian-lora/train_lora.py in the MOSS-TTS repository for the loss reference. Done means the processor and loss design is settled, with tests checking input and label shapes and -100 masking before the cookbook and documentation work begins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- audio-video-rtc, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100