[Bugfix][Model] Fix Qwen4Exp MTP buffer placement, config parsing, and Triton warmup

Three initialization and config defects found serving Qwen4Exp, each with a
regression test.

**The MTP hidden buffer lands on the ambient device.** torch.empty for the
spec-decode hidden buffer takes no device, so it follows whatever device is
current rather than vllm_config.device_config.device. The allocation was
duplicated verbatim in the NVIDIA and AMD backends; it moves to
common/mtp.py so the two cannot drift, and the caller passes is_last_rank
rather than reaching for the process group from shared code.

**M-RoPE keys are reported as unrecognized.** Qwen4Exp drives M-RoPE through
mrope_section and mrope_interleaved, which transformers' rope validator does
not know for rope_type="default", so every load warns about a configuration
the model genuinely uses. Declare them at rope validation on the text config
and on the outer config that mirrors it; every other key still warns.

**transformers' layer_types spelling is unread.** Its Qwen4Exp config
canonicalizes "full_attention" entries to "qwen_sparse_attention" in memory,
so checkpoints re-exported through it serialize that name. vLLM keys QSA off
"full_attention" plus indexer_n_heads, so map the spelling back.

**Qwen4Exp is missing from the Triton warmup set.** Its GDN prefill and QSA
run on other backends, but the kernels this warmup covers -- the gated RMS
norm, the causal conv, the post-conv preparation, the decode state update --
are Triton whichever prefill kernel is chosen, so they compile on the first
prompt instead. qwen4_exp_mtp stays out: kernel_warmup passes the worker's
own model_config, which is the target model's.

