@@ -82,7 +82,7 @@ def __init__(
8282
8383 self .enable_multimodal = enable_multimodal
8484 if self .enable_multimodal :
85- self .cache_client = rpyc .connect ("localhost" , cache_port , onfig = {"allow_pickle" : True })
85+ self .cache_client = rpyc .connect ("localhost" , cache_port , config = {"allow_pickle" : True })
8686 self .send_to_visual = context .socket (zmq .PUSH )
8787 self .send_to_visual .connect (f"{ args .zmq_mode } 127.0.0.1:{ visual_port } " )
8888
@@ -114,34 +114,6 @@ def __init__(
114114 self .latest_success_infer_time_mark .set_value (int (time .time ()))
115115 return
116116
117- # connect cache server, calculate md5, alloc resource, return uuid
118- async def _alloc_resource (self , item : Union [ImageItem , AudioItem ]):
119- if isinstance (item , ImageItem ):
120- data = item .read ()
121- # must after init_imageitem_extral_params
122- num_tokens = self .tokenizer .get_image_token_length (item )
123- elif isinstance (item , AudioItem ):
124- data = item .read ()
125- num_tokens = self .tokenizer .get_audio_token_length (item )
126- else :
127- raise ValueError (f"unexpected item type { type (item )} " )
128-
129- md5sum = hashlib .md5 (data ).hexdigest () + "_" + str (hash (frozendict (item .extra_params )))
130- wait_time = 1
131- while True :
132- record = self .cache_client .root .alloc (md5sum , num_tokens )
133- # hit or new
134- if record :
135- uid = record ["id" ]
136- if not self .cache_client .root .get_item_data (uid ):
137- create_shm (get_shm_name_data (uid ), data )
138- self .cache_client .root .set_item_data (uid )
139- return record
140- # cache full
141- else :
142- await asyncio .sleep (wait_time )
143- wait_time = min (wait_time + 2 , 9 )
144-
145117 async def _alloc_multimodal_resources (self , multimodal_params : MultimodalParams , sampling_params : SamplingParams ):
146118 # 只有 P 和 NORMAL 节点需要真的管理多模态资源
147119 if self .pd_mode .is_P_or_NORMAL ():
@@ -160,9 +132,6 @@ async def _alloc_multimodal_resources(self, multimodal_params: MultimodalParams,
160132 token_nums .append (num_tokens )
161133 datas .append (data )
162134 items .append (img )
163- # img.uuid = record["id"]
164- # img.token_id = record["token_id"]
165- # img.token_num = record["token_num"]
166135 for audio in multimodal_params .audios :
167136 self .tokenizer .init_audioitem_extral_params (audio , multimodal_params , sampling_params )
168137 data = audio .read ()
@@ -172,9 +141,6 @@ async def _alloc_multimodal_resources(self, multimodal_params: MultimodalParams,
172141 token_nums .append (num_tokens )
173142 datas .append (data )
174143 items .append (audio )
175- # audio.uuid = record["id"]
176- # audio.token_id = record["token_id"]
177- # audio.token_num = record["token_num"]
178144 wait_time = 1
179145 while True :
180146 records = self .cache_client .root .alloc_batch (md5s , token_nums )
@@ -194,7 +160,6 @@ async def _alloc_multimodal_resources(self, multimodal_params: MultimodalParams,
194160 item .token_num = record ["token_num" ]
195161 if not ready :
196162 create_shm (get_shm_name_data (item .uuid ), data )
197- self .cache_client .root .set_items_data (item .uuid )
198163 uids_to_write .append (item .uuid )
199164 if uids_to_write :
200165 self .cache_client .root .set_items_data (uids_to_write )
@@ -203,20 +168,23 @@ async def _release_multimodal_resources(self, multimodal_params: MultimodalParam
203168 # 只有 P 和 NORMAL 节点需要真的管理多模态资源
204169 if self .pd_mode .is_P_or_NORMAL ():
205170 if multimodal_params is not None :
171+ ids_to_release = []
206172 for img in multimodal_params .images :
207173 if img .uuid is not None :
208- self . cache_client . root . release (img .uuid )
174+ ids_to_release . append (img .uuid )
209175 # 将 uuid 等 赋值为 None, 防止因为abort等异常情况造成重复释放异常
210176 img .uuid = None
211177 img .token_id = None
212178 img .token_num = None
213179 for audio in multimodal_params .audios :
214180 if audio .uuid is not None :
215- self . cache_client . root . release (audio .uuid )
181+ ids_to_release . append (audio .uuid )
216182 # 将 uuid 等 赋值为 None, 防止因为abort等异常情况造成重复释放异常
217183 audio .uuid = None
218184 audio .token_id = None
219185 audio .token_num = None
186+ if ids_to_release :
187+ self .cache_client .root .release (ids_to_release )
220188 return
221189
222190 def tokens (self , prompt , multimodal_params , samping_params : SamplingParams , kwargs = None ):
0 commit comments