Skip to content

Commit cffa0a0

Browse files
committed
0909
1 parent c1d98eb commit cffa0a0

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

lightllm/models/vit/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def encode(self, images: List[ImageItem]):
178178
for i, img in enumerate(images):
179179
if isinstance(img, ImageItem):
180180
uuids.append(img.uuid)
181-
image_data = img._preload_data
181+
image_data = read_shm(get_shm_name_data(img.uuid))
182182
image_data = Image.open(BytesIO(image_data))
183183
t = self.load_image_func(image_data, max_num=img.extra_params["image_patch_max_num"])
184184
img_tensors.append(t)

lightllm/server/embed_cache/impl/memory_cache_with_redis.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ def set_items_embed(self, ids: list[int]) -> None:
4747
self._records[id].ref -= 1
4848

4949
def get_items_embed(self, ids: list[int]) -> list[Optional[bool]]:
50+
ret = []
51+
for id in ids:
52+
print(f"id is {id}")
53+
print(f"self.redis_cache.query(str(id)) is {self.redis_cache.query(str(id))}")
54+
exist = self.redis_cache.query(str(id))
55+
ret.append(exist)
56+
if exist:
57+
self._records[id].embed = True
58+
return ret
59+
60+
def get_items_embed_and_incre(self, ids: list[int]) -> list[Optional[bool]]:
5061
ret = []
5162
for id in ids:
5263
# if self.redis_cache.query(str(id)):

lightllm/server/embed_cache/utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,19 @@ def _delete_afs_files(self, victims: List[str]) -> None:
326326
return {-1, 0} -- Not found
327327
end
328328
329+
--ref 递减到 0 时保留键,只更新计数与 LRU
329330
local rc = tonumber(val) - 1
330-
if rc <= 0 then
331-
redis.call('DEL', ref_key)
332-
redis.call('ZREM', zset, md5)
333-
return {0, 1} -- Deleted
334-
else
335-
redis.call('SET', ref_key, rc)
336-
local now = redis.call('TIME')[1] * 1000
337-
redis.call('ZADD', zset, now, md5)
338-
return {rc, 0} -- Updated
331+
if rc < 0 then
332+
rc = 0
339333
end
334+
335+
redis.call('SET', ref_key, rc)
336+
337+
-- 更新 LRU 时间戳(最近释放的条目更不容易被立即逐出)
338+
local now = redis.call('TIME')[1] * 1000
339+
redis.call('ZADD', zset, now, md5)
340+
341+
return {rc, 0} -- 未删除
340342
"""
341343

342344
_EVICT_AND_INSERT_LUA = r"""

lightllm/server/httpserver/manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ async def recycle_resource_loop(self):
687687
for req in req_status.group_req_objs.shm_req_objs:
688688
await self.shm_req_manager.async_put_back_req_obj(req)
689689
await self.shm_req_manager.async_release_req_index(req.index_in_shm_mem)
690-
print("begin release")
691690
await self._release_multimodal_resources(req_status.group_req_objs.multimodal_params)
692691

693692
# 先保留这个关键得日志,用于方便定位重构中的问题。

lightllm/server/visualserver/manager.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ def _recv_reqs(self):
160160
# img for img in recv_req.multimodal_params.images
161161
# if not self.cache_client.root.get_item_embed(img.uuid) # embed已存在的被丢弃 , ref +1
162162
# ]
163-
uuids = []
163+
uuids = [img.uuid for img in recv_req.multimodal_params.images]
164+
already_embed = self.cache_client.root.get_items_embed(uuids)
164165
token_nums = []
165-
for img in recv_req.multimodal_params.images:
166-
uuids.append(img.uuid)
167-
token_nums.append(img.token_num)
168-
record = self.cache_client.root.alloc(uuids, token_nums)
169-
print(f"record is {record}")
166+
for img, embed in zip(recv_req.multimodal_params.images, already_embed):
167+
if not embed:
168+
uuids.append(img.uuid)
169+
token_nums.append(img.token_num)
170+
self.cache_client.root.alloc(uuids, token_nums)
170171
return recv_req
171172
else:
172173
return self.vit_receiver.recv_pyobj(zmq.NOBLOCK)
@@ -182,6 +183,7 @@ async def loop_for_netio_req(self):
182183
if isinstance(recv_req, GroupReqIndexes):
183184
# print(recv_req, flush=True)
184185
self.waiting_reqs.append(recv_req)
186+
print(f"recv_req.multimodal_params is {recv_req.multimodal_params}")
185187
else:
186188
assert False, f"Error Req Inf {recv_req}"
187189
self.visual_recv_max_count = min(self.visual_recv_max_count * 1.3, 256)