tests/models/qwen4_exp/test_config.py: 15 passed.
tests/model_executor/test_qwen_triton_warmup.py: 6 passed.
ruff check, ruff format --check and mypy (Python 3.10) report what they
already report on the base commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: lesj0610 <lesj0610@users.noreply.github.com>
This commit is contained in:
lesj0610
2026-09-14 07:25:01 +09:00
co-authored by Claude Opus 5
parent 319cc5ef19
commit 3b1911c0ca
7 changed files with 254 additions and 36 deletions
+5 -18
View File
@@ -76,6 +76,7 @@ from vllm.transformers_utils.configs.qwen4_exp import (
from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum
from vllm.v1.kv_cache_interface import MambaSpec
from ..common.mtp import make_mtp_hidden_buffer
from ..config import Qwen4ExpConfig
from .hyperconnection import GatedResidual, HyperConnectionConfig
from .low_latency_gemm import enable_qwen4_exp_low_latency_gemm
@@ -446,25 +447,11 @@ class Qwen4ExpModel(nn.Module):
else:
self.hyper_connection_mixer = None
spec_config = vllm_config.speculative_config
# MTP HC multi-stream outputs: when speculative method=="mtp" and the
# model uses HC with hc_count>1, retain the pre-final-mixer multi-stream
# hidden state [T, hc_count*H] so the MTP drafter can feed a real
# multi-stream backbone hidden on its first step (scheme A). Derived
# purely from config (NOT node identity) so P/D nodes stay consistent.
needs_mtp_hidden = (
spec_config is not None
and getattr(spec_config, "method", None) == "mtp"
and get_pp_group().is_last_rank
self._mtp_hidden_buffer = make_mtp_hidden_buffer(
vllm_config,
config,
is_last_rank=get_pp_group().is_last_rank,
)
if needs_mtp_hidden:
self._mtp_hidden_buffer = torch.empty(
vllm_config.scheduler_config.max_num_batched_tokens,
config.hc_count * config.hidden_size,
dtype=vllm_config.model_config.dtype,
)
else:
self._mtp_hidden_buffer = None
def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:
return self.embed_tokens(input_ids)
+37
View File
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Shared MTP drafter state for Qwen4Exp."""
import torch
from vllm.config import VllmConfig
from vllm.transformers_utils.configs.qwen4_exp import Qwen4ExpTextConfig
def make_mtp_hidden_buffer(
vllm_config: VllmConfig,
config: Qwen4ExpTextConfig,
*,
is_last_rank: bool,
) -> torch.Tensor | None:
"""Buffer holding the pre-final-mixer multi-stream hidden state, or None.
When speculative ``method == "mtp"`` the drafter feeds a real multi-stream
backbone hidden on its first step, so the last stage retains
``[T, hc_count * H]``. Whether it is needed is derived from the config
alone, not from node identity, so prefill and decode nodes agree.
"""
spec_config = vllm_config.speculative_config
needs_mtp_hidden = (
spec_config is not None
and getattr(spec_config, "method", None) == "mtp"
and is_last_rank
)
if not needs_mtp_hidden:
return None
return torch.empty(
vllm_config.scheduler_config.max_num_batched_tokens,
config.hc_count * config.hidden_size,
dtype=vllm_config.model_config.dtype,
device=vllm_config.device_config.device,
)
+21
View File
@@ -29,6 +29,11 @@ class Qwen4ExpTextConfig(Qwen3NextConfig):
model_type = "qwen4_exp_text"
base_config_key = "text_config"
keys_to_ignore_at_inference = ["past_key_values"]
# Qwen4Exp drives M-RoPE through these two rope_parameters entries, which
# transformers' rope validator does not know about for rope_type="default".
# Declare them here so validation stays strict for every other key instead
# of warning on a configuration the model genuinely uses.
ignore_keys_at_rope_validation = {"mrope_section", "mrope_interleaved"}
def __init__(
self,
@@ -49,6 +54,19 @@ class Qwen4ExpTextConfig(Qwen3NextConfig):
if hc_count <= 1:
raise ValueError(f"Qwen4Exp requires hc_count > 1, got {hc_count}.")
if layer_types is not None:
# Transformers' Qwen4Exp config canonicalizes "full_attention"
# entries to "qwen_sparse_attention" in memory, so checkpoints
# re-exported through it (e.g. quantized exports) serialize that
# name. vLLM keys QSA off "full_attention" plus indexer_n_heads,
# so map the transformers spelling back.
layer_types = [
"full_attention"
if layer_type == "qwen_sparse_attention"
else layer_type
for layer_type in layer_types
]
if rope_parameters is not None:
if kwargs.get("rope_scaling") is None:
kwargs["rope_scaling"] = rope_parameters
@@ -197,6 +215,9 @@ class Qwen4ExpConfig(PretrainedConfig):
"text_config": Qwen4ExpTextConfig,
}
keys_to_ignore_at_inference = ["past_key_values"]
# The outer config mirrors the text config's rope_parameters (see below),
# so it is validated a second time and needs the same allowance.
ignore_keys_at_rope_validation = {"mrope_section", "mrope_interleaved"}
def __init__(
self,
+5 -18
View File
@@ -75,6 +75,7 @@ from vllm.transformers_utils.configs.qwen4_exp import (
from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum
from vllm.v1.kv_cache_interface import MambaSpec
from ..common.mtp import make_mtp_hidden_buffer
from ..config import Qwen4ExpConfig
from .hyperconnection import GatedResidual, HyperConnectionConfig
from .low_latency_gemm import enable_qwen4_exp_low_latency_gemm
@@ -438,25 +439,11 @@ class Qwen4ExpModel(nn.Module):
else:
self.hyper_connection_mixer = None
spec_config = vllm_config.speculative_config
# MTP HC multi-stream outputs: when speculative method=="mtp" and the
# model uses HC with hc_count>1, retain the pre-final-mixer multi-stream
# hidden state [T, hc_count*H] so the MTP drafter can feed a real
# multi-stream backbone hidden on its first step (scheme A). Derived
# purely from config (NOT node identity) so P/D nodes stay consistent.
needs_mtp_hidden = (
spec_config is not None
and getattr(spec_config, "method", None) == "mtp"
and get_pp_group().is_last_rank
self._mtp_hidden_buffer = make_mtp_hidden_buffer(
vllm_config,
config,
is_last_rank=get_pp_group().is_last_rank,
)
if needs_mtp_hidden:
self._mtp_hidden_buffer = torch.empty(
vllm_config.scheduler_config.max_num_batched_tokens,
config.hc_count * config.hidden_size,
dtype=vllm_config.model_config.dtype,
)
else:
self._mtp_hidden_buffer = None
def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:
return self.embed_tokens(input_ids)