[Bugfix] Fix level-2 sleep/wake/reload with enable_lora=True (#39935)
Signed-off-by: Silen Naihin <silen.naihin@gmail.com> Co-authored-by: Dakai An <dakaian108@gmail.com> Co-authored-by: Jiangyun Zhu <riverclouds.zhu@qq.com>
This commit is contained in:
co-authored by
Dakai An
Jiangyun Zhu
parent
8cfa01cdd2
commit
b50fdebce0
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from collections.abc import Iterable
|
||||
from typing import TYPE_CHECKING, overload
|
||||
|
||||
import torch
|
||||
@@ -14,6 +15,18 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class BaseLayerWithLoRA(nn.Module):
|
||||
def load_weights(
|
||||
self, weights: Iterable[tuple[str, torch.Tensor]]
|
||||
) -> Iterable[str]:
|
||||
"""Load checkpoint weights into the wrapped base layer."""
|
||||
base_load_weights = getattr(self.base_layer, "load_weights", None)
|
||||
if callable(base_load_weights):
|
||||
return base_load_weights(weights)
|
||||
|
||||
from vllm.model_executor.models.utils import AutoWeightsLoader
|
||||
|
||||
return AutoWeightsLoader(self.base_layer).load_weights(weights)
|
||||
|
||||
@overload
|
||||
def slice_lora_a(
|
||||
self, lora_a: list[torch.Tensor | None]
|
||||
|
||||
@@ -118,6 +118,18 @@ class LogitsProcessorWithLoRA(BaseLayerWithLoRA):
|
||||
else:
|
||||
self.sharded_to_full_mapping_gpu = None
|
||||
|
||||
def reset_sharded_to_full_mapping(self) -> None:
|
||||
"""Restore the TP logits mapping after its GPU memory is reused."""
|
||||
mapping_gpu = self.sharded_to_full_mapping_gpu
|
||||
if mapping_gpu is not None:
|
||||
mapping_gpu.copy_(
|
||||
torch.tensor(
|
||||
self.sharded_to_full_mapping,
|
||||
device=mapping_gpu.device,
|
||||
dtype=mapping_gpu.dtype,
|
||||
)
|
||||
)
|
||||
|
||||
def reset_lora(self, index: int):
|
||||
self.lora_a_stacked[index] = 0
|
||||
self.lora_b_stacked[index] = 0
|
||||
|
||||
@@ -387,6 +387,8 @@ class LoRAModelManager:
|
||||
self._registered_adapters.clear()
|
||||
self.lora_index_to_id = [None] * self.lora_slots
|
||||
self._active_adapters.clear()
|
||||
self._last_mapping = None
|
||||
self._last_slot_layout = None
|
||||
|
||||
def _create_lora_modules(self):
|
||||
def _parent_module(module_name: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user