Skip to content

Commit 042a26b

Browse files
committed
fix
1 parent bda9b67 commit 042a26b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightllm/server/embed_cache/impl/naive_memory_cache.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ def _del_ref(self, md5_sum):
134134
self._sorted_records.add(rec)
135135
return
136136

137+
def _judge_enough_token_cache(self, md5sum_list: list[str], token_num_list: list[int]) -> bool:
138+
tmp_dict = {}
139+
for md5, token_num in zip(md5sum_list, token_num_list):
140+
tmp_dict[md5] = token_num
141+
return sum(tmp_dict.values()) < self.cpu_embed_cache_client.token_num / 3
142+
137143
def alloc(self, md5sum_list: list[str], token_num_list: list[int]) -> Optional[list[dict]]:
138144
now = time.time()
139145
with self.lock:
146+
if not self._judge_enough_token_cache(md5sum_list=md5sum_list, token_num_list=token_num_list):
147+
return "error not enough cache"
148+
140149
add_ref_m_list = []
141150
new_md5_dict = {}
142151
for m, token_need in zip(md5sum_list, token_num_list):

0 commit comments

Comments
 (0)