Skip to content
3 changes: 2 additions & 1 deletion tests/models/multimodal/generation/test_memory_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from vllm.distributed import cleanup_dist_env_and_memory
from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
from vllm.platforms import current_platform
from vllm.utils.mem_utils import KiB_bytes, MiB_bytes, format_mib
from vllm.utils.mem_constants import KiB_bytes, MiB_bytes
from vllm.utils.mem_utils import format_mib

MODEL_NAME = "Qwen/Qwen3-VL-4B-Instruct"
RANDOM_PREFIX_LEN = 100
Expand Down
10 changes: 0 additions & 10 deletions vllm/compilation/passes/fx_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

import operator
from collections.abc import Iterable, Iterator

from torch import fx
Expand Down Expand Up @@ -29,15 +28,6 @@ def find_auto_fn(nodes: Iterable[fx.Node], op: OpOverload) -> fx.Node:
return node


# Returns the getitem node that extracts the idx-th element from node
# (if it exists)
def find_getitem_maybe(node: fx.Node, idx: int) -> fx.Node | None:
for user in node.users:
if is_func(user, operator.getitem) and user.args[1] == idx:
return user
return None


# An auto-functionalization-aware utility for finding nodes with a specific op
# Also handles op overload packets and finds all overloads
def find_op_nodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
_config_lock = threading.Lock()


def is_false(value: str) -> bool:
"""Check if the given string value is equivalent to 'false'."""
return value.lower() in ("false", "0", "no", "n", "off")


def lmcache_get_or_create_config() -> V1Config:
"""Get the LMCache configuration from the environment variable
`LMCACHE_CONFIG_FILE`. If the environment variable is not set, this
Expand Down Expand Up @@ -97,75 +92,6 @@ def mla_enabled(model_config: "ModelConfig") -> bool:
)


def create_lmcache_metadata(
vllm_config=None, model_config=None, parallel_config=None, cache_config=None
):
"""
Create LMCacheEngineMetadata from vLLM configuration.

This function extracts common metadata creation logic that was duplicated
across multiple files.

Args:
vllm_config (VllmConfig): vLLM configuration object containing model,
parallel, and cache configs (alternative to
individual config parameters)
model_config (ModelConfig): Model configuration (alternative to
vllm_config)
parallel_config (ParallelConfig): Parallel configuration (alternative
to vllm_config)
cache_config (CacheConfig): Cache configuration (alternative to
vllm_config)
"""
# Third Party
# First Party
from lmcache.config import LMCacheEngineMetadata

from vllm.utils.torch_utils import get_kv_cache_torch_dtype

config = lmcache_get_or_create_config()
# Support both vllm_config object and individual config parameters
if vllm_config is not None:
model_cfg = vllm_config.model_config
parallel_cfg = vllm_config.parallel_config
cache_cfg = vllm_config.cache_config
else:
if model_config is None or parallel_config is None or cache_config is None:
raise ValueError(
"Either vllm_config must be provided, or all of "
"model_config, parallel_config, and cache_config must be provided."
)
model_cfg = model_config
parallel_cfg = parallel_config
cache_cfg = cache_config

# Get KV cache dtype
kv_dtype = get_kv_cache_torch_dtype(cache_cfg.cache_dtype, model_cfg.dtype)

# Check if MLA is enabled
use_mla = mla_enabled(model_cfg)

# Construct KV shape (for memory pool)
num_layer = model_cfg.get_num_layers(parallel_cfg)
chunk_size = config.chunk_size
num_kv_head = model_cfg.get_num_kv_heads(parallel_cfg)
head_size = model_cfg.get_head_size()
kv_shape = (num_layer, 1 if use_mla else 2, chunk_size, num_kv_head, head_size)

# Create metadata
metadata = LMCacheEngineMetadata(
model_cfg.model,
parallel_cfg.world_size,
parallel_cfg.rank,
"vllm",
kv_dtype,
kv_shape,
use_mla,
)

return metadata, config


def extract_mm_features(
request: Union["Request", "NewRequestData"], modify: bool = False
) -> tuple[list[str], list["PlaceholderRange"]]:
Expand Down
8 changes: 0 additions & 8 deletions vllm/model_executor/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@

logger = init_logger(__name__)

MOE_LAYER_ROUTER_GATE_SUFFIXES = {
"gate",
"router",
"router_gate",
"shared_expert_gate",
"expert_gate",
}


def get_token_bin_counts_and_mask(
tokens: torch.Tensor,
Expand Down
15 changes: 0 additions & 15 deletions vllm/model_executor/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,21 +1209,6 @@ def _load_file(bin_file: str):
del state


def convert_pyslice_to_tensor(x: Any) -> torch.Tensor:
"""convert PySafeSlice object from safetensors to torch.Tensor

