[Bugfix][Model Runner V2] Restore multimodal draft capability detection (#50417)
Signed-off-by: Raphael Rialland <raphael.rialland@mistral.ai>
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.forward_context import BatchDescriptor, set_forward_context
|
||||
from vllm.logger import init_logger
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.triton_utils import tl, triton
|
||||
from vllm.v1.worker.gpu.attn_utils import build_slot_mappings_by_layer
|
||||
from vllm.v1.worker.gpu.cudagraph_utils import (
|
||||
@@ -37,17 +37,23 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
self.max_num_reqs, dtype=torch.int64, device=device
|
||||
)
|
||||
|
||||
self.supports_mm_inputs = MULTIMODAL_REGISTRY.supports_multimodal_inputs(
|
||||
self.draft_model_config
|
||||
)
|
||||
if self.supports_mm_inputs:
|
||||
self.inputs_embeds = torch.zeros(
|
||||
self.max_num_tokens, self.hidden_size, dtype=self.dtype, device=device
|
||||
)
|
||||
self.inputs_embeds: torch.Tensor | None = None
|
||||
|
||||
self.prefill_cudagraph_manager: SpeculatorCudaGraphManager | None = None
|
||||
self.decode_cudagraph_manager: SpeculatorCudaGraphManager | None = None
|
||||
|
||||
def load_model(self, target_model: nn.Module) -> None:
|
||||
super().load_model(target_model)
|
||||
if not self.supports_mm_inputs:
|
||||
return
|
||||
|
||||
self.inputs_embeds = torch.zeros(
|
||||
self.max_num_tokens,
|
||||
self.hidden_size,
|
||||
dtype=self.dtype,
|
||||
device=self.device,
|
||||
)
|
||||
|
||||
@property
|
||||
def advance_draft_positions(self) -> bool:
|
||||
"""
|
||||
@@ -295,6 +301,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
):
|
||||
inputs_embeds = None
|
||||
if self.supports_mm_inputs:
|
||||
assert self.inputs_embeds is not None
|
||||
# Merge multimodal embeddings with input ids.
|
||||
mm_embeds, is_mm_embed = mm_inputs or (None, None)
|
||||
num_input_tokens = (
|
||||
|
||||
@@ -9,7 +9,6 @@ from vllm.config import VllmConfig
|
||||
from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.forward_context import BatchDescriptor, set_forward_context
|
||||
from vllm.logger import init_logger
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.triton_utils import tl, triton
|
||||
from vllm.v1.attention.backends.utils import PAD_SLOT_ID
|
||||
from vllm.v1.worker.gpu.attn_utils import build_slot_mappings_by_layer
|
||||
@@ -39,25 +38,7 @@ class MultiModuleMTPSpeculator(DraftModelSpeculator):
|
||||
self.max_num_reqs, dtype=torch.int64, device=device
|
||||
)
|
||||
|
||||
self.supports_mm_inputs = MULTIMODAL_REGISTRY.supports_multimodal_inputs(
|
||||
self.draft_model_config
|
||||
)
|
||||
# HACK: the Inkling MTP draft has no MM processor of its own (its draft
|
||||
# config is flattened text-only), but it consumes the target's merged
|
||||
# embeddings at draft prefill — treat it as MM-capable whenever the
|
||||
# target is.
|
||||
if (
|
||||
not self.supports_mm_inputs
|
||||
and self.draft_model_config.hf_config.model_type == "inkling_mtp"
|
||||
):
|
||||
self.supports_mm_inputs = MULTIMODAL_REGISTRY.supports_multimodal_inputs(
|
||||
vllm_config.model_config
|
||||
)
|
||||
self.inputs_embeds: torch.Tensor | None = None
|
||||
if self.supports_mm_inputs:
|
||||
self.inputs_embeds = torch.zeros(
|
||||
self.max_num_tokens, self.hidden_size, dtype=self.dtype, device=device
|
||||
)
|
||||
|
||||
# Input id overrides for the last num_speculative_steps - 1 draft steps.
|
||||
# Used by chunked-prefilling requests to swap in the future prefill token
|
||||
@@ -80,14 +61,6 @@ class MultiModuleMTPSpeculator(DraftModelSpeculator):
|
||||
device=self.device,
|
||||
)
|
||||
self.cached_draft_input_embeds: torch.Tensor | None = None
|
||||
if self.supports_mm_inputs:
|
||||
self.cached_draft_input_embeds = torch.zeros(
|
||||
self.max_num_reqs,
|
||||
self.num_speculative_steps - 1,
|
||||
self.hidden_size,
|
||||
dtype=self.dtype,
|
||||
device=self.device,
|
||||
)
|
||||
self.cached_target_hidden_states = torch.zeros(
|
||||
self.max_num_reqs,
|
||||
self.num_speculative_steps - 1,
|
||||
@@ -105,6 +78,25 @@ class MultiModuleMTPSpeculator(DraftModelSpeculator):
|
||||
) -> nn.Module:
|
||||
return load_eagle_model(target_model, self.vllm_config)
|
||||
|
||||
def load_model(self, target_model: nn.Module) -> None:
|
||||
super().load_model(target_model)
|
||||
if not self.supports_mm_inputs:
|
||||
return
|
||||
|
||||
self.inputs_embeds = torch.zeros(
|
||||
self.max_num_tokens,
|
||||
self.hidden_size,
|
||||
dtype=self.dtype,
|
||||
device=self.device,
|
||||
)
|
||||
self.cached_draft_input_embeds = torch.zeros(
|
||||
self.max_num_reqs,
|
||||
self.num_speculative_steps - 1,
|
||||
self.hidden_size,
|
||||
dtype=self.dtype,
|
||||
device=self.device,
|
||||
)
|
||||
|
||||
def init_cudagraph_manager(self, cudagraph_mode: CUDAGraphMode) -> None:
|
||||
# TODO(TheEpicDolphin): Support piecewise cudagraph for multi-module MTP.
|
||||
if cudagraph_mode.has_piecewise_cudagraphs():
|
||||
|
||||
@@ -13,6 +13,8 @@ from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.distributed.eplb.eplb_state import EplbState
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.model_executor.models import supports_multimodal_embeddings
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig
|
||||
from vllm.v1.worker.gpu.attn_utils import (
|
||||
build_attn_metadata,
|
||||
@@ -137,6 +139,8 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
device=device,
|
||||
)
|
||||
|
||||
self.supports_mm_inputs = False
|
||||
|
||||
@abstractmethod
|
||||
def load_draft_model(
|
||||
self,
|
||||
@@ -164,6 +168,19 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
)
|
||||
self.draft_attn_layer_names = all_attn_layers - target_attn_layer_names
|
||||
|
||||
target_supports_mm = MULTIMODAL_REGISTRY.supports_multimodal_inputs(
|
||||
self.vllm_config.model_config
|
||||
)
|
||||
draft_supports_mm = supports_multimodal_embeddings(self.model)
|
||||
self.supports_mm_inputs = target_supports_mm and draft_supports_mm
|
||||
if target_supports_mm and not draft_supports_mm:
|
||||
logger.warning_once(
|
||||
"Draft model %s does not support external multimodal embeddings. "
|
||||
"Embeddings from the target model will not be passed to the "
|
||||
"drafter; using text-only draft inputs instead.",
|
||||
type(self.model).__name__,
|
||||
)
|
||||
|
||||
def set_eplb_state(self, eplb_state: EplbState) -> None:
|
||||
"""Inject EPLB state after construction."""
|
||||
self.eplb_state = eplb_state
|
||||
|
||||
Reference in New Issue
Block a user