[Mini-VLLM] Remove LoRA, plugins, speech-to-text and scale-out surfaces

Production runs one static model behind the OpenAI-compatible API. Every
adapter path and non-OpenAI HTTP surface is unreachable there.

- Delete the LoRA stack: vllm/lora, LoRARequest on the engine wire, the
  scheduler, worker, cudagraph and MoE plumbing, LoRA metrics, the lora
  CLI group, and the LoRA tests.
- Drop the plugin loader in vllm/plugins. Platform resolution is now
  CUDA-only and the general/stat-logger plugin hooks are gone.
- Delete the speech-to-text and realtime entrypoints, the scale-out
  render routes, and vllm/config/speech_to_text.py. GenerationTask is
  generate-only.
- Cut DecodeBenchConnector and the disagg-prefill doc and image. The
  Multi, Offloading and Example connectors stay; production uses the
  CPU KV offload tier.
- Delete the ROCm-only fused KDA chunk kernel (2346 lines) with its CMake
  arch gate, declarations and op registrations. The CUDA build never
  defined the guard and no Python caller existed.
- Delete the orphan Mistral and Pixtral chat fixtures and examples/.
- Fix _check_model: removing the LoRA early return made every request
  fail with "The model ... does not exist. Valid aliases: ...".

Verified on an RTX 3090: import sweep reports 1242 modules with 7 known
optional-dependency failures; a live server answers chat, completions,
responses, tokenize and detokenize with zero log errors and 404 for the
removed surfaces; collection yields 8558 tests with the 3 pre-existing
errors; ruff adds no new finding; the incremental _C build succeeds.

