[Refactor] Remove dead code multiple places (#60120)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
@@ -4464,12 +4464,6 @@ def cpu_gemm_wna16(
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def cpu_activation_lut_bf16(input: torch.Tensor, activation: str) -> torch.Tensor:
|
|
||||||
out = torch.empty_like(input)
|
|
||||||
torch.ops._C.activation_lut_bf16(out, input, activation)
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def cpu_prepack_moe_weight(
|
def cpu_prepack_moe_weight(
|
||||||
weight: torch.Tensor,
|
weight: torch.Tensor,
|
||||||
isa: str,
|
isa: str,
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ from vllm.lora.utils import (
|
|||||||
from vllm.model_executor.layers.fused_moe import MoERunner
|
from vllm.model_executor.layers.fused_moe import MoERunner
|
||||||
from vllm.model_executor.models import (
|
from vllm.model_executor.models import (
|
||||||
SupportsLoRA,
|
SupportsLoRA,
|
||||||
SupportsMultiModal,
|
|
||||||
is_pooling_model,
|
is_pooling_model,
|
||||||
supports_multimodal,
|
supports_multimodal,
|
||||||
)
|
)
|
||||||
@@ -60,9 +59,6 @@ DEFAULT_LANGUAGE_WRAPPER_KEY = "language_model"
|
|||||||
class SupportsLoRAModel(nn.Module, SupportsLoRA): ...
|
class SupportsLoRAModel(nn.Module, SupportsLoRA): ...
|
||||||
|
|
||||||
|
|
||||||
class SupportsLoRAMultiModalModel(SupportsLoRAModel, SupportsMultiModal): ...
|
|
||||||
|
|
||||||
|
|
||||||
class AdapterLRUCache(LRUCache[int, T]):
|
class AdapterLRUCache(LRUCache[int, T]):
|
||||||
def __init__(self, capacity: int, deactivate_fn: Callable[[int], object]):
|
def __init__(self, capacity: int, deactivate_fn: Callable[[int], object]):
|
||||||
super().__init__(capacity)
|
super().__init__(capacity)
|
||||||
|
|||||||
@@ -973,34 +973,6 @@ class CPUExpertsInt4(mk.FusedMoEExpertsModular):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# ===========================================================================
|
|
||||||
# INT8 W8A8 MoE
|
|
||||||
# ===========================================================================
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_int8_moe_layer_for_cpu(
|
|
||||||
w13: torch.Tensor,
|
|
||||||
w2: torch.Tensor,
|
|
||||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
|
||||||
"""Prepack INT8 MoE weights for the current CPU architecture."""
|
|
||||||
# SMMLA packing for AArch64
|
|
||||||
if current_platform.get_cpu_architecture() == CpuArchEnum.ARM:
|
|
||||||
return (
|
|
||||||
cpu_prepack_moe_weight_int8(w13, "neon"),
|
|
||||||
cpu_prepack_moe_weight_int8(w2, "neon"),
|
|
||||||
)
|
|
||||||
# VSX packing for POWER
|
|
||||||
if current_platform.get_cpu_architecture() == CpuArchEnum.POWERPC:
|
|
||||||
return (
|
|
||||||
cpu_prepack_moe_weight_int8(w13, "vsx"),
|
|
||||||
cpu_prepack_moe_weight_int8(w2, "vsx"),
|
|
||||||
)
|
|
||||||
# VNNI packing for x86
|
|
||||||
packed_w13 = torch.ops._C.convert_weight_packed(w13)
|
|
||||||
packed_w2 = torch.ops._C.convert_weight_packed(w2)
|
|
||||||
return packed_w13, packed_w2
|
|
||||||
|
|
||||||
|
|
||||||
class CPUExpertsInt8(mk.FusedMoEExpertsModular):
|
class CPUExpertsInt8(mk.FusedMoEExpertsModular):
|
||||||
"""CPU INT8 W8A8 per-channel weight / dynamic per-token activation
|
"""CPU INT8 W8A8 per-channel weight / dynamic per-token activation
|
||||||
modular MoE experts."""
|
modular MoE experts."""
|
||||||
|
|||||||
@@ -564,9 +564,6 @@ class BertMLMHead(nn.Module):
|
|||||||
self.layer_norm = nn.LayerNorm(hidden_size, eps=layer_norm_eps)
|
self.layer_norm = nn.LayerNorm(hidden_size, eps=layer_norm_eps)
|
||||||
self.decoder = nn.Linear(hidden_size, vocab_size, bias=True)
|
self.decoder = nn.Linear(hidden_size, vocab_size, bias=True)
|
||||||
|
|
||||||
def tie_weights_with_embeddings(self, embeddings_weight: torch.Tensor):
|
|
||||||
self.decoder.weight = embeddings_weight
|
|
||||||
|
|
||||||
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
||||||
x = self.dense(hidden_states)
|
x = self.dense(hidden_states)
|
||||||
x = self.activation(x)
|
x = self.activation(x)
|
||||||
|
|||||||
@@ -129,13 +129,6 @@ class BlipAttention(nn.Module):
|
|||||||
prefix=f"{prefix}.attn",
|
prefix=f"{prefix}.attn",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
|
||||||
return (
|
|
||||||
tensor.view(bsz, seq_len, self.num_heads, self.head_dim)
|
|
||||||
.transpose(1, 2)
|
|
||||||
.contiguous()
|
|
||||||
)
|
|
||||||
|
|
||||||
def forward(
|
def forward(
|
||||||
self,
|
self,
|
||||||
hidden_states: torch.Tensor,
|
hidden_states: torch.Tensor,
|
||||||
|
|||||||
@@ -269,17 +269,6 @@ class DiffusionGemmaForConditionalGeneration(
|
|||||||
eps=getattr(text_config, "rms_norm_eps", 1e-6),
|
eps=getattr(text_config, "rms_norm_eps", 1e-6),
|
||||||
)
|
)
|
||||||
|
|
||||||
def compute_self_conditioning(
|
|
||||||
self,
|
|
||||||
inputs_embeds: torch.Tensor,
|
|
||||||
probs: torch.Tensor,
|
|
||||||
) -> torch.Tensor:
|
|
||||||
embed_weight = self.model.embed_tokens.weight
|
|
||||||
soft_embeds = torch.matmul(
|
|
||||||
probs.to(embed_weight.dtype), embed_weight
|
|
||||||
) * self.model.normalizer.to(inputs_embeds.dtype)
|
|
||||||
return self.self_conditioning(inputs_embeds, soft_embeds)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------ #
|
# ------------------------------------------------------------------ #
|
||||||
# Multimodal: reuse Gemma4's image parsing, processing & embedding
|
# Multimodal: reuse Gemma4's image parsing, processing & embedding
|
||||||
# ------------------------------------------------------------------ #
|
# ------------------------------------------------------------------ #
|
||||||
|
|||||||
@@ -255,25 +255,6 @@ class KeyeVisionEmbeddings(nn.Module):
|
|||||||
patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, -1, dim)
|
patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, -1, dim)
|
||||||
return patch_pos_embed
|
return patch_pos_embed
|
||||||
|
|
||||||
def fetch_position_embedding_lfu_cache(self, embeddings, h, w, max_cache: int = 20):
|
|
||||||
grid = (h, w)
|
|
||||||
if grid in self.cache_position_embedding:
|
|
||||||
self.cache_position_count[grid] += 1
|
|
||||||
return self.cache_position_embedding[grid]
|
|
||||||
|
|
||||||
if len(self.cache_position_embedding) >= max_cache:
|
|
||||||
min_hit_grid = min(
|
|
||||||
self.cache_position_count,
|
|
||||||
key=self.cache_position_count.__getitem__,
|
|
||||||
)
|
|
||||||
self.cache_position_count.pop(min_hit_grid)
|
|
||||||
self.cache_position_embedding.pop(min_hit_grid)
|
|
||||||
|
|
||||||
position_embedding = self.interpolate_pos_encoding(embeddings, h, w, True)
|
|
||||||
self.cache_position_count[grid] = 1
|
|
||||||
self.cache_position_embedding[grid] = position_embedding
|
|
||||||
return position_embedding
|
|
||||||
|
|
||||||
def forward(
|
def forward(
|
||||||
self,
|
self,
|
||||||
pixel_values: torch.FloatTensor,
|
pixel_values: torch.FloatTensor,
|
||||||
|
|||||||
@@ -455,27 +455,6 @@ class SiglipVisionEmbeddings(nn.Module):
|
|||||||
patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, -1, dim)
|
patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, -1, dim)
|
||||||
return patch_pos_embed
|
return patch_pos_embed
|
||||||
|
|
||||||
def fetch_position_embedding_lfu_cache(
|
|
||||||
self, embeddings: torch.Tensor, h: int, w: int, max_cache: int = 20
|
|
||||||
):
|
|
||||||
grid = (h, w)
|
|
||||||
if grid in self.cache_position_embedding:
|
|
||||||
self.cache_position_count[grid] += 1
|
|
||||||
return self.cache_position_embedding[grid]
|
|
||||||
|
|
||||||
if len(self.cache_position_embedding) >= max_cache:
|
|
||||||
min_hit_grid = min(
|
|
||||||
self.cache_position_count,
|
|
||||||
key=self.cache_position_count.__getitem__,
|
|
||||||
)
|
|
||||||
self.cache_position_count.pop(min_hit_grid)
|
|
||||||
self.cache_position_embedding.pop(min_hit_grid)
|
|
||||||
|
|
||||||
position_embedding = self.interpolate_pos_encoding(embeddings, h, w, True)
|
|
||||||
self.cache_position_count[grid] = 1
|
|
||||||
self.cache_position_embedding[grid] = position_embedding
|
|
||||||
return position_embedding
|
|
||||||
|
|
||||||
def forward(
|
def forward(
|
||||||
self,
|
self,
|
||||||
pixel_values: torch.FloatTensor,
|
pixel_values: torch.FloatTensor,
|
||||||
|
|||||||
@@ -1256,12 +1256,6 @@ class AudioEmbedding(nn.Module):
|
|||||||
self.input_embeds = None
|
self.input_embeds = None
|
||||||
self.audio_embed_sizes = None
|
self.audio_embed_sizes = None
|
||||||
|
|
||||||
def set_audio_embeds(self, input_embeds: torch.Tensor) -> None:
|
|
||||||
self.input_embeds = input_embeds
|
|
||||||
|
|
||||||
def set_audio_embed_sizes(self, audio_embed_sizes: torch.Tensor) -> None:
|
|
||||||
self.audio_embed_sizes = audio_embed_sizes
|
|
||||||
|
|
||||||
def get_audio_features(
|
def get_audio_features(
|
||||||
self,
|
self,
|
||||||
input_embeds: torch.Tensor,
|
input_embeds: torch.Tensor,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from vllm.distributed import (
|
|||||||
get_pp_group,
|
get_pp_group,
|
||||||
get_tensor_model_parallel_rank,
|
get_tensor_model_parallel_rank,
|
||||||
get_tensor_model_parallel_world_size,
|
get_tensor_model_parallel_world_size,
|
||||||
get_tp_group,
|
|
||||||
)
|
)
|
||||||
from vllm.logger import init_logger
|
from vllm.logger import init_logger
|
||||||
from vllm.model_executor.layers.activation import SiluAndMul, SwigluStepAndMul
|
from vllm.model_executor.layers.activation import SiluAndMul, SwigluStepAndMul
|
||||||
@@ -459,7 +458,6 @@ class Step3p5DecoderLayer(nn.Module):
|
|||||||
f"Unsupported attention implementation: {config.att_impl_type}"
|
f"Unsupported attention implementation: {config.att_impl_type}"
|
||||||
)
|
)
|
||||||
self.use_moe = False
|
self.use_moe = False
|
||||||
self.tp_group = get_tp_group()
|
|
||||||
self.use_fused_all_reduce = (
|
self.use_fused_all_reduce = (
|
||||||
get_tensor_model_parallel_world_size() > 1
|
get_tensor_model_parallel_world_size() > 1
|
||||||
and get_dp_group().world_size == 1
|
and get_dp_group().world_size == 1
|
||||||
@@ -496,13 +494,6 @@ class Step3p5DecoderLayer(nn.Module):
|
|||||||
)
|
)
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
|
||||||
def add_and_maybe_inplace_all_reduce(
|
|
||||||
self, in1: torch.Tensor, in2: torch.Tensor
|
|
||||||
) -> torch.Tensor:
|
|
||||||
if not self.use_fused_all_reduce:
|
|
||||||
return in1 + in2
|
|
||||||
return self.tp_group.all_reduce(in1 + in2)
|
|
||||||
|
|
||||||
def forward(
|
def forward(
|
||||||
self, positions: torch.Tensor, hidden_states: torch.Tensor
|
self, positions: torch.Tensor, hidden_states: torch.Tensor
|
||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
|
|||||||
@@ -718,65 +718,6 @@ class TritonPointerInputVariant:
|
|||||||
return TritonWarmupTensor(dtype, aligned=self.is_aligned(name), shape=shape)
|
return TritonWarmupTensor(dtype, aligned=self.is_aligned(name), shape=shape)
|
||||||
|
|
||||||
|
|
||||||
def _literal_str_refs(node: ast.AST) -> tuple[str | int, ...]:
|
|
||||||
if isinstance(node, ast.Constant) and isinstance(node.value, str | int):
|
|
||||||
return (node.value,)
|
|
||||||
if isinstance(node, ast.List | ast.Tuple):
|
|
||||||
refs: list[str | int] = []
|
|
||||||
for elt in node.elts:
|
|
||||||
if isinstance(elt, ast.Constant) and isinstance(elt.value, str | int):
|
|
||||||
refs.append(elt.value)
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
f"Unsupported Triton specialization ref: {ast.dump(elt)}"
|
|
||||||
)
|
|
||||||
return tuple(refs)
|
|
||||||
raise ValueError(f"Unsupported Triton specialization refs: {ast.dump(node)}")
|
|
||||||
|
|
||||||
|
|
||||||
def _normalize_arg_refs(
|
|
||||||
refs: tuple[str | int, ...],
|
|
||||||
arg_names: tuple[str, ...],
|
|
||||||
) -> frozenset[str]:
|
|
||||||
names: set[str] = set()
|
|
||||||
for ref in refs:
|
|
||||||
if isinstance(ref, int):
|
|
||||||
names.add(arg_names[ref])
|
|
||||||
else:
|
|
||||||
names.add(ref)
|
|
||||||
return frozenset(names)
|
|
||||||
|
|
||||||
|
|
||||||
def _decorator_keyword_refs(
|
|
||||||
function_def: ast.FunctionDef,
|
|
||||||
keyword_name: str,
|
|
||||||
) -> tuple[str | int, ...]:
|
|
||||||
for decorator in function_def.decorator_list:
|
|
||||||
if not isinstance(decorator, ast.Call):
|
|
||||||
continue
|
|
||||||
decorator_name = get_ast_full_name(decorator.func)
|
|
||||||
if decorator_name not in ("triton.jit", "jit"):
|
|
||||||
continue
|
|
||||||
for keyword in decorator.keywords:
|
|
||||||
if keyword.arg == keyword_name:
|
|
||||||
return _literal_str_refs(keyword.value)
|
|
||||||
return ()
|
|
||||||
|
|
||||||
|
|
||||||
def _triton_do_not_specialize_args(
|
|
||||||
kernel: Callable[..., Any],
|
|
||||||
function_def: ast.FunctionDef,
|
|
||||||
arg_names: tuple[str, ...],
|
|
||||||
) -> frozenset[str]:
|
|
||||||
refs = getattr(kernel, "do_not_specialize", None)
|
|
||||||
if refs is not None:
|
|
||||||
return _normalize_arg_refs(tuple(refs), arg_names)
|
|
||||||
return _normalize_arg_refs(
|
|
||||||
_decorator_keyword_refs(function_def, "do_not_specialize"),
|
|
||||||
arg_names,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _triton_constexpr_arg_names(
|
def _triton_constexpr_arg_names(
|
||||||
kernel: Callable[..., Any],
|
kernel: Callable[..., Any],
|
||||||
function_def: ast.FunctionDef,
|
function_def: ast.FunctionDef,
|
||||||
@@ -821,25 +762,3 @@ def _pointer_arg_names(
|
|||||||
if name in candidate_names:
|
if name in candidate_names:
|
||||||
pointer_names.add(name)
|
pointer_names.add(name)
|
||||||
return frozenset(pointer_names)
|
return frozenset(pointer_names)
|
||||||
|
|
||||||
|
|
||||||
def trace_triton_kernel_specialization_args(
|
|
||||||
kernel: Callable[..., Any],
|
|
||||||
) -> tuple[str, ...]:
|
|
||||||
function_def = get_function_source_node(kernel)
|
|
||||||
if not isinstance(function_def, ast.FunctionDef):
|
|
||||||
raise ValueError("Expected Triton kernel to be defined as a function")
|
|
||||||
source_fn = getattr(kernel, "fn", kernel)
|
|
||||||
arg_names = tuple(inspect.signature(source_fn).parameters)
|
|
||||||
constexpr_args = _triton_constexpr_arg_names(kernel, function_def, arg_names)
|
|
||||||
do_not_specialize_args = _triton_do_not_specialize_args(
|
|
||||||
kernel, function_def, arg_names
|
|
||||||
)
|
|
||||||
pointer_args = _pointer_arg_names(function_def, arg_names)
|
|
||||||
|
|
||||||
return tuple(
|
|
||||||
name
|
|
||||||
for name in arg_names
|
|
||||||
if name in constexpr_args
|
|
||||||
or (name not in pointer_args and name not in do_not_specialize_args)
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -178,14 +178,6 @@ def _tekken_token_to_id(tokenizer: "Tekkenizer", t: str | bytes) -> int:
|
|||||||
return tokenizer.unk_id
|
return tokenizer.unk_id
|
||||||
|
|
||||||
|
|
||||||
def mistral_common_tekkenizer(tokenizer: object) -> "Tekkenizer | None":
|
|
||||||
"""Return the underlying `Tekkenizer` for a `MistralCommonBackend`."""
|
|
||||||
mistral = getattr(tokenizer, "tokenizer", None)
|
|
||||||
instruct = getattr(mistral, "instruct_tokenizer", None)
|
|
||||||
tekken = getattr(instruct, "tokenizer", None)
|
|
||||||
return tekken if isinstance(tekken, Tekkenizer) else None
|
|
||||||
|
|
||||||
|
|
||||||
def tekken_convert_ids_to_tokens(
|
def tekken_convert_ids_to_tokens(
|
||||||
tokenizer: "Tekkenizer", ids: Sequence[int]
|
tokenizer: "Tekkenizer", ids: Sequence[int]
|
||||||
) -> list[str | bytes]:
|
) -> list[str | bytes]:
|
||||||
|
|||||||
Reference in New Issue
Block a user