[Core] Add generic typing to LRUCache (#3511)

This commit is contained in:
Nick Hill
2024-03-20 00:36:09 -07:00
committed by GitHub
parent 9474e89ba4
commit 4ad521d8b5
4 changed files with 29 additions and 22 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import logging
import math
import os
import re
from typing import (Any, Callable, Dict, Hashable, List, Optional, Tuple, Type)
from typing import (Callable, Dict, Hashable, List, Optional, Tuple, Type)
import safetensors.torch
import torch
@@ -535,14 +535,14 @@ class LoRAModelManager:
replacement_loras)
class LoRALRUCache(LRUCache):
class LoRALRUCache(LRUCache[LoRAModel]):
def __init__(self, capacity: int, deactivate_lora_fn: Callable[[Hashable],
None]):
super().__init__(capacity)
self.deactivate_lora_fn = deactivate_lora_fn
def _on_remove(self, key: Hashable, value: Any):
def _on_remove(self, key: Hashable, value: LoRAModel):
logger.debug(f"Removing LoRA. int id: {key}")
self.deactivate_lora_fn(key)
return super()._on_remove(key, value)