Co-authored-by: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-19 21:06:19 +07:00
co-authored by Hinata
parent 5f3c7bd8ab
commit 5aa2ac64f8
269 changed files with 417 additions and 29932 deletions
-2
View File
@@ -103,7 +103,6 @@ class FastPrefillHelper:
cu_num_logits_np: np.ndarray,
has_prefill: bool,
batch_desc: "BatchExecutionDescriptor",
num_active_loras: int = 0,
) -> FastPrefillBatchMetadata | None:
if (
not has_prefill
@@ -125,7 +124,6 @@ class FastPrefillHelper:
num_reqs=num_reqs,
num_tokens=num_logits,
uniform_token_count=None,
num_active_loras=num_active_loras,
)
num_logits_padded = min(desc.num_tokens, self.max_num_tokens)
return FastPrefillBatchMetadata(
+16 -80
View File
@@ -6,7 +6,7 @@ from collections import defaultdict
from collections.abc import Callable, Iterable, Sequence
from contextlib import ExitStack
from dataclasses import dataclass, replace
from itertools import groupby, product
from itertools import groupby
from typing import TYPE_CHECKING, Any, NamedTuple, Protocol
import torch
@@ -80,7 +80,6 @@ class BatchExecutionDescriptor:
# uniform_token_count unset, so this is what keeps a prefill batch out of one:
# the runner passes None for any batch with a prefill.
max_query_len: int | None = None
num_active_loras: int = 0
# Number of microbatches the batch is split into (DBO). 1 means no splitting.
num_ubatches: int = 1
@@ -113,7 +112,6 @@ def _is_compatible(
num_reqs: int,
num_tokens: int,
uniform_token_count: int | None,
num_active_loras: int,
max_query_len: int | None,
num_ubatches: int,
) -> bool:
@@ -133,7 +131,6 @@ def _is_compatible(
)
and (desc.num_reqs is None or desc.num_reqs >= num_reqs)
and desc.num_tokens >= num_tokens
and desc.num_active_loras == num_active_loras
and desc.num_ubatches == num_ubatches
)
@@ -154,7 +151,6 @@ class CudaGraphManager:
device: torch.device,
cudagraph_mode: CUDAGraphMode,
decode_query_len: int,
lora_capture_cases: list[int] | None = None,
varlen_decode: bool = False,
ubatch_runner: "UBatchRunner | None" = None,
):
@@ -172,10 +168,6 @@ class CudaGraphManager:
self.tp_size = vllm_config.parallel_config.tensor_parallel_size
self.is_first_pp_rank = get_pp_group().is_first_rank
self.is_last_pp_rank = get_pp_group().is_last_rank
self.lora_capture_cases = lora_capture_cases or [0]
# Precompute actual num_active_loras -> captured case mapping so that
# dispatch() is a plain dict lookup instead of a per-call bisect.
self._lora_dispatch_map, self._max_lora_case = self._build_lora_dispatch_map()
self.graphs: dict[BatchExecutionDescriptor, torch.cuda.CUDAGraph] = {}
self.pool = current_platform.get_global_graph_pool() if cudagraph_mode else None
@@ -188,7 +180,7 @@ class CudaGraphManager:
self._max_full_descs_to_capture: int | None = None
self._capture_mem_samples: list[int] | None = None
self._candidates: dict[tuple[int, int], list[BatchExecutionDescriptor]] = {}
self._candidates: dict[int, list[BatchExecutionDescriptor]] = {}
self._capture_descs: dict[CUDAGraphMode, list[BatchExecutionDescriptor]] = {}
# Breakable CUDA graph (PW CUDA graph without torch.compile)
@@ -200,32 +192,6 @@ class CudaGraphManager:
self._init_candidates()
def _build_lora_dispatch_map(self) -> tuple[dict[int, int], int]:
"""Precompute actual num_active_loras -> effective captured case.
Mirrors the num_tokens candidate expansion in ``_init_candidates``:
every possible active-LoRA count is mapped ahead of time to the
smallest captured case that can serve it, so ``dispatch`` is a plain
dict lookup instead of a per-call bisect.
"""
captured_with_lora = sorted(c for c in self.lora_capture_cases if c > 0)
if not captured_with_lora:
return {}, 0
dispatch_map: dict[int, int] = {}
case_idx = 0
for n in range(1, captured_with_lora[-1] + 1):
while captured_with_lora[case_idx] < n:
case_idx += 1
dispatch_map[n] = captured_with_lora[case_idx]
return dispatch_map, captured_with_lora[-1]
def _resolve_effective_loras(self, num_active_loras: int) -> int:
"""Map an actual active-LoRA count to its captured graph case."""
if num_active_loras <= 0 or not self._lora_dispatch_map:
return num_active_loras
# Counts above the largest captured case clamp to it.
return self._lora_dispatch_map.get(num_active_loras, self._max_lora_case)
def _maybe_ubatch_twin(
self, desc: BatchExecutionDescriptor
) -> BatchExecutionDescriptor | None:
@@ -302,9 +268,7 @@ class CudaGraphManager:
capture_varlen_decode = (
separate_decode_routine and bool(decode_mode) and self.varlen_decode
)
for num_tokens, num_active_loras in product(
capture_sizes, self.lora_capture_cases
):
for num_tokens in capture_sizes:
# Varlen decode graphs take any mix of 1..decode_query_len tokens per
# request, worst case 1 token per request (or max_num_reqs)
if capture_varlen_decode and num_tokens <= max_decode_tokens:
@@ -313,7 +277,6 @@ class CudaGraphManager:
num_tokens=num_tokens,
num_reqs=min(num_tokens, self.max_num_reqs),
max_query_len=self.decode_query_len,
num_active_loras=num_active_loras,
)
descs_by_mode[decode_mode].append(desc)
# Capture uniform decode specfifc graphs if required
@@ -335,7 +298,6 @@ class CudaGraphManager:
num_tokens=rounded_num_tokens,
num_reqs=rounded_num_reqs,
uniform_token_count=decode_query_len,
num_active_loras=num_active_loras,
)
# avoid duplicate graphs
@@ -365,7 +327,6 @@ class CudaGraphManager:
cg_mode=mixed_mode,
num_tokens=num_tokens,
num_reqs=num_reqs,
num_active_loras=num_active_loras,
)
descs_by_mode[mixed_mode].append(desc)
@@ -379,19 +340,14 @@ class CudaGraphManager:
for mode in (CUDAGraphMode.FULL, CUDAGraphMode.PIECEWISE):
mode_descs = tuple(reversed(descs_by_mode.get(mode, [])))
for num_active_loras in self.lora_capture_cases:
lora_descs = [
d for d in mode_descs if d.num_active_loras == num_active_loras
]
current_range_start = 0
# Dynamic speculative decoding can produce multiple graphs with the same
# num_tokens. Group them so each graph covers the same candidate range.
for num_tokens, group in groupby(lora_descs, lambda d: d.num_tokens):
matching = list(group)
for i in range(current_range_start, num_tokens + 1):
key = (i, num_active_loras)
self._candidates.setdefault(key, []).extend(matching)
current_range_start = num_tokens + 1
current_range_start = 0
# Dynamic speculative decoding can produce multiple graphs with the same
# num_tokens. Group them so each graph covers the same candidate range.
for num_tokens, group in groupby(mode_descs, lambda d: d.num_tokens):
matching = list(group)
for i in range(current_range_start, num_tokens + 1):
self._candidates.setdefault(i, []).extend(matching)
current_range_start = num_tokens + 1
@property
def dp_size(self) -> int:
@@ -515,31 +471,25 @@ class CudaGraphManager:
self._graphs_captured = True
def captured_token_counts(self) -> list[int]:
"""Sorted token counts with a captured graph, ignoring LoRA variants."""
return sorted(
{desc.num_tokens for desc in self.graphs if desc.num_active_loras == 0}
)
"""Sorted token counts with a captured graph."""
return sorted({desc.num_tokens for desc in self.graphs})
def dispatch(
self,
num_reqs: int,
num_tokens: int,
uniform_token_count: int | None,
num_active_loras: int,
max_query_len: int | None = None,
num_ubatches: int = 1,
) -> BatchExecutionDescriptor:
"""Find matching cudagraph descriptor from priority-ordered candidates."""
effective_loras = self._resolve_effective_loras(num_active_loras)
key = (num_tokens, effective_loras)
if self._graphs_captured and num_tokens > 0 and key in self._candidates:
for desc in self._candidates[key]:
if self._graphs_captured and num_tokens > 0 and num_tokens in self._candidates:
for desc in self._candidates[num_tokens]:
if _is_compatible(
desc,
num_reqs,
num_tokens,
uniform_token_count,
effective_loras,
max_query_len,
num_ubatches,
):
@@ -548,7 +498,6 @@ class CudaGraphManager:
cg_mode=CUDAGraphMode.NONE,
num_tokens=num_tokens,
num_reqs=num_reqs,
num_active_loras=effective_loras,
num_ubatches=num_ubatches,
)
@@ -590,7 +539,6 @@ class ModelCudaGraphManager(CudaGraphManager):
device: torch.device,
cudagraph_mode: CUDAGraphMode,
decode_query_len: int,
lora_capture_cases: list[int] | None = None,
varlen_decode: bool = False,
ubatch_runner: "UBatchRunner | None" = None,
):
@@ -599,7 +547,6 @@ class ModelCudaGraphManager(CudaGraphManager):
device,
cudagraph_mode,
decode_query_len,
lora_capture_cases=lora_capture_cases,
varlen_decode=varlen_decode,
ubatch_runner=ubatch_runner,
)
@@ -618,9 +565,7 @@ class ModelCudaGraphManager(CudaGraphManager):
attn_groups: list[list[AttentionGroup]],
kv_cache_config: KVCacheConfig,
pcp_manager: "PCPManager | None" = None,
has_lora: bool = False,
use_aux_hidden_state_outputs: bool = False,
lora_capture_hook: Callable[[int, int, int], None] | None = None,
progress_bar_desc: str = "Capturing CUDA graphs",
) -> None:
"""Capture CUDA graphs for model forward pass."""
@@ -673,10 +618,6 @@ class ModelCudaGraphManager(CudaGraphManager):
num_tokens = desc.num_tokens
num_reqs = desc.num_reqs or min(num_tokens, self.max_num_reqs)
# Set LoRA state before capture so kernels see correct adapters.
if lora_capture_hook is not None:
lora_capture_hook(desc.num_active_loras, num_reqs, num_tokens)
num_tokens_across_dp = (
torch.full((self.dp_size,), num_tokens, dtype=torch.int32, device="cpu")
if self.dp_size > 1
@@ -752,11 +693,7 @@ class ModelCudaGraphManager(CudaGraphManager):
def forward_fn(cg_mode: CUDAGraphMode) -> None:
batch_descriptor = None
if cg_mode == CUDAGraphMode.PIECEWISE:
batch_descriptor = BatchDescriptor(
num_tokens=num_tokens,
has_lora=has_lora,
num_active_loras=desc.num_active_loras,
)
batch_descriptor = BatchDescriptor(num_tokens=num_tokens)
with set_forward_context(
attn_metadata,
self.vllm_config,
@@ -1091,6 +1028,5 @@ def _teardown_profiling_state(runner: "GPUModelRunner") -> None:
clear_layer_kv_caches(layers)
release_hisparse_profiling_cache(runner.compilation_config.static_forward_context)
runner.cache_config.num_gpu_blocks = None
runner.maybe_remove_all_loras(runner.lora_config)
gc.collect()
torch.accelerator.empty_cache()
-11
View File
@@ -49,7 +49,6 @@ def sync_cudagraph_and_dp_padding(
dp_size: int,
dp_rank: int,
max_query_len: int | None = None,
num_active_loras: int = 0,
parallel_config: ParallelConfig | None = None,
allow_ubatching: bool = False,
uniform_decode: bool = False,
@@ -121,7 +120,6 @@ def sync_cudagraph_and_dp_padding(
num_reqs,
ubatch_num_tokens,
synced_uniform_token_count,
num_active_loras=num_active_loras,
num_ubatches=num_ubatches,
)
if 2 * int(num_tokens_across_dp.min()) < ubatch_desc.num_tokens:
@@ -159,7 +157,6 @@ def sync_cudagraph_and_dp_padding(
cg_mode=CUDAGraphMode.NONE,
num_tokens=num_tokens,
num_reqs=num_reqs,
num_active_loras=desired_batch_desc.num_active_loras,
),
DPSyncState(
num_tokens_across_dp=num_tokens_across_dp,
@@ -183,12 +180,10 @@ def sync_cudagraph_and_dp_padding(
# Dispatch for the final synced values, use num_reqs instead of synced_num_reqs
# so we don't perform request padding for PIECEWISE graphs.
# num_active_loras is per-rank and doesn't need cross-rank agreement.
synced_desc = cudagraph_manager.dispatch(
num_reqs,
synced_num_tokens,
synced_uniform_token_count,
num_active_loras=num_active_loras,
max_query_len=synced_max_query_len,
)
@@ -217,7 +212,6 @@ def dispatch_cg_and_sync_dp(
dp_rank: int,
max_query_len: int | None = None,
need_eager: bool = False,
num_active_loras: int = 0,
parallel_config: ParallelConfig | None = None,
allow_ubatching: bool = False,
uniform_decode: bool = False,
@@ -244,8 +238,6 @@ def dispatch_cg_and_sync_dp(
varlen decode graphs. None, as for a batch with a prefill, keeps
the batch out of graphs that constrain it.
need_eager: Force `CUDAGraphMode.NONE` instead of dispatching.
num_active_loras: Active LoRA count for this rank. Does not need
cross-rank agreement; it never changes a bucket's token count.
parallel_config: Only needed to decide whether to microbatch, so
callers that never do (`allow_ubatching=False`) can leave it out.
allow_ubatching: Whether this rank's batch may be split into
@@ -270,7 +262,6 @@ def dispatch_cg_and_sync_dp(
cg_mode=CUDAGraphMode.NONE,
num_tokens=num_tokens,
num_reqs=num_reqs,
num_active_loras=num_active_loras,
)
else:
assert cudagraph_manager is not None, (
@@ -281,7 +272,6 @@ def dispatch_cg_and_sync_dp(
num_reqs,
num_tokens,
dp_sync_state.uniform_token_count if dp_sync_state else uniform_token_count,
num_active_loras=num_active_loras,
max_query_len=max_query_len,
)
@@ -316,7 +306,6 @@ def dispatch_cg_and_sync_dp(
dp_size,
dp_rank,
max_query_len=max_query_len,
num_active_loras=num_active_loras,
parallel_config=parallel_config,
allow_ubatching=allow_ubatching,
uniform_decode=uniform_decode,
-112
View File
@@ -1,112 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""LoRA utilities for the Model Runner V2 and cudagraph."""
from collections.abc import Callable
from typing import TYPE_CHECKING, Any
import numpy as np
from vllm.lora.request import LoRARequest
from vllm.lora.utils import get_captured_lora_counts
if TYPE_CHECKING:
from vllm.config.compilation import CompilationConfig
from vllm.config.lora import LoRAConfig
NO_LORA_ID = 0
def get_lora_capture_cases(
lora_config: "LoRAConfig | None",
compilation_config: "CompilationConfig",
) -> list[int]:
"""Return num_active_loras values for cudagraph capture.
When cudagraph_specialize_lora=True: powers of 2 up to max_loras, plus
max_loras+1. When False: [0, max_loras+1]. When LoRA disabled: [0].
"""
if lora_config is None:
return [0]
if compilation_config.cudagraph_specialize_lora:
specialize = getattr(lora_config, "specialize_active_lora", False)
captured = get_captured_lora_counts(lora_config.max_loras, specialize)
return [0] + [c for c in captured if c > 0]
return [0, lora_config.max_loras + 1]
def get_num_active_loras_for_dispatch(
lora_config: "LoRAConfig | None",
lora_state: "LoraState",
req_ids: list[str],
dummy_run: bool,
) -> int:
"""Compute num_active_loras for cudagraph dispatch."""
if lora_config and not dummy_run:
return len(lora_state.get_activate_loras(req_ids))
if dummy_run and lora_config:
return lora_config.max_loras + 1
return 0
def create_lora_capture_hook(
lora_config: "LoRAConfig | None",
runner: Any,
) -> Callable[[int, int, int], None] | None:
"""Create a hook to set up LoRA state before each cudagraph capture."""
if lora_config is None:
return None
def hook(num_active_loras: int, num_reqs: int, num_tokens: int) -> None:
# Match InputBatch.make_dummy: distribute the remainder evenly so no
# dummy request exceeds ceil(num_tokens / num_reqs) tokens.
num_scheduled = np.full(num_reqs, num_tokens // num_reqs, dtype=np.int32)
num_extra = num_tokens % num_reqs
if num_extra > 0:
num_scheduled[-num_extra:] += 1
with runner.maybe_select_dummy_loras(
lora_config, num_scheduled, num_active_loras=num_active_loras
):
pass
return hook
class LoraState:
def __init__(self, max_num_reqs: int):
self.lora_ids = np.zeros(max_num_reqs, dtype=np.int32)
self.lora_ids.fill(NO_LORA_ID)
# req_id -> lora_request
self.lora_requests: dict[str, LoRARequest] = {}
def add_request(
self, req_id: str, req_index: int, lora_request: LoRARequest | None
) -> None:
if lora_request is not None:
self.lora_requests[req_id] = lora_request
self.lora_ids[req_index] = lora_request.lora_int_id
else:
self.lora_ids[req_index] = NO_LORA_ID
def remove_request(self, req_id: str) -> None:
self.lora_requests.pop(req_id, None)
def make_lora_inputs(
self,
req_ids: list[str],
idx_mapping: np.ndarray,
num_scheduled_tokens: np.ndarray,
) -> tuple[tuple[int, ...], tuple[int, ...], set[LoRARequest]]:
lora_ids = self.lora_ids[idx_mapping]
prompt_lora_mapping = tuple(lora_ids)
token_lora_mapping = tuple(lora_ids.repeat(num_scheduled_tokens))
active_lora_requests: set[LoRARequest] = self.get_activate_loras(req_ids)
return prompt_lora_mapping, token_lora_mapping, active_lora_requests
def get_activate_loras(self, req_ids: list[str]) -> set[LoRARequest]:
active_lora_requests: set[LoRARequest] = set()
for req_id in req_ids:
lora_request = self.lora_requests.get(req_id)
if lora_request is not None:
active_lora_requests.add(lora_request)
return active_lora_requests
+8 -12
View File
@@ -10,7 +10,7 @@ import numpy as np
import torch
from vllm.logger import init_logger
from vllm.model_executor.models.interfaces import SupportsMultiModal, supports_realtime
from vllm.model_executor.models.interfaces import SupportsMultiModal
from vllm.multimodal.encoder_budget import MultiModalBudget
from vllm.multimodal.inputs import MultiModalKwargsItem
from vllm.multimodal.utils import (
@@ -49,7 +49,6 @@ class EncoderRunner:
self.encoder_cache = encoder_cache
self.dtype = dtype
self.device = device
self.is_realtime = supports_realtime(model)
self.cudagraph_manager = cudagraph_manager
self.enable_timing = enable_timing
self.encoder_timing_registry: dict[str, EncoderTimingStats] = {}
@@ -224,22 +223,19 @@ class EncoderRunner:
pin_memory=PIN_MEMORY,
)
# Whether to gather media embeddings this step.
exclude_embeddings: list[bool] | None = None
if not self.is_realtime:
# Non-realtime models only have media embeddings within the prompt.
is_decode = num_computed_tokens >= prefill_lens
if is_decode.all():
# All decode requests, so no need to gather any embeddings.
return [], is_mm_embed
exclude_embeddings = is_decode.tolist()
# Media embeddings only exist within the prompt.
is_decode = num_computed_tokens >= prefill_lens
if is_decode.all():
# All decode requests, so no need to gather any embeddings.
return [], is_mm_embed
exclude_embeddings: list[bool] = is_decode.tolist()
query_start = num_computed_tokens.tolist()
query_end = (num_computed_tokens + num_scheduled_tokens).tolist()
mm_embeds: list[torch.Tensor] = []
for i, req_id in enumerate(req_ids):
if exclude_embeddings is not None and exclude_embeddings[i]:
if exclude_embeddings[i]:
continue
cur_query_start = query_start[i]
-99
View File
@@ -1,99 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from typing import Any
import numpy as np
from vllm.lora.layers import LoRAMapping, LoRAMappingType
from vllm.lora.worker_manager import WorkerLoRAManager
from vllm.multimodal.inputs import MultiModalFeatureSpec
from vllm.v1.worker.gpu.lora_utils import LoraState
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
def set_active_mm_loras(
model: Any,
lora_manager: WorkerLoRAManager,
encoder_cache: EncoderCache | None,
req_id_to_index: dict[str, int],
lora_state: LoraState,
scheduled_encoder_inputs: dict[str, list[int]],
) -> None:
if (
not scheduled_encoder_inputs
or encoder_cache is None
or not lora_manager.supports_tower_connector_lora()
):
return
prompt_lora_mapping: list[int] = []
token_lora_mapping: list[int] = []
lora_requests = set()
encoder_token_counts: list[int] = []
connector_token_counts: list[int] = []
mm_items: list[tuple[int, MultiModalFeatureSpec]] = []
for req_id, encoder_input_ids in scheduled_encoder_inputs.items():
req_idx = req_id_to_index.get(req_id)
if req_idx is None:
continue
lora_id = int(lora_state.lora_ids[req_idx])
mm_features = encoder_cache.mm_features[req_id]
mm_items.extend((lora_id, mm_features[i]) for i in encoder_input_ids)
if lora_id > 0:
lora_request = lora_state.lora_requests.get(req_id)
if lora_request is not None:
lora_requests.add(lora_request)
# Runs items sorted by modality.
mm_items.sort(key=lambda x: x[1].modality)
for lora_id, mm_feature in mm_items:
pos_info = mm_feature.mm_position
tower_tokens, connector_tokens = model.get_mm_lora_token_counts(
modality=mm_feature.modality,
mm_kwargs=mm_feature.data,
num_mm_embeds=pos_info.get_num_embeds(),
)
prompt_lora_mapping.append(lora_id)
token_lora_mapping.extend([lora_id] * tower_tokens)
encoder_token_counts.append(tower_tokens)
connector_token_counts.append(connector_tokens)
if not prompt_lora_mapping:
return
lora_manager.set_active_adapters(
lora_requests,
LoRAMapping(
tuple(token_lora_mapping),
tuple(prompt_lora_mapping),
is_prefill=True,
type=LoRAMappingType.TOWER,
),
)
mm_mapping = model.get_mm_mapping() if hasattr(model, "get_mm_mapping") else None
if (
mm_mapping is None
or not mm_mapping.connector
or not all(count is not None for count in connector_token_counts)
):
return
connector_token_mapping = np.repeat(
np.array(prompt_lora_mapping, dtype=np.int32),
np.array(connector_token_counts, dtype=np.int32),
)
lora_manager.set_active_adapters(
lora_requests,
LoRAMapping(
index_mapping=tuple(connector_token_mapping.tolist()),
prompt_mapping=tuple(prompt_lora_mapping),
is_prefill=True,
type=LoRAMappingType.CONNECTOR,
),
)
+49 -117
View File
@@ -131,14 +131,7 @@ from vllm.v1.worker.gpu.kv_connector import (
KVConnector,
get_kv_connector,
)
from vllm.v1.worker.gpu.lora_utils import (
LoraState,
create_lora_capture_hook,
get_lora_capture_cases,
get_num_active_loras_for_dispatch,
)
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
from vllm.v1.worker.gpu.mm.lora import set_active_mm_loras
from vllm.v1.worker.gpu.model_states import init_model_state
from vllm.v1.worker.gpu.pool.pooling_runner import PoolingRunner
from vllm.v1.worker.gpu.pp_utils import PPHandler
@@ -182,7 +175,6 @@ from vllm.v1.worker.gpu.ubatch_utils import (
UBatchState,
maybe_build_ubatch_runner,
)
from vllm.v1.worker.lora_model_runner_mixin import LoRAModelRunnerMixin
from vllm.v1.worker.utils import (
KVBlockZeroer,
clear_layer_kv_caches,
@@ -194,13 +186,12 @@ from vllm.v1.worker.workspace import lock_workspace, use_workspace_lane
logger = init_logger(__name__)
class GPUModelRunner(LoRAModelRunnerMixin):
class GPUModelRunner:
def __init__(self, vllm_config: VllmConfig, device: torch.device):
self.vllm_config = vllm_config
self.model_config = vllm_config.model_config
self.cache_config = vllm_config.cache_config
self.compilation_config = vllm_config.compilation_config
self.lora_config = vllm_config.lora_config
self.load_config = vllm_config.load_config
self.parallel_config = vllm_config.parallel_config
self.scheduler_config = vllm_config.scheduler_config
@@ -344,14 +335,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.structured_outputs_worker: StructuredOutputsWorker | None = None
self.cudagraph_manager: ModelCudaGraphManager | None = None
# LoRA-related workers.
self.lora_state = LoraState(max_num_reqs=self.max_num_reqs)
self.lora_capture_cases = [0]
if self.lora_config:
self.lora_capture_cases = get_lora_capture_cases(
self.lora_config, self.compilation_config
)
# KV Connector if configured.
self.kv_connector: KVConnector = NO_OP_KV_CONNECTOR
@@ -402,10 +385,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
vllm_config=self.vllm_config,
model_config=self.vllm_config.model_config,
)
if self.lora_config:
self.model = self.load_lora_model(
self.model, self.vllm_config, self.device
)
if self.use_aux_hidden_state_outputs:
assert self.speculative_config is not None
@@ -572,8 +551,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
return None
return speculator.model
def reset_lora_state(self) -> None:
super().reset_lora_state()
def refresh_draft_weights(self) -> None:
# Called whenever the target's weights are replaced (reload, weight
# transfer), so draft weights derived from them must follow.
draft_model = self.get_draft_model()
@@ -593,7 +571,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
reload_weights(
vllm_config, model, weights_iterator, weights_path, is_checkpoint_format
)
self.reset_lora_state()
self.refresh_draft_weights()
self.reset_encoder_cache()
self.reset_mm_cache()
@@ -758,7 +736,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.device,
cudagraph_mode,
decode_query_len=self.decode_query_len,
lora_capture_cases=self.lora_capture_cases,
varlen_decode=self.adaptive_verification is not None,
ubatch_runner=self.ubatch_runner,
)
@@ -898,25 +875,17 @@ class GPUModelRunner(LoRAModelRunnerMixin):
assert self.intermediate_tensors is not None
intermediate_tensors = self.intermediate_tensors[:num_tokens]
max_loras = self.lora_config.max_loras if self.lora_config is not None else 0
with self.maybe_dummy_run_with_lora(
self.lora_config,
num_scheduled_tokens=np.array(num_tokens_per_request, dtype=np.int32),
num_sampled_tokens=None,
remove_lora=True,
num_active_loras=max_loras,
):
# Execute the model.
self.execute_model(
dummy_scheduler_output,
intermediate_tensors=intermediate_tensors,
dummy_run=True,
skip_attn_for_dummy_run=skip_attn,
is_profile=is_profile,
context_len=context_len,
valid_dummy_state_slots=valid_dummy_state_slots,
randomize_inputs=randomize_inputs,
)
# Execute the model.
self.execute_model(
dummy_scheduler_output,
intermediate_tensors=intermediate_tensors,
dummy_run=True,
skip_attn_for_dummy_run=skip_attn,
is_profile=is_profile,
context_len=context_len,
valid_dummy_state_slots=valid_dummy_state_slots,
randomize_inputs=randomize_inputs,
)
self.kv_connector.set_disabled(False)
# Non-last PP ranks don't produce output for sampling.
@@ -1085,46 +1054,41 @@ class GPUModelRunner(LoRAModelRunnerMixin):
torch.accelerator.empty_cache()
start_free_gpu_memory = torch.accelerator.get_memory_info()[0]
with self.maybe_setup_dummy_loras(self.lora_config):
if capture_encoder:
self.model_state.encoder_runner.capture()
if capture_encoder:
self.model_state.encoder_runner.capture()
if capture_decoder:
input_buffers = self.input_buffers
if self.pcp_manager is not None:
input_buffers = self.pcp_manager.input_buffers
self.cudagraph_manager.capture(
self.model,
self.model_state,
input_buffers,
self.intermediate_tensors,
self.block_tables,
self.attn_groups,
self.kv_cache_config,
pcp_manager=self.pcp_manager,
has_lora=self.lora_config is not None,
use_aux_hidden_state_outputs=self.use_aux_hidden_state_outputs,
lora_capture_hook=create_lora_capture_hook(
self.lora_config, self
),
)
self.model_state.capture_inner_cudagraphs(
input_buffers,
self.block_tables,
self.attn_groups,
self.kv_cache_config,
)
if self.speculator is not None:
with use_workspace_lane(self._draft_workspace_lane):
self.speculator.capture()
if self.adaptive_verification is not None:
with self.step_timing.collect() as timings:
for batch in self.adaptive_verification.batches_to_profile(
self.cudagraph_manager.captured_token_counts()
):
self._dummy_run(**batch)
self.adaptive_verification.set_initial_cost_curves(timings)
self.kv_connector.reset_capture_state()
if capture_decoder:
input_buffers = self.input_buffers
if self.pcp_manager is not None:
input_buffers = self.pcp_manager.input_buffers
self.cudagraph_manager.capture(
self.model,
self.model_state,
input_buffers,
self.intermediate_tensors,
self.block_tables,
self.attn_groups,
self.kv_cache_config,
pcp_manager=self.pcp_manager,
use_aux_hidden_state_outputs=self.use_aux_hidden_state_outputs,
)
self.model_state.capture_inner_cudagraphs(
input_buffers,
self.block_tables,
self.attn_groups,
self.kv_cache_config,
)
if self.speculator is not None:
with use_workspace_lane(self._draft_workspace_lane):
self.speculator.capture()
if self.adaptive_verification is not None:
with self.step_timing.collect() as timings:
for batch in self.adaptive_verification.batches_to_profile(
self.cudagraph_manager.captured_token_counts()
):
self._dummy_run(**batch)
self.adaptive_verification.set_initial_cost_curves(timings)
self.kv_connector.reset_capture_state()
end_free_gpu_memory = torch.accelerator.get_memory_info()[0]
@@ -1159,7 +1123,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.encoder_cache.remove_request(req_id)
if self.prompt_logprobs_worker is not None:
self.prompt_logprobs_worker.remove_request(req_id)
self.lora_state.remove_request(req_id)
return True
def finish_requests(self, scheduler_output: SchedulerOutput) -> None:
@@ -1230,7 +1193,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.block_tables.append_block_ids(
req_index, new_req_data.block_ids, overwrite=True
)
self.lora_state.add_request(req_id, req_index, new_req_data.lora_request)
if self.is_last_pp_rank and new_req_data.sampling_params is not None:
assert self.sampler is not None
@@ -1369,7 +1331,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
scheduler_output: SchedulerOutput,
batch_req_state: "BatchReqState",
batch_desc: BatchExecutionDescriptor,
num_active_loras: int,
) -> InputBatch:
num_tokens = batch_req_state.num_tokens
num_tokens_after_padding = max(num_tokens, batch_desc.num_tokens)
@@ -1503,7 +1464,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
cu_num_logits_np,
batch_req_state.has_prefill,
batch_desc,
num_active_loras=num_active_loras,
)
# CPU upper bound on seq_lens; padded entries left at zero.
@@ -1779,13 +1739,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
batch_req_state.is_prefilling_np,
)
num_active_loras = 0
if self.lora_config:
req_ids = list(scheduler_output.num_scheduled_tokens.keys())
num_active_loras = get_num_active_loras_for_dispatch(
self.lora_config, self.lora_state, req_ids, dummy_run
)
skip_compiled = False
if self.is_encoder_decoder and scheduler_output.scheduled_encoder_inputs:
# Encoder-decoder models such as Whisper should run eager/non-compiled
@@ -1802,7 +1755,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.dp_rank,
max_query_len=max_query_len,
need_eager=is_profile or skip_compiled,
num_active_loras=num_active_loras,
parallel_config=self.parallel_config,
allow_ubatching=(
self.ubatch_runner is not None and not skip_attn_for_dummy_run
@@ -1823,7 +1775,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
cudagraph_stats = make_cudagraph_stats(batch_desc, num_toks)
assert batch_req_state is not None
input_batch = self.prepare_inputs(
scheduler_output, batch_req_state, batch_desc, num_active_loras
scheduler_output, batch_req_state, batch_desc
)
block_tables, slot_mappings = self.prepare_attn(input_batch)
# Mamba "align" pre-copy: migrate recurrent state across block
@@ -1836,15 +1788,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
self.kv_cache_config,
self.req_states.num_computed_tokens.gpu,
)
if self.lora_config:
# Activate LoRA adapters.
lora_inputs = self.lora_state.make_lora_inputs(
input_batch.req_ids,
input_batch.idx_mapping_np,
input_batch.num_scheduled_tokens,
)
self._set_active_loras(*lora_inputs)
else:
# No actual tokens to run. A dummy run for DP or memory profiling.
dummy_num_reqs = batch_desc.num_reqs or num_reqs
@@ -1953,15 +1896,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
)
else:
scheduled_encoder_inputs = scheduler_output.scheduled_encoder_inputs
if self.supports_mm_inputs and self.lora_config is not None:
set_active_mm_loras(
model=self.model,
lora_manager=self.lora_manager,
encoder_cache=self.encoder_cache,
req_id_to_index=self.req_states.req_id_to_index,
lora_state=self.lora_state,
scheduled_encoder_inputs=scheduled_encoder_inputs,
)
with self.ec_connector.maybe_get_output(
scheduler_output
) as ec_connector_output:
@@ -2024,8 +1958,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
# For piecewise and eager mode, just call model().
batch_descriptor = BatchDescriptor(
num_tokens=input_batch.num_tokens_after_padding,
has_lora=self.lora_config is not None,
num_active_loras=batch_desc.num_active_loras,
)
with set_forward_context(
@@ -101,21 +101,11 @@ class ModelState(ABC):
return self.model_config.max_model_len
def get_supported_generation_tasks(self) -> tuple[GenerationTask, ...]:
from vllm.model_executor.models.interfaces import (
supports_realtime,
supports_transcription,
)
from vllm.model_executor.models.interfaces_base import is_text_generation_model
supported_tasks = list[GenerationTask]()
if is_text_generation_model(self.model):
supported_tasks.append("generate")
if supports_transcription(self.model):
if self.model.supports_transcription_only:
return ("transcription",)
supported_tasks.append("transcription")
if supports_realtime(self.model):
supported_tasks.append("realtime")
return tuple(supported_tasks)
def add_request(self, req_index: int, new_req_data: NewRequestData) -> None:
-2
View File
@@ -157,8 +157,6 @@ class PCPManager:
)
if supports_mm_inputs:
raise NotImplementedError("MRV2 PCP does not support MM inputs yet.")
if vllm_config.lora_config is not None:
raise NotImplementedError("MRV2 PCP does not support LoRA yet.")
speculative_config = vllm_config.speculative_config
if speculative_config is not None:
if speculative_config.use_dspark():
@@ -5,7 +5,6 @@ import torch.nn as nn
from vllm.config import VllmConfig, replace
from vllm.distributed.parallel_state import get_pp_group
from vllm.lora.layers.base import BaseLayerWithLoRA
from vllm.model_executor.layers.quantization.online.lm_head import (
quantized_lm_head_copy,
)
@@ -51,9 +50,6 @@ def maybe_share_target_embed(
)
if isinstance(target_embed, PPMissingLayer):
target_embed = None
# The drafter does not use the target's LoRA adapter.
if isinstance(target_embed, BaseLayerWithLoRA):
target_embed = target_embed.base_layer
draft_embed = getattr(draft_inner, "embed_tokens", None)
if get_pp_group().world_size > 1 and not hasattr(
-2
View File
@@ -157,7 +157,6 @@ def run_mixed_prefill_decode_warmup(
pooling_params=None,
block_ids=tuple(_alloc_blocks(n) for n in decode_prefill_block_counts),
num_computed_tokens=0,
lora_request=None,
prefill_token_ids=decode_token_ids,
),
]
@@ -187,7 +186,6 @@ def run_mixed_prefill_decode_warmup(
pooling_params=None,
block_ids=tuple(_alloc_blocks(n) for n in prefill_block_counts),
num_computed_tokens=0,
lora_request=None,
prefill_token_ids=prefill_token_ids,
),
]