[Perf][Qwen4Exp] Merge QSA QKVG and indexer QK projections (#59533)

Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: namgyu-youn <namgyu.dev@gmail.com>
This commit is contained in:
Thien Tran
2026-10-05 07:03:29 +00:00
committed by GitHub
co-authored by Codex namgyu-youn
parent 92044241a0
commit 042ab0305c
6 changed files with 181 additions and 119 deletions
+14 -1
View File
@@ -622,7 +622,7 @@ class Qwen4ExpForCausalLM(
IsHybrid,
):
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
"qkv_proj": ["q_proj", "k_proj", "v_proj", "indexer.index_qk_proj"],
"gate_up_proj": ["gate_proj", "up_proj"],
"kv_proj": ["key_proj", "value_proj"],
"in_proj_qkvz": ["in_proj_qkv", "in_proj_z"],
@@ -641,6 +641,12 @@ class Qwen4ExpForCausalLM(
def __init__(self, *, vllm_config: VllmConfig, prefix: str = "") -> None:
super().__init__()
config: Qwen4ExpTextConfig = vllm_config.model_config.hf_text_config
if vllm_config.lora_config is not None:
# LoRA does not support the merged QKV/indexer projection, so its
# packed mapping must keep the indexer separate.
self.packed_modules_mapping = self.packed_modules_mapping | {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
}
self.vllm_config = vllm_config
self.model_config = vllm_config.model_config
self.quant_config = vllm_config.quant_config
@@ -866,6 +872,7 @@ class Qwen4ExpForConditionalGeneration(
requires_raw_input_tokens = True
packed_modules_mapping = Qwen3_5ForConditionalGeneration.packed_modules_mapping | {
"qkv_proj": Qwen4ExpForCausalLM.packed_modules_mapping["qkv_proj"],
"kv_proj": ["key_proj", "value_proj"],
"input_mix_weight_down_block_inject": [
"input_mix_weight_down",
@@ -883,6 +890,12 @@ class Qwen4ExpForConditionalGeneration(
def __init__(self, *, vllm_config: VllmConfig, prefix: str = "model") -> None:
nn.Module.__init__(self)
config: Qwen4ExpConfig = vllm_config.model_config.hf_config
if vllm_config.lora_config is not None:
# LoRA does not support the merged QKV/indexer projection, so its
# packed mapping must keep the indexer separate.
self.packed_modules_mapping = self.packed_modules_mapping | {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
}
quant_config = vllm_config.quant_config
multimodal_config = vllm_config.model_config.multimodal_config
if multimodal_config is None: