[Refactor] Remove multiple dead codes (#50285)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
@@ -14,10 +14,6 @@ def is_func(node: fx.Node, target: Target) -> bool:
|
|||||||
return bool(node.op == "call_function" and node.target == target)
|
return bool(node.op == "call_function" and node.target == target)
|
||||||
|
|
||||||
|
|
||||||
def is_auto_func(node: fx.Node, op: OpOverload) -> bool:
|
|
||||||
return is_func(node, auto_functionalized) and node.args[0] == op
|
|
||||||
|
|
||||||
|
|
||||||
# Returns the first auto_functionalized node with the given op (if it exists)
|
# Returns the first auto_functionalized node with the given op (if it exists)
|
||||||
def find_auto_fn_maybe(nodes: Iterable[fx.Node], op: OpOverload) -> fx.Node | None:
|
def find_auto_fn_maybe(nodes: Iterable[fx.Node], op: OpOverload) -> fx.Node | None:
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
@@ -42,13 +38,6 @@ def find_getitem_maybe(node: fx.Node, idx: int) -> fx.Node | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# Returns the getitem node that extracts the idx-th element from node
|
|
||||||
def find_getitem(node: fx.Node, idx: int) -> fx.Node:
|
|
||||||
ret = find_getitem_maybe(node, idx)
|
|
||||||
assert ret is not None, f"Could not find getitem {idx} in node {node}"
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
# An auto-functionalization-aware utility for finding nodes with a specific op
|
# An auto-functionalization-aware utility for finding nodes with a specific op
|
||||||
# Also handles op overload packets and finds all overloads
|
# Also handles op overload packets and finds all overloads
|
||||||
def find_op_nodes(
|
def find_op_nodes(
|
||||||
@@ -67,11 +56,3 @@ def find_op_nodes(
|
|||||||
for n in graph.find_nodes(op="call_function", target=auto_functionalized):
|
for n in graph.find_nodes(op="call_function", target=auto_functionalized):
|
||||||
if n.args[0] == op:
|
if n.args[0] == op:
|
||||||
yield n
|
yield n
|
||||||
|
|
||||||
|
|
||||||
# Asserts that the node only has one user and returns it
|
|
||||||
# Even if a node has only 1 user, it might share storage with another node,
|
|
||||||
# which might need to be taken into account.
|
|
||||||
def get_only_user(node: fx.Node) -> fx.Node:
|
|
||||||
assert len(node.users) == 1
|
|
||||||
return next(iter(node.users))
|
|
||||||
|
|||||||
@@ -333,12 +333,3 @@ class VllmFusionPatternMatcherPass(VllmPatternMatcherPass):
|
|||||||
def __call__(self, graph: torch.fx.Graph) -> None:
|
def __call__(self, graph: torch.fx.Graph) -> None:
|
||||||
self.matched_count = self.pm_pass.apply(graph)
|
self.matched_count = self.pm_pass.apply(graph)
|
||||||
VllmPatternMatcherPass.match_table[self.pass_name] += self.matched_count
|
VllmPatternMatcherPass.match_table[self.pass_name] += self.matched_count
|
||||||
|
|
||||||
|
|
||||||
class PrinterInductorPass(VllmInductorPass):
|
|
||||||
def __init__(self, name: str, config: VllmConfig) -> None:
|
|
||||||
super().__init__(config)
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def __call__(self, graph: torch.fx.Graph) -> None:
|
|
||||||
self.dump_graph(graph, self.name)
|
|
||||||
|
|||||||
@@ -2081,9 +2081,6 @@ def model_parallel_is_initialized():
|
|||||||
return _TP is not None and _PP is not None
|
return _TP is not None and _PP is not None
|
||||||
|
|
||||||
|
|
||||||
_TP_STATE_PATCHED = False
|
|
||||||
|
|
||||||
|
|
||||||
def get_tensor_model_parallel_world_size() -> int:
|
def get_tensor_model_parallel_world_size() -> int:
|
||||||
"""Return world size for the tensor model parallel group."""
|
"""Return world size for the tensor model parallel group."""
|
||||||
return get_tp_group().world_size
|
return get_tp_group().world_size
|
||||||
|
|||||||
@@ -2029,15 +2029,6 @@ async def parse_chat_messages_async(
|
|||||||
return conversation, mm_data, mm_uuids
|
return conversation, mm_data, mm_uuids
|
||||||
|
|
||||||
|
|
||||||
def get_history_tool_calls_cnt(conversation: list[ConversationMessage]):
|
|
||||||
idx = 0
|
|
||||||
for msg in conversation:
|
|
||||||
if msg["role"] == "assistant":
|
|
||||||
tool_calls = msg.get("tool_calls")
|
|
||||||
idx += len(list(tool_calls)) if tool_calls is not None else 0 # noqa
|
|
||||||
return idx
|
|
||||||
|
|
||||||
|
|
||||||
_KIMI_MODEL_TYPES = ("kimi_k2", "kimi_k25", "kimi_k3")
|
_KIMI_MODEL_TYPES = ("kimi_k2", "kimi_k25", "kimi_k3")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,8 @@ import torch
|
|||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
import torch.nn.functional as F
|
import torch.nn.functional as F
|
||||||
|
|
||||||
from vllm.distributed import (
|
|
||||||
divide,
|
|
||||||
get_tensor_model_parallel_rank,
|
|
||||||
get_tensor_model_parallel_world_size,
|
|
||||||
)
|
|
||||||
from vllm.logger import init_logger
|
from vllm.logger import init_logger
|
||||||
from vllm.model_executor.custom_op import CustomOp
|
from vllm.model_executor.custom_op import CustomOp
|
||||||
from vllm.model_executor.utils import set_weight_attrs
|
|
||||||
from vllm.platforms import CpuArchEnum, current_platform
|
from vllm.platforms import CpuArchEnum, current_platform
|
||||||
from vllm.triton_utils import tl, triton
|
from vllm.triton_utils import tl, triton
|
||||||
from vllm.utils.collection_utils import LazyDict
|
from vllm.utils.collection_utils import LazyDict
|
||||||
@@ -788,48 +782,6 @@ class XIELU(CustomOp):
|
|||||||
return self.forward_native(input)
|
return self.forward_native(input)
|
||||||
|
|
||||||
|
|
||||||
class ScaledActivation(nn.Module):
|
|
||||||
"""An activation function with post-scale parameters.
|
|
||||||
|
|
||||||
This is used for some quantization methods like AWQ.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
act_module: nn.Module,
|
|
||||||
intermediate_size: int,
|
|
||||||
input_is_parallel: bool = True,
|
|
||||||
params_dtype: torch.dtype | None = None,
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.act = act_module
|
|
||||||
self.input_is_parallel = input_is_parallel
|
|
||||||
if input_is_parallel:
|
|
||||||
tp_size = get_tensor_model_parallel_world_size()
|
|
||||||
intermediate_size_per_partition = divide(intermediate_size, tp_size)
|
|
||||||
else:
|
|
||||||
intermediate_size_per_partition = intermediate_size
|
|
||||||
if params_dtype is None:
|
|
||||||
params_dtype = torch.get_default_dtype()
|
|
||||||
self.scales = nn.Parameter(
|
|
||||||
torch.empty(intermediate_size_per_partition, dtype=params_dtype)
|
|
||||||
)
|
|
||||||
set_weight_attrs(self.scales, {"weight_loader": self.weight_loader})
|
|
||||||
|
|
||||||
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
||||||
return self.act(x) / self.scales
|
|
||||||
|
|
||||||
def weight_loader(self, param: nn.Parameter, loaded_weight: torch.Tensor):
|
|
||||||
param_data = param.data
|
|
||||||
if self.input_is_parallel:
|
|
||||||
tp_rank = get_tensor_model_parallel_rank()
|
|
||||||
shard_size = param_data.shape[0]
|
|
||||||
start_idx = tp_rank * shard_size
|
|
||||||
loaded_weight = loaded_weight.narrow(0, start_idx, shard_size)
|
|
||||||
assert param_data.shape == loaded_weight.shape
|
|
||||||
param_data.copy_(loaded_weight)
|
|
||||||
|
|
||||||
|
|
||||||
_ACTIVATION_REGISTRY = LazyDict(
|
_ACTIVATION_REGISTRY = LazyDict(
|
||||||
{
|
{
|
||||||
"gelu": lambda: GELU(),
|
"gelu": lambda: GELU(),
|
||||||
|
|||||||
@@ -155,58 +155,6 @@ class Conv2dLayer(ConvLayerBase):
|
|||||||
return self._forward_conv(x)
|
return self._forward_conv(x)
|
||||||
|
|
||||||
|
|
||||||
class CausalConv2dLayer(Conv2dLayer):
|
|
||||||
"""
|
|
||||||
A causal version of nn.Conv2d where each location in the 2D matrix would
|
|
||||||
have no access to locations on its right or down
|
|
||||||
All arguments are the same as nn.Conv2d except padding which should be
|
|
||||||
set as None
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
in_channels: int,
|
|
||||||
out_channels: int,
|
|
||||||
kernel_size: int,
|
|
||||||
stride: int,
|
|
||||||
padding: int = 0,
|
|
||||||
dilation: int = 1,
|
|
||||||
groups: int = 1,
|
|
||||||
bias: bool = True,
|
|
||||||
padding_mode: str = "zeros",
|
|
||||||
*,
|
|
||||||
params_dtype: torch.dtype | None = None,
|
|
||||||
) -> None:
|
|
||||||
if padding is not None:
|
|
||||||
raise ValueError(
|
|
||||||
"Argument padding should be set to None for CausalConv2dLayer."
|
|
||||||
)
|
|
||||||
self._left_padding: int = kernel_size - 1
|
|
||||||
self._right_padding: int = stride - 1
|
|
||||||
padding = 0
|
|
||||||
|
|
||||||
super().__init__(
|
|
||||||
in_channels,
|
|
||||||
out_channels,
|
|
||||||
kernel_size,
|
|
||||||
stride,
|
|
||||||
padding,
|
|
||||||
dilation,
|
|
||||||
groups,
|
|
||||||
bias,
|
|
||||||
padding_mode,
|
|
||||||
params_dtype=params_dtype,
|
|
||||||
)
|
|
||||||
|
|
||||||
def forward(
|
|
||||||
self,
|
|
||||||
x: torch.Tensor,
|
|
||||||
) -> torch.Tensor:
|
|
||||||
x = F.pad(x, pad=(self._left_padding, self._right_padding, 0, 0))
|
|
||||||
x = super().forward(x)
|
|
||||||
return x
|
|
||||||
|
|
||||||
|
|
||||||
# --8<-- [start:conv3d]
|
# --8<-- [start:conv3d]
|
||||||
@CustomOp.register("conv3d")
|
@CustomOp.register("conv3d")
|
||||||
class Conv3dLayer(ConvLayerBase):
|
class Conv3dLayer(ConvLayerBase):
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.utils._python_dispatch import TorchDispatchMode
|
|
||||||
|
|
||||||
import vllm.envs as envs
|
import vllm.envs as envs
|
||||||
import vllm.model_executor.layers.fused_moe.modular_kernel as mk
|
import vllm.model_executor.layers.fused_moe.modular_kernel as mk
|
||||||
@@ -234,26 +233,6 @@ class Fp8Config(QuantizationConfig):
|
|||||||
return cache_scale_mapper | QuantizationConfig.get_cache_scale_mapper()
|
return cache_scale_mapper | QuantizationConfig.get_cache_scale_mapper()
|
||||||
|
|
||||||
|
|
||||||
class CopyNumelCounter(TorchDispatchMode):
|
|
||||||
"""
|
|
||||||
Tracks total number of elements modified with `copy_`. Useful for keeping
|
|
||||||
track of weight loading where underlying weights can be arbitrarily
|
|
||||||
transformed (such as with `narrow`) before calling copy.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.copied_numel = 0
|
|
||||||
|
|
||||||
def __torch_dispatch__(self, func, types, args=(), kwargs=None):
|
|
||||||
if kwargs is None:
|
|
||||||
kwargs = {}
|
|
||||||
out = func(*args, **kwargs)
|
|
||||||
if func == torch.ops.aten.copy_.default:
|
|
||||||
self.copied_numel += args[0].numel()
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
class Fp8LinearMethod(LinearMethodBase):
|
class Fp8LinearMethod(LinearMethodBase):
|
||||||
"""Linear method for FP8.
|
"""Linear method for FP8.
|
||||||
Supports loading FP8 checkpoints with static weight scale and
|
Supports loading FP8 checkpoints with static weight scale and
|
||||||
|
|||||||
@@ -25,12 +25,6 @@ MOE_LAYER_ROUTER_GATE_SUFFIXES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def is_layer_moe_router_gate(prefix: str) -> bool:
|
|
||||||
if not prefix:
|
|
||||||
return False
|
|
||||||
return prefix.rsplit(".", 1)[-1] in MOE_LAYER_ROUTER_GATE_SUFFIXES
|
|
||||||
|
|
||||||
|
|
||||||
def get_token_bin_counts_and_mask(
|
def get_token_bin_counts_and_mask(
|
||||||
tokens: torch.Tensor,
|
tokens: torch.Tensor,
|
||||||
vocab_size: int,
|
vocab_size: int,
|
||||||
|
|||||||
@@ -242,10 +242,6 @@ class GlmOcrVisionBlock(Glm4vVisionBlock):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class GlmOcrVisionPatchEmbed(Glm4vVisionPatchEmbed):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class GlmOcrPatchMerger(Glm4vPatchMerger):
|
class GlmOcrPatchMerger(Glm4vPatchMerger):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -103,41 +103,6 @@ class Idefics3ProcessingInfo(BaseProcessingInfo):
|
|||||||
def get_supported_mm_limits(self) -> Mapping[str, int | None]:
|
def get_supported_mm_limits(self) -> Mapping[str, int | None]:
|
||||||
return {"image": None}
|
return {"image": None}
|
||||||
|
|
||||||
def _resize_output_size(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
height: int,
|
|
||||||
width: int,
|
|
||||||
max_len: int | None = None,
|
|
||||||
min_len: int = 1,
|
|
||||||
max_size: int | None = None,
|
|
||||||
) -> tuple[int, int]:
|
|
||||||
# Set default value for max_len if not provided
|
|
||||||
max_len = max(height, width) if max_len is None else max_len
|
|
||||||
aspect_ratio = width / height
|
|
||||||
|
|
||||||
# Handle the maximum size constraint
|
|
||||||
if max_size is not None:
|
|
||||||
max_len = min(max_len, max_size)
|
|
||||||
|
|
||||||
# Adjust dimensions according to the aspect ratio
|
|
||||||
if width >= height:
|
|
||||||
width = max_len
|
|
||||||
height = int(width / aspect_ratio)
|
|
||||||
else:
|
|
||||||
height = max_len
|
|
||||||
width = int(height * aspect_ratio)
|
|
||||||
|
|
||||||
# Ensure both width and height are even (if needed)
|
|
||||||
height += height % 2
|
|
||||||
width += width % 2
|
|
||||||
|
|
||||||
# Ensure dimensions are not smaller than the minimum length
|
|
||||||
height = max(height, min_len)
|
|
||||||
width = max(width, min_len)
|
|
||||||
|
|
||||||
return height, width
|
|
||||||
|
|
||||||
def _get_image_feature_grid_size(
|
def _get_image_feature_grid_size(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
|
|||||||
@@ -1531,13 +1531,6 @@ class LlavaOnevision2MultiModalDataParser(MultiModalDataParser):
|
|||||||
class LlavaOnevision2MultiModalProcessor(
|
class LlavaOnevision2MultiModalProcessor(
|
||||||
BaseMultiModalProcessor[LlavaOnevision2ProcessingInfo]
|
BaseMultiModalProcessor[LlavaOnevision2ProcessingInfo]
|
||||||
):
|
):
|
||||||
def _get_data_parser(self) -> MultiModalDataParser:
|
|
||||||
# Retained for symmetry; vLLM actually fetches the parser via
|
|
||||||
# info.get_data_parser() (see ProcessingInfo override above).
|
|
||||||
return LlavaOnevision2MultiModalDataParser(
|
|
||||||
self.info.get_hf_config().vision_config.spatial_merge_size
|
|
||||||
)
|
|
||||||
|
|
||||||
def _call_hf_processor(
|
def _call_hf_processor(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
prompt: str,
|
||||||
|
|||||||
@@ -77,24 +77,6 @@ class BartScaledWordEmbedding(VocabParallelEmbedding):
|
|||||||
return super().forward(input_ids) * self.embed_scale
|
return super().forward(input_ids) * self.embed_scale
|
||||||
|
|
||||||
|
|
||||||
class BartParallelLMHead(ParallelLMHead):
|
|
||||||
"""
|
|
||||||
This module overrides ParallelLMHead's
|
|
||||||
forward by dividing by embeddings scale,
|
|
||||||
yielding effectively the inverse of
|
|
||||||
BartScaledWordEmbedding
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self, num_embeddings: int, embedding_dim: int, embed_scale: float = 1.0
|
|
||||||
):
|
|
||||||
super().__init__(num_embeddings, embedding_dim)
|
|
||||||
self.embed_scale = embed_scale
|
|
||||||
|
|
||||||
def forward(self, input_ids: torch.Tensor) -> torch.Tensor:
|
|
||||||
return super().forward(input_ids) / self.embed_scale
|
|
||||||
|
|
||||||
|
|
||||||
class BartDecoderLayer(nn.Module):
|
class BartDecoderLayer(nn.Module):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -521,32 +521,6 @@ class Phi4MMAudioEmbeddingInputs(TensorSchema):
|
|||||||
Phi4MMAudioInputs: TypeAlias = Phi4MMAudioFeatureInputs | Phi4MMAudioEmbeddingInputs
|
Phi4MMAudioInputs: TypeAlias = Phi4MMAudioFeatureInputs | Phi4MMAudioEmbeddingInputs
|
||||||
|
|
||||||
|
|
||||||
def cat_with_pad(tensors, dim, padding_value=0):
|
|
||||||
"""
|
|
||||||
cat along dim, while pad to max for all other dims
|
|
||||||
"""
|
|
||||||
ndim = tensors[0].dim()
|
|
||||||
assert all(t.dim() == ndim for t in tensors[1:]), (
|
|
||||||
"All tensors must have the same number of dimensions"
|
|
||||||
)
|
|
||||||
|
|
||||||
out_size = [max(t.shape[i] for t in tensors) for i in range(ndim)]
|
|
||||||
out_size[dim] = sum(t.shape[dim] for t in tensors)
|
|
||||||
output = tensors[0].new_full(out_size, padding_value)
|
|
||||||
|
|
||||||
index = 0
|
|
||||||
for t in tensors:
|
|
||||||
# Create a slice list where every dimension except dim is full slice
|
|
||||||
slices = [slice(0, t.shape[d]) for d in range(ndim)]
|
|
||||||
# Update only the concat dimension slice
|
|
||||||
slices[dim] = slice(index, index + t.shape[dim])
|
|
||||||
|
|
||||||
output[slices] = t
|
|
||||||
index += t.shape[dim]
|
|
||||||
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
def stack_with_pad(
|
def stack_with_pad(
|
||||||
tensors: torch.Tensor | list[torch.Tensor],
|
tensors: torch.Tensor | list[torch.Tensor],
|
||||||
padding_value: int | float = 0,
|
padding_value: int | float = 0,
|
||||||
|
|||||||
@@ -1595,14 +1595,6 @@ class AttModule(nn.Module):
|
|||||||
return x, memory, pos_emb, att_mask
|
return x, memory, pos_emb, att_mask
|
||||||
|
|
||||||
|
|
||||||
class AttBlock(BlockBase, AttModule):
|
|
||||||
"""Attention Block module to support both Attention and Block module."""
|
|
||||||
|
|
||||||
def memory_dims(self, max_len: bool = False) -> tuple[int, int]:
|
|
||||||
"""memory dimensions"""
|
|
||||||
return (1, self.input_size)
|
|
||||||
|
|
||||||
|
|
||||||
def masked_softmax(
|
def masked_softmax(
|
||||||
scores: Tensor,
|
scores: Tensor,
|
||||||
mask: Tensor | None,
|
mask: Tensor | None,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
# Copyright (c) 2025 Skywork
|
# Copyright (c) 2025 Skywork
|
||||||
# Licensed under The MIT License [see LICENSE for details]
|
# Licensed under The MIT License [see LICENSE for details]
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
from collections.abc import Iterable, Mapping
|
from collections.abc import Iterable
|
||||||
from typing import Annotated, Literal, TypeAlias
|
from typing import Annotated, Literal, TypeAlias
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
@@ -15,8 +15,6 @@ import torch.nn as nn
|
|||||||
from transformers import PretrainedConfig
|
from transformers import PretrainedConfig
|
||||||
|
|
||||||
from vllm.config import VllmConfig
|
from vllm.config import VllmConfig
|
||||||
from vllm.config.multimodal import BaseDummyOptions
|
|
||||||
from vllm.inputs import MultiModalDataDict
|
|
||||||
from vllm.model_executor.layers.linear import ReplicatedLinear
|
from vllm.model_executor.layers.linear import ReplicatedLinear
|
||||||
from vllm.model_executor.layers.quantization import QuantizationConfig
|
from vllm.model_executor.layers.quantization import QuantizationConfig
|
||||||
from vllm.model_executor.layers.quantization.auto_awq import AutoAWQConfig
|
from vllm.model_executor.layers.quantization.auto_awq import AutoAWQConfig
|
||||||
@@ -24,7 +22,6 @@ from vllm.model_executor.models.intern_vit import (
|
|||||||
InternVisionModel,
|
InternVisionModel,
|
||||||
)
|
)
|
||||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||||
from vllm.multimodal.processing import BaseDummyInputsBuilder
|
|
||||||
from vllm.sequence import IntermediateTensors
|
from vllm.sequence import IntermediateTensors
|
||||||
from vllm.transformers_utils.processors.internvl import (
|
from vllm.transformers_utils.processors.internvl import (
|
||||||
InternVLImageProcessor,
|
InternVLImageProcessor,
|
||||||
@@ -117,33 +114,6 @@ class SkyworkR1VProcessingInfo(BaseInternVLProcessingInfo):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SkyworkR1VDummyInputsBuilder(BaseDummyInputsBuilder[SkyworkR1VProcessingInfo]):
|
|
||||||
def get_dummy_text(self, mm_counts: Mapping[str, int]) -> str:
|
|
||||||
num_images = mm_counts.get("image", 0)
|
|
||||||
|
|
||||||
return "<image>" * num_images
|
|
||||||
|
|
||||||
def get_dummy_mm_data(
|
|
||||||
self,
|
|
||||||
seq_len: int,
|
|
||||||
mm_counts: Mapping[str, int],
|
|
||||||
mm_options: Mapping[str, BaseDummyOptions],
|
|
||||||
) -> MultiModalDataDict:
|
|
||||||
target_width, target_height = self.info.get_image_size_with_most_features()
|
|
||||||
num_images = mm_counts.get("image", 0)
|
|
||||||
|
|
||||||
image_overrides = mm_options.get("image")
|
|
||||||
|
|
||||||
return {
|
|
||||||
"image": self._get_dummy_images(
|
|
||||||
width=target_width,
|
|
||||||
height=target_height,
|
|
||||||
num_images=num_images,
|
|
||||||
overrides=image_overrides,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@MULTIMODAL_REGISTRY.register_processor(
|
@MULTIMODAL_REGISTRY.register_processor(
|
||||||
BaseInternVLMultiModalProcessor,
|
BaseInternVLMultiModalProcessor,
|
||||||
info=SkyworkR1VProcessingInfo,
|
info=SkyworkR1VProcessingInfo,
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ from vllm.multimodal import NestedTensors
|
|||||||
from vllm.sequence import IntermediateTensors
|
from vllm.sequence import IntermediateTensors
|
||||||
from vllm.utils.math_utils import cdiv
|
from vllm.utils.math_utils import cdiv
|
||||||
from vllm.utils.torch_utils import (
|
from vllm.utils.torch_utils import (
|
||||||
async_tensor_h2d,
|
|
||||||
direct_register_custom_op,
|
direct_register_custom_op,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -673,17 +672,6 @@ def _merge_multimodal_embeddings(
|
|||||||
return inputs_embeds
|
return inputs_embeds
|
||||||
|
|
||||||
|
|
||||||
def isin_list(
|
|
||||||
elements: torch.Tensor,
|
|
||||||
test_elements_list: list[int],
|
|
||||||
) -> torch.Tensor:
|
|
||||||
test_elements = async_tensor_h2d(
|
|
||||||
test_elements_list, dtype=torch.int64, device=elements.device
|
|
||||||
)
|
|
||||||
|
|
||||||
return torch.isin(elements, test_elements)
|
|
||||||
|
|
||||||
|
|
||||||
class StageMissingLayer(nn.Module):
|
class StageMissingLayer(nn.Module):
|
||||||
def __init__(self, stage_name: str, module: nn.Module | None = None) -> None:
|
def __init__(self, stage_name: str, module: nn.Module | None = None) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
@@ -580,40 +580,3 @@ def run_dp_sharded_mrope_vision_model(
|
|||||||
"Found unassigned embeddings"
|
"Found unassigned embeddings"
|
||||||
)
|
)
|
||||||
return out_embeddings
|
return out_embeddings
|
||||||
|
|
||||||
|
|
||||||
def get_llm_pos_ids_for_vision(
|
|
||||||
start_idx: int,
|
|
||||||
vision_idx: int,
|
|
||||||
spatial_merge_size: int,
|
|
||||||
t_index: list[int],
|
|
||||||
grid_hs: torch.Tensor,
|
|
||||||
grid_ws: torch.Tensor,
|
|
||||||
) -> torch.Tensor:
|
|
||||||
llm_pos_ids_list = []
|
|
||||||
llm_grid_h = grid_hs[vision_idx] // spatial_merge_size
|
|
||||||
llm_grid_w = grid_ws[vision_idx] // spatial_merge_size
|
|
||||||
h_index = (
|
|
||||||
torch.arange(llm_grid_h)
|
|
||||||
.view(1, -1, 1)
|
|
||||||
.expand(len(t_index), -1, llm_grid_w)
|
|
||||||
.flatten()
|
|
||||||
)
|
|
||||||
w_index = (
|
|
||||||
torch.arange(llm_grid_w)
|
|
||||||
.view(1, 1, -1)
|
|
||||||
.expand(len(t_index), llm_grid_h, -1)
|
|
||||||
.flatten()
|
|
||||||
)
|
|
||||||
t_index_tensor = (
|
|
||||||
torch.Tensor(t_index)
|
|
||||||
.to(llm_grid_h.device)
|
|
||||||
.view(-1, 1)
|
|
||||||
.expand(-1, llm_grid_h * llm_grid_w)
|
|
||||||
.long()
|
|
||||||
.flatten()
|
|
||||||
)
|
|
||||||
_llm_pos_ids = torch.stack([t_index_tensor, h_index, w_index])
|
|
||||||
llm_pos_ids_list.append(_llm_pos_ids + start_idx)
|
|
||||||
llm_pos_ids = torch.cat(llm_pos_ids_list, dim=1)
|
|
||||||
return llm_pos_ids
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ from vllm.multimodal.inputs import (
|
|||||||
from vllm.multimodal.parse import (
|
from vllm.multimodal.parse import (
|
||||||
ImageSize,
|
ImageSize,
|
||||||
MultiModalDataItems,
|
MultiModalDataItems,
|
||||||
MultiModalDataParser,
|
|
||||||
)
|
)
|
||||||
from vllm.multimodal.processing import (
|
from vllm.multimodal.processing import (
|
||||||
BaseDummyInputsBuilder,
|
BaseDummyInputsBuilder,
|
||||||
@@ -307,14 +306,6 @@ class MiniMaxM3VLDummyInputsBuilder(BaseDummyInputsBuilder[MiniMaxM3VLProcessing
|
|||||||
class MiniMaxM3VLMultiModalProcessor(
|
class MiniMaxM3VLMultiModalProcessor(
|
||||||
BaseMultiModalProcessor[MiniMaxM3VLProcessingInfo]
|
BaseMultiModalProcessor[MiniMaxM3VLProcessingInfo]
|
||||||
):
|
):
|
||||||
def _get_data_parser(self) -> MultiModalDataParser:
|
|
||||||
# Request video metadata (fps + sampled frame indices) so the HF
|
|
||||||
# processor can emit per-frame ``]<]X.X seconds[>[`` timestamp markers,
|
|
||||||
# matching MiniMax's reference video token stream. ``_get_prompt_updates``
|
|
||||||
# reconstructs the same markers from the metadata to keep the prompt
|
|
||||||
# replacement aligned with the processor output.
|
|
||||||
return MultiModalDataParser(video_needs_metadata=True)
|
|
||||||
|
|
||||||
def _call_hf_processor(
|
def _call_hf_processor(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
prompt: str,
|
||||||
|
|||||||
@@ -12,15 +12,6 @@ from torch._C._profiler import _EventType, _ProfilerEvent, _TensorMetadata
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def trim_string_front(string: str, width: int) -> str:
|
|
||||||
if len(string) > width:
|
|
||||||
offset = len(string) - width + 3
|
|
||||||
string = string[offset:]
|
|
||||||
if len(string) > 3:
|
|
||||||
string = "..." + string[3:]
|
|
||||||
return string
|
|
||||||
|
|
||||||
|
|
||||||
def trim_string_back(string: str, width: int) -> str:
|
def trim_string_back(string: str, width: int) -> str:
|
||||||
if len(string) > width:
|
if len(string) > width:
|
||||||
offset = len(string) - width + 3
|
offset = len(string) - width + 3
|
||||||
|
|||||||
@@ -182,10 +182,6 @@ class LRUCache(cachetools.LRUCache[_K, _V]):
|
|||||||
|
|
||||||
self.popitem(remove_pinned=remove_pinned)
|
self.popitem(remove_pinned=remove_pinned)
|
||||||
|
|
||||||
def _remove_old_if_needed(self) -> None:
|
|
||||||
while self.currsize > self.capacity:
|
|
||||||
self.remove_oldest()
|
|
||||||
|
|
||||||
def popitem(self, remove_pinned: bool = False):
|
def popitem(self, remove_pinned: bool = False):
|
||||||
"""Remove and return the `(key, value)` pair least recently used."""
|
"""Remove and return the `(key, value)` pair least recently used."""
|
||||||
if not remove_pinned:
|
if not remove_pinned:
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ from typing import Any
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
|
||||||
class AuxStreamType(Enum):
|
|
||||||
Attention = 1
|
|
||||||
|
|
||||||
|
|
||||||
class EventType(Enum):
|
class EventType(Enum):
|
||||||
Main = 0
|
Main = 0
|
||||||
Attention = 1
|
Attention = 1
|
||||||
|
|||||||
@@ -427,26 +427,6 @@ class FreeKVCacheBlockQueue:
|
|||||||
curr_block = curr_block.next_free_block
|
curr_block = curr_block.next_free_block
|
||||||
|
|
||||||
|
|
||||||
def need_extra_keys(request: Request) -> bool:
|
|
||||||
"""Check whether the blocks allocated to this request need extra hash keys.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (Request): The request.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: Whether blocks allocated to this request need extra hash keys.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Multimodal requests need to include the MM hash.
|
|
||||||
# LoRA requests need to include the LoRA name.
|
|
||||||
# Request with provided cache salt need to include the salt.
|
|
||||||
return (
|
|
||||||
bool(request.mm_features)
|
|
||||||
or (request.lora_request is not None)
|
|
||||||
or (request.cache_salt is not None)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_mm_extra_hash_keys(
|
def _gen_mm_extra_hash_keys(
|
||||||
request: Request, start_token_idx: int, end_token_idx: int, start_mm_idx: int
|
request: Request, start_token_idx: int, end_token_idx: int, start_mm_idx: int
|
||||||
) -> tuple[list[Any], int]:
|
) -> tuple[list[Any], int]:
|
||||||
@@ -1053,20 +1033,6 @@ def _get_kv_cache_groups_uniform_type(
|
|||||||
return [KVCacheGroupSpec(list(spec.kv_cache_specs.keys()), spec)]
|
return [KVCacheGroupSpec(list(spec.kv_cache_specs.keys()), spec)]
|
||||||
|
|
||||||
|
|
||||||
def is_kv_cache_page_size_uniform(kv_cache_spec: dict[str, KVCacheSpec]) -> bool:
|
|
||||||
"""
|
|
||||||
Whether all layers in the given KVCacheSpec have the same page size.
|
|
||||||
Args:
|
|
||||||
kv_cache_spec: The KVCacheSpec of each attention layer in the model
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if all layers have the same page size, False otherwise.
|
|
||||||
"""
|
|
||||||
|
|
||||||
page_sizes = {layer.page_size_bytes for layer in kv_cache_spec.values()}
|
|
||||||
return len(page_sizes) == 1
|
|
||||||
|
|
||||||
|
|
||||||
def unify_kv_cache_spec_page_size(
|
def unify_kv_cache_spec_page_size(
|
||||||
kv_cache_spec: dict[str, KVCacheSpec],
|
kv_cache_spec: dict[str, KVCacheSpec],
|
||||||
) -> dict[str, KVCacheSpec]:
|
) -> dict[str, KVCacheSpec]:
|
||||||
|
|||||||
Reference in New Issue
Block a user