java-topology/defects/vllm/patch/vllm-0001-lora-convert-mapping-index.patch

29 lines
1.1 KiB
Diff

# UNDF: UNDF-2026-000000874
--- a/vllm/lora/punica_wrapper/utils.py
+++ b/vllm/lora/punica_wrapper/utils.py
@@ -86,15 +86,18 @@
embeddings_indices).
"""
index_mapping_indices: list[int] = list(mapping.index_mapping).copy()
embedding_indices = index_mapping_indices.copy()
lora_indices = index_mapping_indices.copy()
+ # Pre-build reverse lookup: lora_id -> position in lora_index_to_id
+ # Replaces O(L) list.index() with O(1) dict lookup per token
+ id_to_index: dict[int, int] = {
+ v: i for i, v in enumerate(lora_index_to_id) if v is not None and v > 0
+ }
+
prompt_mapping: list[int] = [
- lora_index_to_id.index(x) if x > 0 else -1 for x in mapping.prompt_mapping
+ id_to_index[x] if x > 0 else -1 for x in mapping.prompt_mapping
]
lora_idx = None
for i in range(len(index_mapping_indices)):
- # TODO index can be slow. optimize
lora_idx = (
- lora_index_to_id.index(index_mapping_indices[i])
+ id_to_index[index_mapping_indices[i]]
if index_mapping_indices[i] > 0
else -1
)