Skip to content

Commit eef9d35

Browse files
committed
improve postprocess
1 parent bba8286 commit eef9d35

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lightllm/server/router/model_infer/infer_batch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ def init_all(self):
271271
else:
272272
self.out_token_id_count = collections.defaultdict(int)
273273

274+
shm_param = self.sampling_param.shm_param
275+
# 提前标记当前请求是否需要统计输出token的计数,因为这个统计可能会导致一些特定场景下后处理效率的下降
276+
# 所以提前标记不需要进行后处理统计的场景。
277+
self.need_out_token_id_statistics = not (
278+
shm_param.presence_penalty == 0.0
279+
and shm_param.frequency_penalty == 0.0
280+
and shm_param.repetition_penalty == 1.0
281+
)
282+
274283
self.stop_sequences = self.sampling_param.shm_param.stop_sequences.to_list()
275284
# token healing mode 才被使用的管理对象
276285
if self.shm_req.prefix_token_ids.size != 0:

lightllm/server/router/model_infer/mode_backend/base_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ def _post_handle(
282282
req_obj.set_next_gen_token_id(next_token_id, next_token_logprob)
283283
req_obj.cur_output_len += 1
284284

285-
if req_obj.out_token_id_count is not None:
285+
if req_obj.need_out_token_id_statistics:
286286
req_obj.out_token_id_count[next_token_id] += 1
287+
287288
req_obj.update_finish_status(self.eos_id)
288289

289290
if extra_post_req_handle_func is not None:

lightllm/server/router/model_infer/mode_backend/continues_batch/impl_for_return_all_prompt_logprobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def prefill(self, run_reqs: List[Tuple]):
5555
for i in range(req_obj.shm_req.input_len - 1):
5656
req_obj.shm_req.shm_logprobs.arr[i + 1] = cur_logprobs[i]
5757

58-
if req_obj.out_token_id_count is not None:
58+
if req_obj.need_out_token_id_statistics:
5959
req_obj.out_token_id_count[next_token_id] += 1
6060
req_obj.update_finish_status(self.eos_id)
6161

lightllm/server/router/model_infer/mode_backend/continues_batch/impl_for_reward_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def prefill(self, reqs: List[Tuple]):
3232
req_obj.set_next_gen_token_id(next_token_id, next_token_logprob)
3333
req_obj.cur_output_len += 1
3434

35-
if req_obj.out_token_id_count is not None:
35+
if req_obj.need_out_token_id_statistics:
3636
req_obj.out_token_id_count[next_token_id] += 1
3737
req_obj.update_finish_status(self.eos_id)
3838

0 commit comments

Comments
 (0)