Skip to content

Commit

Permalink
Refactor convert_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjuCSudhakaran committed Dec 12, 2024
1 parent cd66840 commit ebcb891
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions vllm/lora/punica_wrapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import torch

from vllm.platforms import current_platform

if TYPE_CHECKING:
# avoid circuit import
from vllm.lora.layers import LoRAMapping
Expand Down Expand Up @@ -86,10 +88,14 @@ def convert_mapping(
embedding_indices = index_mapping_indices.copy()
lora_indices = index_mapping_indices.copy()
long_lora_offsets: Optional[torch.Tensor] = None

if long_lora_context:
long_lora_offsets = torch.zeros(len(index_mapping_indices),
device=device,
dtype=torch.long)
if current_platform.is_hpu():
long_lora_offsets_list: List[int] = []
else:
long_lora_offsets = torch.zeros(len(index_mapping_indices),
device=device,
dtype=torch.long)
prompt_mapping: List[int] = [
lora_index_to_id.index(x) if x > 0 else -1
for x in mapping.prompt_mapping
Expand All @@ -102,10 +108,18 @@ def convert_mapping(
embedding_indices[i] = lora_idx if index_mapping_indices[i] > 0 else 0
lora_indices[i] = lora_idx
if long_lora_context:
assert long_lora_offsets is not None
lora_offset: int = long_lora_context.offsets_by_lora_id.get(
index_mapping_indices[i], 0)
long_lora_offsets[i] = lora_offset
if current_platform.is_hpu():
long_lora_offsets_list.append(lora_offset)
else:
assert long_lora_offsets is not None
long_lora_offsets[i] = lora_offset

if long_lora_context and current_platform.is_hpu():
long_lora_offsets = torch.tensor(long_lora_offsets_list,
device=device,
dtype=torch.long)

indices_list: List[Union[List[int], torch.Tensor]] = [
index_mapping_indices,
Expand Down

0 comments on commit ebcb891

Please sign in to comment.