From 738bc8811ae31b733a7806adbc7a580d55729329 Mon Sep 17 00:00:00 2001 From: kaiyuanxie Date: Sat, 29 Aug 2026 11:18:04 +0800 Subject: [PATCH] [BugFix] Disable TP for Qwen3-Omni audio encoder when heads % TP != 0 (#50858) Signed-off-by: CalvinXKY Co-authored-by: CalvinXKY --- vllm/model_executor/models/qwen3_omni_moe_thinker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vllm/model_executor/models/qwen3_omni_moe_thinker.py b/vllm/model_executor/models/qwen3_omni_moe_thinker.py index 96a2212cde..9f309d27f5 100755 --- a/vllm/model_executor/models/qwen3_omni_moe_thinker.py +++ b/vllm/model_executor/models/qwen3_omni_moe_thinker.py @@ -196,8 +196,13 @@ class Qwen3OmniMoeAudioAttention(nn.Module): self.embed_dim = config.d_model self.num_heads = config.encoder_attention_heads self.head_dim = self.embed_dim // self.num_heads + # Audio encoder uses 20 heads. Shard across TP when divisible + # (e.g. TP=2/4); otherwise keep unreplicated (e.g. TP=8). tp_size = get_tensor_model_parallel_world_size() - self.num_local_heads = self.num_heads // tp_size + self.disable_tp = self.num_heads % tp_size != 0 + self.num_local_heads = ( + self.num_heads if self.disable_tp else self.num_heads // tp_size + ) if (self.head_dim * self.num_heads) != self.embed_dim: raise ValueError( @@ -214,6 +219,7 @@ class Qwen3OmniMoeAudioAttention(nn.Module): total_num_kv_heads=self.num_heads, bias=True, prefix=f"{prefix}.qkv_proj", + disable_tp=self.disable_tp, ) self.out_proj = RowParallelLinear( @@ -221,6 +227,7 @@ class Qwen3OmniMoeAudioAttention(nn.Module): output_size=self.embed_dim, bias=True, prefix=f"{prefix}.out_proj", + disable_tp=self.disable_tp, ) self.attn = MMEncoderAttention(