[Qwen4Exp] Pipeline-stage ownership for PLE, the MTP drafter and the vision tower

Each pipeline stage builds only the parts it owns: PLE when every PLE layer
lives on stage 0, MTP under PP (port of vLLM PR #46994 minus its ROCm MLA file
and tests) with the drafter on the last stage, and the vision tower on the
first stage only.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-09 19:43:53 +07:00
co-authored by Hinata
parent 461a8a0f82
commit 7e5f658d75
5 changed files with 170 additions and 18 deletions
+35 -6
View File
@@ -61,6 +61,7 @@ from vllm.model_executor.models.qwen3_vl import (
)
from vllm.model_executor.models.utils import (
AutoWeightsLoader,
PPMissingLayer,
StageMissingLayer,
WeightsMapper,
_merge_multimodal_embeddings,
@@ -748,11 +749,16 @@ class Qwen4ExpForCausalLM(
self.model = Qwen4ExpModel(
vllm_config=vllm_config, prefix=maybe_prefix(prefix, "model")
)
self.lm_head = ParallelLMHead(
config.vocab_size,
config.hidden_size,
prefix=maybe_prefix(prefix, "lm_head"),
)
# PP ownership: logits are computed on the
# last stage only; earlier stages carried an unused 0.59 GiB head.
if get_pp_group().is_last_rank:
self.lm_head = ParallelLMHead(
config.vocab_size,
config.hidden_size,
prefix=maybe_prefix(prefix, "lm_head"),
)
else:
self.lm_head = PPMissingLayer()
self.logits_processor = LogitsProcessor(config.vocab_size)
self.make_empty_intermediate_tensors = (
self.model.make_empty_intermediate_tensors
@@ -1033,6 +1039,14 @@ class Qwen4ExpForConditionalGeneration(
self.model_config = vllm_config.model_config
self.multimodal_config = multimodal_config
self.language_model_only = multimodal_config.language_model_only
# PP ownership: the encoder cache and the image
# embeddings exist on the first pipeline stage only; later stages
# carried an unused vision tower (~0.42 GiB per GPU at TP2). Absence
# on a later stage is an ownership decision, not language_model_only:
# the multimodal configuration stays global.
self._owns_vision_tower = (
not self.language_model_only and get_pp_group().is_first_rank
)
if self.language_model_only:
self.use_data_parallel = False
self.is_multimodal_pruning_enabled = False
@@ -1041,6 +1055,12 @@ class Qwen4ExpForConditionalGeneration(
self._tokenizer = None
self.visual = StageMissingLayer("vision_tower")
self._tower_model_names = []
elif not self._owns_vision_tower:
self.use_data_parallel = multimodal_config.mm_encoder_tp_mode == "data"
self._init_video_pruning(multimodal_config)
self._tokenizer = cached_tokenizer_from_config(vllm_config.model_config)
self.visual = StageMissingLayer("vision_tower")
self._tower_model_names = []
else:
self.use_data_parallel = multimodal_config.mm_encoder_tp_mode == "data"
self._init_video_pruning(multimodal_config)
@@ -1087,7 +1107,16 @@ class Qwen4ExpForConditionalGeneration(
self.make_empty_intermediate_tensors = (
self.language_model.make_empty_intermediate_tensors
)
if not get_pp_group().is_first_rank and self.use_deepstack:
# Deepstack levels are injected into the first len(indexes) decoder
# layers on the first stage and are not forwarded through PP; keep the
# boundary assertion independent of use_deepstack (False on stages
# without a tower) so a future checkpoint with deepstack cannot be
# split across the boundary silently.
if (
not get_pp_group().is_first_rank
and not self.language_model_only
and bool(config.vision_config.deepstack_visual_indexes)
):
assert self.language_model.model.start_layer >= len(
config.vision_config.deepstack_visual_indexes
), (
+1 -7
View File
@@ -38,13 +38,7 @@ class Qwen4ExpModelState(MambaHybridModelState):
self.ngram_eos_token_id = 0
return
if vllm_config.parallel_config.pipeline_parallel_size > 1:
raise RuntimeError(
"N-gram PLE embedding currently requires "
"pipeline_parallel_size=1 because non-first pipeline ranks do "
"not receive the raw input_ids required by PLE. Please run "
"with PP=1."
)
# vllm#54709: PP gate moved to config.py (placement-based).
self.ngram_context_len = int(config.ngram_size) - 1
if self.ngram_context_len <= 0:
+5 -1
View File
@@ -288,7 +288,11 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
hidden_size = self.hidden_size
prev_block_output: torch.Tensor | None = None
if get_pp_group().is_first_rank:
# Branch on the inputs, not the rank (vllm PR #46994's rule, applied
# there to Qwen3_5MTP / DeepSeek MTP): the drafter is built entirely on
# the LAST pipeline stage, where is_first_rank is False, and it always
# starts from the target's hidden state + token ids it embeds itself.
if intermediate_tensors is None:
assert hidden_states is not None
if inputs_embeds is None:
assert input_ids is not None