PySafeSlice object supports indexing, which is done before loading the
actual tensor and can reduce the amount of memory being read into the
memory. However, it does not support more advanced functionalities
like `.view()` or `.t()`. Therefore, if we need to modify the loaded
tensor with these more complicated operators, we need to convert to
tensor first.
"""
if not isinstance(x, torch.Tensor):
x = x[:]
return x


def default_weight_loader(param: torch.Tensor, loaded_weight: torch.Tensor) -> None:
"""Default weight loader."""
try:
Expand Down
38 changes: 0 additions & 38 deletions vllm/utils/flashinfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,44 +918,6 @@ def mm_mxfp8_fake(
return torch.empty(A.shape[0], B.shape[1], dtype=out_dtype, device=A.device)


def flashinfer_mm_mxfp8(
a: torch.Tensor,
b: torch.Tensor,
block_scale_a: torch.Tensor,
block_scale_b: torch.Tensor,
out_dtype: torch.dtype,
backend: str = "cutlass",
) -> torch.Tensor:
"""MXFP8 MM helper - mirrors flashinfer_scaled_fp4_mm API.

Takes non-transposed weights and handles transpose internally.

CRITICAL: mm_mxfp8 CUTLASS kernel requires SWIZZLED 1D scales for optimal
performance and accuracy. Both input and weight scales should be in
swizzled format from FlashInfer's mxfp8_quantize(is_sf_swizzled_layout=True).
"""
# a shape [M, K]
# b shape [K, N]
assert a.ndim == 2 and b.ndim == 2
assert a.shape[1] == b.shape[1] # K dimension must match

if block_scale_b.ndim != 1:
raise ValueError(
"mm_mxfp8 expects 1D swizzled weight scales for CUTLASS; "
f"got shape={tuple(block_scale_b.shape)}"
)

# Output tensor [M, N]
return mm_mxfp8(
a,
b.t(), # Transpose weight: [N, K] -> [K, N]
block_scale_a,
block_scale_b,
out_dtype,
backend=backend,
)


def flashinfer_scaled_fp4_mm(
a: torch.Tensor,
b: torch.Tensor,
Expand Down
41 changes: 0 additions & 41 deletions vllm/utils/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,6 @@ def fuse_moe_impl(
)


# @torch.library.register_fake(
# "vllm::fuse_moe_impl",
# )
def fuse_moe_impl_fake(
x: torch.Tensor,
gate_up_weight: torch.Tensor,
down_weight: torch.Tensor,
gate_up_scale: torch.Tensor,
down_scale: torch.Tensor,
act_and_mul_scale: torch.Tensor,
topk_ids: torch.Tensor,
topk_scale: torch.Tensor,
rank_ep: int,
num_expert_total: int,
use_bf16_mul: bool = True,
shared_output: torch.Tensor = None,
output: torch.Tensor = None,
) -> torch.Tensor:
return torch.empty_like(x)


def hpc_fuse_moe(
x: torch.Tensor,
gate_up_weight: torch.Tensor,
Expand Down Expand Up @@ -166,26 +145,6 @@ def fuse_moe_blockwise_impl(
)


# @torch.library.register_fake(
# "vllm::fuse_moe_blockwise_impl",
# )
def fuse_moe_blockwise_impl_fake(
x: torch.Tensor,
x_scale: torch.Tensor,
gate_up_weight: torch.Tensor,
gate_up_weight_scale: torch.Tensor,
down_weight: torch.Tensor,
down_weight_scale: torch.Tensor,
topk_ids: torch.Tensor,
topk_scale: torch.Tensor,
rank_ep: int,
num_expert_total: int,
shared_output: torch.Tensor = None,
output: torch.Tensor = None,
) -> torch.Tensor:
return torch.empty_like(x)


def hpc_fuse_moe_blockwise(
x: torch.Tensor,
x_scale: torch.Tensor,
Expand Down
5 changes: 0 additions & 5 deletions vllm/utils/mem_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ def get_max_shared_memory_bytes(gpu: int = 0) -> int:
return int(max_shared_mem)


def get_cpu_memory() -> int:
"""Returns the total CPU memory of the node in bytes."""
return psutil.virtual_memory().total


_UMA_PRESSURE_THRESHOLD = 0.8
_UMA_MIN_RELEASE_BYTES = 512 * MiB_bytes

Expand Down
9 changes: 0 additions & 9 deletions vllm/utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,6 @@ def get_kv_cache_quant_algo_string(quant_cfg: dict[str, Any]) -> str | None:
return None


def get_kv_cache_quant_algo_dtype(quant_cfg: dict[str, Any]) -> torch.dtype | None:
"""Get the KV cache quantization algorithm dtype from the quantization config."""
kv_algo_str = get_kv_cache_quant_algo_string(quant_cfg)
if kv_algo_str is not None and kv_algo_str != "auto":
# Only convert if we have a valid dtype string (not "auto" fallback)
return STR_DTYPE_TO_TORCH_DTYPE[kv_algo_str]
return None


def resolve_kv_cache_dtype_string(
kv_cache_dtype: str, model_config: ModelConfig
) -> str:
Expand Down
15 changes: 1 addition & 14 deletions vllm/v1/attention/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
from collections import defaultdict
from collections.abc import Callable, Iterable, Sequence
from dataclasses import dataclass, field, fields, make_dataclass
from dataclasses import dataclass, field, fields
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -975,19 +975,6 @@ def reshape_attn_output_for_spec_decode(attn_output: torch.Tensor) -> torch.Tens
return attn_output.view(total_tokens, attn_output.shape[2], attn_output.shape[3])


def subclass_attention_metadata(
name_prefix: str,
metadata_cls: Any,
fields: list[tuple[str, Any, Any]],
) -> Any:
"""
Return a new subclass of `metadata_cls` with additional fields
"""
name: str = name_prefix + metadata_cls.__name__ # type: ignore
Wrapped = make_dataclass(name, fields, bases=(metadata_cls,))
return Wrapped


@runtime_checkable
class KVSharingFastPrefillMetadata(Protocol):
logits_indices_padded: torch.Tensor | None = None
Expand Down
2 changes: 0 additions & 2 deletions vllm/v1/core/kv_cache_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def __init__(
num_prefill_lookahead: int = 0,
):
self.kv_cache_config = kv_cache_config
self.max_model_len = max_model_len
self.enable_caching = enable_caching
# The scheduling granularity (LCM of all group block sizes), must be a multiple
# of the hash_block_size and the block size of each group.
assert scheduler_block_size % hash_block_size == 0 and all(
Expand Down
2 changes: 0 additions & 2 deletions vllm/v1/core/single_type_kv_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2013,8 +2013,6 @@ def __init__(
)
sink_len = kv_cache_spec.sink_len
assert sink_len is not None and sink_len > 0 and sink_len % self.block_size == 0
num_sink_block = sink_len // self.block_size
self.sink_blocks = self.block_pool.free_block_queue.popleft_n(num_sink_block)


def get_manager_for_kv_cache_spec(
Expand Down
21 changes: 1 addition & 20 deletions vllm/v1/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
EngineCoreSentinel,
fault_tolerant_wrapper,
)
from vllm.v1.kv_cache_interface import KVCacheConfig, get_kv_cache_spec_kind
from vllm.v1.kv_cache_interface import KVCacheConfig
from vllm.v1.metrics.stats import SchedulerIterationDetails, SchedulerStats
from vllm.v1.outputs import ModelRunnerOutput
from vllm.v1.request import Request, RequestStatus
Expand Down Expand Up @@ -430,25 +430,6 @@ def log_field(name: str, field: str) -> str:
supported_pooling_tasks,
)

def get_kv_cache_group_metadata(self) -> list[dict[str, int | str | None]]:
"""Return msgspec-serializable metadata for scheduler KV cache groups."""
kv_cache_config = getattr(self.scheduler, "kv_cache_config", None)
if kv_cache_config is None:
return []

metadata: list[dict[str, int | str | None]] = []
for group_idx, group in enumerate(kv_cache_config.kv_cache_groups):
spec = group.kv_cache_spec
metadata.append(
{
"group_idx": group_idx,
"kind": get_kv_cache_spec_kind(spec).value,
"block_size": spec.block_size,
"sliding_window": getattr(spec, "sliding_window", None),
}
)
return metadata

def add_request(self, request: Request, request_wave: int = 0):
"""Add request to the scheduler.

Expand Down
Loading
Loading