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

Function _send_rsp

tensorrt_llm/executor/base_worker.py:902–946  ·  view source on GitHub ↗
(
        worker,
        response: Union[tllm.Response, ResponseWrapper, ErrorResponse],
        postproc_batches: Optional[List[List["PostprocWorker.Input"]]] = None,
        rsp_batch: Optional[List[tllm.Response]] = None)

Source from the content-addressed store, hash-verified

900
901
902def _send_rsp(
903 worker,
904 response: Union[tllm.Response, ResponseWrapper, ErrorResponse],
905 postproc_batches: Optional[List[List["PostprocWorker.Input"]]] = None,
906 rsp_batch: Optional[List[tllm.Response]] = None):
907 # if postproc_batches is set, append to batch instead of putting to IpcQueue
908
909 if worker.result_queue is not None:
910 if rsp_batch is not None:
911 rsp_batch.append(response)
912 else:
913 worker.result_queue.put(response)
914 else:
915 sampling_params, postproc_params = _get_params_for_first_rsp(
916 worker, response.client_id)
917 inp = PostprocWorker.Input(
918 response,
919 # sampling_params is necessary for creating fake GenerationResult
920 # instances in the postproc processes. They are for incremental
921 # detokenize. They should be transmitted only once for each
922 # Request.
923 sampling_params=sampling_params,
924 postproc_params=postproc_params,
925 streaming=worker._results.get(response.client_id, None)._streaming)
926
927 pid = response.client_id % worker.postproc_config.num_postprocess_workers
928
929 if not postproc_batches:
930 # Group the responses into buckets for the postprocessing steps.
931 # Bucketing is used instead of random dispatching because the
932 # incremental detokenization during postprocessing relies on the
933 # prior CompletionOutput of a given request.
934 worker.postproc_queues[pid].put(inp)
935 else:
936 postproc_batches[pid].append(inp)
937
938 # Eliminate the finished GenerationRequest instances timely, which may
939 # take considerable memory.
940 if is_llm_response(response):
941 if response.has_error() or response.result.is_final:
942 worker._pop_result(response.client_id)
943 elif isinstance(response, ErrorResponse):
944 worker._pop_result(response.client_id)
945 else:
946 raise ValueError(f"Unknown response type: {response}")
947
948
949def _get_metrics_dict(

Callers 1

Calls 7

is_llm_responseFunction · 0.85
appendMethod · 0.45
putMethod · 0.45
getMethod · 0.45
has_errorMethod · 0.45
_pop_resultMethod · 0.45

Tested by

no test coverage detected