Spaces:
Runtime error
Runtime error
zetavg
commited on
Commit
•
fe7c9d2
1
Parent(s):
966795b
move to latest working version of peft
Browse files
llama_lora/utils/lru_cache.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import OrderedDict
|
2 |
+
|
3 |
+
|
4 |
+
class LRUCache:
|
5 |
+
def __init__(self, capacity=5):
|
6 |
+
self.cache = OrderedDict()
|
7 |
+
self.capacity = capacity
|
8 |
+
|
9 |
+
def get(self, key):
|
10 |
+
if key in self.cache:
|
11 |
+
# Move the accessed item to the end of the OrderedDict
|
12 |
+
self.cache.move_to_end(key)
|
13 |
+
return self.cache[key]
|
14 |
+
return None
|
15 |
+
|
16 |
+
def set(self, key, value):
|
17 |
+
if key in self.cache:
|
18 |
+
# If the key already exists, update its value
|
19 |
+
self.cache[key] = value
|
20 |
+
else:
|
21 |
+
# If the cache has reached its capacity, remove the least recently used item
|
22 |
+
if len(self.cache) >= self.capacity:
|
23 |
+
self.cache.popitem(last=False)
|
24 |
+
self.cache[key] = value
|
25 |
+
|
26 |
+
def clear(self):
|
27 |
+
self.cache.clear()
|