55import pickle
66from typing import Dict , List , Optional , Any
77from 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
810import httpx
911import base64
1012from 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