[Rebase] Rebase to vllm 0.27.0 (#5976)
Signed-off-by: tzhouam <tzhouam@connect.ust.hk> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
584d78c673
commit
2ce15ab7a0
55 files changed
+1335
-93
No files matched your search
@@ -431,7 +431,10 @@ class DyninOmniMultiModalProcessor(BaseMultiModalProcessor[DyninOmniProcessingIn
|
||||
mm_items = inputs.mm_data_items
|
||||
|
||||
with timing_ctx.record("get_mm_hashes"):
|
||||
mm_hashes = inputs.get_mm_hashes(self.info.model_id)
|
||||
mm_hashes = inputs.get_mm_hashes(
|
||||
self.info.model_id,
|
||||
self.info.ctx.get_mm_config().mm_hasher_algorithm,
|
||||
)
|
||||
|
||||
tokenizer = self.info.ctx.tokenizer
|
||||
prompt_token_ids = self._encode_prompt_to_token_ids(prompt, tokenizer)
|
||||
|
||||
@@ -29,7 +29,7 @@ from vllm.distributed import (
|
||||
)
|
||||
from vllm.inputs import MultiModalDataDict
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.fused_moe import FusedMoE as SharedFusedMoE
|
||||
from vllm.model_executor.layers.fused_moe import FusedMoEFactory as SharedFusedMoE
|
||||
from vllm.model_executor.layers.fused_moe import fused_moe_make_expert_params_mapping
|
||||
from vllm.model_executor.layers.linear import (
|
||||
ColumnParallelLinear,
|
||||
|
||||
@@ -49,13 +49,12 @@ from vllm.model_executor.models.utils import (
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.sequence import IntermediateTensors
|
||||
from vllm.transformers_utils.config import (
|
||||
is_interleaved,
|
||||
patch_rope_parameters,
|
||||
set_default_rope_theta,
|
||||
)
|
||||
|
||||
from vllm_omni.model_executor.models.output_templates import OmniOutput
|
||||
from vllm_omni.model_executor.models.utils import add_prefix_to_loaded_weights
|
||||
from vllm_omni.model_executor.models.utils import add_prefix_to_loaded_weights, is_interleaved
|
||||
from vllm_omni.transformers_utils.configs.mammoth_moda2 import Mammothmoda2Config
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.activation import SiluAndMul
|
||||
from vllm.model_executor.layers.attention import Attention
|
||||
from vllm.model_executor.layers.fused_moe import (
|
||||
FusedMoE,
|
||||
FusedMoEFactory,
|
||||
fused_moe_make_expert_params_mapping,
|
||||
)
|
||||
from vllm.model_executor.layers.layernorm import RMSNorm
|
||||
@@ -332,7 +332,7 @@ class BailingMoeV2SparseMoeBlock(nn.Module):
|
||||
else:
|
||||
self.shared_experts = None
|
||||
|
||||
self.experts = FusedMoE(
|
||||
self.experts = FusedMoEFactory(
|
||||
shared_experts=self.shared_experts,
|
||||
num_experts=config.num_experts,
|
||||
top_k=config.num_experts_per_tok,
|
||||
|
||||
@@ -76,7 +76,14 @@ class Qwen2_5OmniForConditionalGeneration(
|
||||
talker_config: Qwen2_5OmniTalkerConfig = config.talker_config
|
||||
self.talker_config = talker_config
|
||||
|
||||
self.model_stage = vllm_config.model_config.model_stage
|
||||
# See qwen3_omni for the full rationale. model_stage is only set by omni's
|
||||
# staged startup; this class is now also constructed for non-staged runs
|
||||
# (its arch overrides upstream's in the registry), where reading the
|
||||
# attribute directly raises AttributeError during engine-core init.
|
||||
# Default to the thinker — the text-generation stage. Note there is no
|
||||
# else-branch below, so an unset stage would otherwise build no submodule
|
||||
# at all and fail later at self.thinker.
|
||||
self.model_stage = getattr(vllm_config.model_config, "model_stage", None) or "thinker"
|
||||
if self.model_stage == "thinker":
|
||||
# Initialize thinker model (multimodal processing)
|
||||
self.thinker = init_vllm_registered_model(
|
||||
|
||||
@@ -296,9 +296,23 @@ class Qwen2_5OmniVideoProcessorItems(VideoProcessorItems):
|
||||
def get_processor_data(self) -> Mapping[str, object]:
|
||||
from transformers.video_utils import VideoMetadata
|
||||
|
||||
videos = [frames for frames, _ in self.data]
|
||||
# Read through self.get(), not self.data. vLLM now wraps loaded media in
|
||||
# MediaWithBytes (multimodal/media/base.py) to retain the original bytes
|
||||
# for hashing, and VideoProcessorItems._unwrap is what strips it back to
|
||||
# the raw frames. Iterating self.data skips that unwrap, so the HF
|
||||
# processor received [MediaWithBytes, ...] where it expects frame arrays.
|
||||
# transformers' make_batched_videos recognises the wrapper as neither a
|
||||
# video nor a sequence, silently builds an empty list, and then indexes
|
||||
# it -- surfacing as a 400 on every video request:
|
||||
# File "transformers/video_utils.py", in convert_pil_frames_to_video
|
||||
# if not (isinstance(videos[0], (list, tuple)) and ...
|
||||
# IndexError: list index out of range
|
||||
# self.get() is also correct on the pre-wrapper vLLM, where it is a
|
||||
# plain self.data[index].
|
||||
items = [self.get(index) for index in range(self.get_count())]
|
||||
videos = [frames for frames, _ in items]
|
||||
video_metadata = [
|
||||
VideoMetadata(**{k: v for k, v in metadata.items() if k != "do_sample_frames"}) for _, metadata in self.data
|
||||
VideoMetadata(**{k: v for k, v in metadata.items() if k != "do_sample_frames"}) for _, metadata in items
|
||||
]
|
||||
return {"videos": videos, "video_metadata": video_metadata}
|
||||
|
||||
@@ -622,7 +636,10 @@ class Qwen2_5OmniThinkerMultiModalProcessor(
|
||||
)
|
||||
|
||||
with timing_ctx.record("get_mm_hashes"):
|
||||
mm_hashes = inputs.get_mm_hashes(self.info.model_id)
|
||||
mm_hashes = inputs.get_mm_hashes(
|
||||
self.info.model_id,
|
||||
self.info.ctx.get_mm_config().mm_hasher_algorithm,
|
||||
)
|
||||
|
||||
mm_cache_keys = self._paired_cache_keys(mm_hashes, aiv_pairs)
|
||||
|
||||
|
||||
@@ -127,8 +127,25 @@ class Qwen3OmniMoeForConditionalGeneration(
|
||||
code2wav_config: Qwen3OmniMoeCode2WavConfig = config.code2wav_config
|
||||
self.code2wav_config = code2wav_config
|
||||
|
||||
# Determine model stage
|
||||
self.model_stage = vllm_config.model_config.model_stage
|
||||
# Determine model stage. model_stage is injected by omni's staged
|
||||
# startup (engine/stage_init_utils.py); a plain, non-staged vLLM run
|
||||
# never sets it, and reading it directly raised
|
||||
# AttributeError: 'ModelConfig' object has no attribute 'model_stage'
|
||||
# killing the engine core before it became ready. That path became
|
||||
# reachable once omni archs began overriding upstream's in the global
|
||||
# registry, so this class is now also constructed for non-staged runs
|
||||
# such as the vLLM-text perf benchmark.
|
||||
#
|
||||
# Default to the thinker: it is the text-generation stage, which is what
|
||||
# a non-staged run of this model is asking for. Same shape as
|
||||
# dynin_omni ("token2text") and glm_tts ("glm_tts"). An explicitly wrong
|
||||
# value still reaches the ValueError below rather than being silently
|
||||
# accepted.
|
||||
self.model_stage = getattr(vllm_config.model_config, "model_stage", None) or "thinker"
|
||||
# Staged startup always injects model_stage; its absence means a plain
|
||||
# vLLM run with no talker stage downstream, so no one consumes captured
|
||||
# thinker layers and the forward must return what stock vLLM expects.
|
||||
self.is_staged_run = getattr(vllm_config.model_config, "model_stage", None) is not None
|
||||
|
||||
if self.model_stage == "thinker":
|
||||
self.use_async_omni_output = True
|
||||
@@ -386,17 +403,21 @@ class Qwen3OmniMoeForConditionalGeneration(
|
||||
inputs_embeds = inputs_embeds.to(thinker_dev)
|
||||
|
||||
# Run thinker forward
|
||||
# If talker expects a specific intermediate layer, capture it here
|
||||
# If talker expects a specific intermediate layer, capture it here.
|
||||
# Only staged runs have a talker stage to consume the capture; in a
|
||||
# plain vLLM run capturing would waste a clone per layer per step
|
||||
# and make the thinker return a tuple stock vLLM cannot handle.
|
||||
accept_layer = getattr(self.talker_config, "accept_hidden_layer", None)
|
||||
capture_kwargs = {}
|
||||
if accept_layer is not None:
|
||||
if accept_layer is not None and self.is_staged_run:
|
||||
capture_kwargs = {
|
||||
"capture_layer_indices": [0, int(accept_layer)],
|
||||
"return_hidden_states": True,
|
||||
}
|
||||
|
||||
# Run thinker
|
||||
text_hidden_states, captured_layer_dict = self.thinker(
|
||||
# Run thinker. Returns (text_hidden_states, captured_layer_dict)
|
||||
# when capturing, a bare tensor otherwise.
|
||||
return self.thinker(
|
||||
input_ids=input_ids,
|
||||
positions=positions,
|
||||
intermediate_tensors=intermediate_tensors,
|
||||
@@ -404,7 +425,6 @@ class Qwen3OmniMoeForConditionalGeneration(
|
||||
**capture_kwargs,
|
||||
**kwargs,
|
||||
)
|
||||
return text_hidden_states, captured_layer_dict
|
||||
|
||||
# ========== Stage 2.1: Talker ==========
|
||||
elif self.model_stage == "talker":
|
||||
@@ -494,7 +514,11 @@ class Qwen3OmniMoeForConditionalGeneration(
|
||||
return model_outputs
|
||||
|
||||
if self.model_stage == "thinker":
|
||||
text_hidden_states, captured_layer_dict = model_outputs
|
||||
if isinstance(model_outputs, tuple):
|
||||
text_hidden_states, captured_layer_dict = model_outputs
|
||||
else:
|
||||
# Bare tensor: capture was not requested (no accept_hidden_layer).
|
||||
text_hidden_states, captured_layer_dict = model_outputs, None
|
||||
# Compute thinker-side TTS token embeddings for BOS/EOS/PAD and expose via multimodal outputs.
|
||||
# These will later be projected into talker text space by the talker stage.
|
||||
multimodal_outputs: OmniPayload = captured_layer_dict if captured_layer_dict is not None else {}
|
||||
|
||||
@@ -1495,7 +1495,7 @@ class Qwen3OmniMoeThinkerForConditionalGeneration(
|
||||
else:
|
||||
deepstack_input_embeds = None
|
||||
|
||||
hidden_states, captured_hidden_states = self.language_model.model(
|
||||
model_output = self.language_model.model(
|
||||
input_ids,
|
||||
positions,
|
||||
intermediate_tensors,
|
||||
@@ -1509,6 +1509,16 @@ class Qwen3OmniMoeThinkerForConditionalGeneration(
|
||||
if inputs_embeds is not None and get_pp_group().is_first_rank:
|
||||
self._clear_deepstack_input_embeds(inputs_embeds.size(0))
|
||||
|
||||
if isinstance(model_output, IntermediateTensors):
|
||||
# Non-last PP rank: forward the intermediate tensors as-is.
|
||||
return model_output
|
||||
hidden_states, captured_hidden_states = model_output
|
||||
if capture_layer_indices is None and not return_hidden_states:
|
||||
# No capture requested. Return a bare tensor: stock vLLM's
|
||||
# GPUModelRunner indexes the forward output directly, so a tuple
|
||||
# here breaks non-staged runs that resolve this class through the
|
||||
# global registry (e.g. plain `vllm serve` of the thinker).
|
||||
return hidden_states
|
||||
return hidden_states, captured_hidden_states
|
||||
|
||||
def compute_logits(
|
||||
|
||||
@@ -137,3 +137,17 @@ def reinit_rotary_inv_freq(
|
||||
inv_freq.copy_(new_inv_freq.to(dtype=inv_freq.dtype))
|
||||
n_fixed += 1
|
||||
return n_fixed
|
||||
|
||||
|
||||
def is_interleaved(config) -> bool:
|
||||
"""Detect if the model with this config is used with interleaved attention.
|
||||
|
||||
Replicates the helper that was removed from upstream
|
||||
``vllm.transformers_utils.config`` (vLLM commit 26d725c334,
|
||||
"[Model] Add VaultGemma via Transformers modeling backend") so models
|
||||
that still need the check can share one copy.
|
||||
"""
|
||||
text_config = config.get_text_config()
|
||||
if layer_types := getattr(text_config, "layer_types", None):
|
||||
return len(set(layer_types)) > 1
|
||||
return False
|
||||
Reference in new issue
Block a user