lightllm/server/visualserver/vit_connect.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import pickle
66
from typing import Dict, List, Optional, Any
77
from lightllm.utils.log_utils import init_logger
8+
from lightllm.server.core.objs.io_objs import GroupReqObjs, GroupReqIndexes
9+
from lightllm.server.multimodal_params import MultimodalParams
810
import httpx
911
import base64
1012
from dataclasses import dataclass
@@ -48,8 +50,10 @@ def _setup_vit_connections(self):
4850
"""
4951
if self.remote_vit:
5052
# 远程VIT实例模式
53+
print("remote")
5154
self._setup_remote_vit_connections()
5255
else:
56+
print("not remote")
5357
self._setup_local_vit_connection()
5458

5559
def _setup_local_vit_connection(self):
@@ -156,31 +160,33 @@ def _get_vit_instance(self):
156160
self.current_vit_index = index
157161
return list(self.remote_vit_instances.values())[index]
158162

159-
async def send_to_vit(self, data, protocol=pickle.HIGHEST_PROTOCOL):
163+
async def send_to_vit(self, req: GroupReqIndexes, protocol=pickle.HIGHEST_PROTOCOL):
160164
"""
161165
发送数据到VIT实例,支持本地和远程模式
162166
"""
163167
instance = self._get_vit_instance()
164168
# 本地模式下,提前释放图片资源,降低传输开销
165169
if not self.remote_vit:
166-
data.multimodal_params.free()
170+
req.multimodal_params.free()
167171

168172
try:
169173
print(instance, flush=True)
170-
instance.send_pyobj(data, protocol=protocol)
174+
instance.send_pyobj(req, protocol=protocol)
171175
except Exception as e:
172176
logger.error(f"Failed to send to VIT instance: {e}")
173177
raise Exception(f"Failed to send to VIT instance: {e}")
174178

175179
# 远程模式下,发送完以后,在释放图片资源
176-
await self._wait_visual_embed_ready(data)
180+
await self._wait_visual_embed_ready(req)
177181
if self.remote_vit:
178-
data.multimodal_params.free()
182+
req.multimodal_params.free()
179183

180184
async def vit_handle_loop(self):
181185
"""
182186
异步VIT连接管理循环,由外部启动
183187
"""
188+
if not self.remote_vit:
189+
return
184190
logger.info("Starting VIT connection management loop")
185191
while True:
186192
try:
@@ -211,12 +217,12 @@ async def _async_get_vit_objs(self) -> Optional[Dict[int, VIT_Obj]]:
211217
logger.exception(f"Error getting VIT instances: {e}")
212218
return None
213219

214-
async def _wait_visual_embed_ready(self, data, timeout_seconds: int = 100):
220+
async def _wait_visual_embed_ready(self, req: GroupReqIndexes, timeout_seconds: int = 100):
215221
# 本地模式不需要等待
216222
if not self.remote_vit:
217223
return
218224

219-
uuids = data.multimodal_params.get_all_uuids()
225+
uuids = req.multimodal_params.get_all_uuids()
220226
print(f"uuids is {uuids}")
221227

222228
async def wait_for_embeds():
@@ -227,5 +233,5 @@ async def wait_for_embeds():
227233
await asyncio.wait_for(wait_for_embeds(), timeout=timeout_seconds)
228234
except asyncio.TimeoutError:
229235
logger.error(
230-
f"Req {data.group_req_id}: timeout waiting for visual embed ready after {timeout_seconds} seconds"
236+
f"Req {req.group_req_id}: timeout waiting for visual embed ready after {timeout_seconds} seconds"
231237
)

0 commit comments

Comments
 (0)