MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / _mainloop

Method _mainloop

tensorrt_llm/executor/postproc_worker.py:175–216  ·  view source on GitHub ↗

The loop for handle_response and keep producing outputs.

(self)

Source from the content-addressed store, hash-verified

173 await self._push_pipe.put_async(batch)
174
175 async def _mainloop(self):
176 ''' The loop for handle_response and keep producing outputs. '''
177
178 async def handle_single_input(inp: PostprocWorker.Input,
179 batch: List[PostprocWorker.Output]):
180 assert isinstance(
181 inp, PostprocWorker.Input
182 ), f"Expect PostprocWorker.Input, got {type(inp)}."
183 client_id = inp.rsp.client_id
184 is_final = inp.rsp.result.is_final if is_llm_response(
185 inp.rsp) else True
186 res, metrics, perf_metrics, disaggregated_params = await self._handle_input(
187 inp)
188 batch.append(
189 PostprocWorker.Output(
190 client_id=client_id,
191 res=res,
192 is_final=is_final,
193 metrics=metrics,
194 request_perf_metrics=perf_metrics,
195 disaggregated_params=disaggregated_params,
196 ))
197 if is_final:
198 self._records.pop(client_id)
199
200 while not self._to_stop.is_set():
201 batch = []
202 inputs: Optional[List[PostprocWorker.Input]
203 | PostprocWorker.
204 Input] = await self._pull_pipe.get_async()
205
206 if not isinstance(inputs, list):
207 inputs = [inputs]
208
209 for inp in inputs:
210 if inp is None:
211 self._to_stop.set()
212 yield None
213 break
214 await handle_single_input(inp, batch)
215
216 yield batch
217
218 def start(self):
219 ''' Start the workflow in the current thread. '''

Callers 1

_batched_putMethod · 0.95

Calls 2

get_asyncMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected