[BugFix][LoRA] Refresh punica metadata when LoRA slots are reassigned under an unchanged mapping (#47725)

Signed-off-by: AmeenP <ameenp360@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Ameen Patel
2026-07-07 08:53:55 -07:00
committed by GitHub
co-authored by Claude mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 21b396abe1
commit 392d1b4d2e
2 changed files with 56 additions and 1 deletions
+7 -1
View File
@@ -117,6 +117,7 @@ class LoRAModelManager:
self.packed_modules: dict[str, list[str]] = {}
self.modules: dict[str, BaseLayerWithLoRA] = {}
self._last_mapping: LoRAMapping | None = None
self._last_slot_layout: tuple[int | None, ...] | None = None
is_moe = is_moe_model(self.model)
self._is_moe = is_moe
@@ -1147,9 +1148,14 @@ class LoRAModelManager:
return True
def set_adapter_mapping(self, mapping: LoRAMapping) -> None:
if self._last_mapping != mapping:
# The punica metadata derives from the slot layout as well as the
# mapping: an out-of-band add_lora() can LRU-evict and reassign slots
# while the running batch, and thus the mapping, is unchanged.
slot_layout = tuple(self.lora_index_to_id)
if self._last_mapping != mapping or self._last_slot_layout != slot_layout:
self._set_adapter_mapping(mapping)
self._last_mapping = mapping
self._last_slot_layout = slot_layout
def remove_adapter(self, adapter_id: int) -> bool:
self.deactivate_adapter(adapter_id)