Revert "[Perf][Qwen3-TTS] Fuse QKV and gate_up projections in code predictor …"

This reverts commit 6fdc4ca62d.
This commit is contained in:
Gao Han authored and GitHub committed 2026-08-04 22:25:12 +08:00
1 parent 6fdc4ca62d
commit 5cf2681aeb
8 files changed
+36 -638

No files matched your search

@@ -23,8 +23,6 @@ previous KV-cache loop -- causal attention, only the last position is read.
from __future__ import annotations
from collections.abc import Iterable
import torch
import torch.nn as nn
import torch.nn.functional as F
@@ -63,22 +61,6 @@ class MossTTSRealtimeLocalTransformer(nn.Module):
prefix="model",
)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
"""Delegate ``model.*`` tensors to ``CodePredictorBaseModel.load_weights``.
The shared body fuses ``q/k/v_proj`` into ``qkv_proj`` and
``gate/up_proj`` into ``gate_up_proj``; its loader re-packs the HF
shards and raises on incomplete or missing fused parameters. Going
through it (instead of ``default_weight_loader`` per tensor) keeps
those guarantees for the MossTTSRealtime checkpoint too.
"""
model_weights: list[tuple[str, torch.Tensor]] = []
for name, tensor in weights:
if name.startswith("model."):
model_weights.append((name[len("model.") :], tensor))
loaded = self.model.load_weights(iter(model_weights))
return {f"model.{n}" for n in loaded}
@torch.no_grad()
def generate_frame(
self,
@@ -1179,13 +1179,7 @@ class MossTTSRealtimeTalkerForGeneration(nn.Module):
# ``gate_proj``/``up_proj`` → ``gate_up_proj``. ``default_weight_loader``
# alone leaves those fused params un-initialised, which silently turns
# the backbone into a slightly-corrupted model that never emits EOS.
# The local depth transformer (shared ``CodePredictorBaseModel``) has
# the exact same hazard: its ``qkv_proj``/``gate_up_proj`` are fused,
# so its shards must go through ``CodePredictorBaseModel.load_weights``
# (via ``MossTTSRealtimeLocalTransformer.load_weights``), which re-packs
# them and raises on incomplete/missing fused parameters.
backbone_weights: list[tuple[str, torch.Tensor]] = []
local_weights: list[tuple[str, torch.Tensor]] = []
skipped: list[str] = []
for name, tensor in weights:
if name.startswith("language_model."):
@@ -1200,9 +1194,8 @@ class MossTTSRealtimeTalkerForGeneration(nn.Module):
continue # non-persistent buffer, recomputed at runtime
if sub.startswith("embed_tokens."):
sub = "codec_embedding." + sub[len("embed_tokens.") :]
local_weights.append((f"model.{sub}", tensor))
continue
if name.startswith("local_transformer.local_lm_heads."):
tgt = "local_transformer.model." + sub
elif name.startswith("local_transformer.local_lm_heads."):
tgt = "local_lm_heads." + name[len("local_transformer.local_lm_heads.") :]
else:
tgt = name
@@ -1217,11 +1210,6 @@ class MossTTSRealtimeTalkerForGeneration(nn.Module):
for n in backbone_loaded:
loaded.add(f"model.{n}")
# Delegate depth-transformer weights to the shared fused loader.
local_loaded = self.local_transformer.load_weights(iter(local_weights))
for n in local_loaded:
loaded.add(f"local_transformer.{n}")
# Build stacked embedding cache for vectorised decode ops.
# embed_tokens[0] is the text embedding; [1..n_vq] are audio codebooks.
self._stacked_audio_emb_w = torch.stack(