[scheduler] fix: correcting extend_logprob_start_len calculation (#15922)

This commit is contained in:
Cheng Wan
2025-12-28 14:57:04 -08:00
committed by GitHub
parent d7a3336ebe
commit 6f9d0a89a0
8 changed files with 84 additions and 53 deletions
+11 -12
View File
@@ -1524,24 +1524,23 @@ class Scheduler(
self._add_request_to_queue(req)
return
# Copy more attributes
if recv_req.logprob_start_len == -1 or not recv_req.return_logprob:
# By default, only return the logprobs for output tokens
# For prefill-only requests with logprob_start_len == -1, set logprob_start_len beyond input sequence
# to skip input logprob computation entirely
if recv_req.logprob_start_len == -1:
if req.is_prefill_only:
# For prefill-only requests with logprob_start_len == -1, set logprob_start_len
# beyond input sequence to skip input logprob computation entirely
req.logprob_start_len = len(req.origin_input_ids)
else:
# TODO: For text generation, evaluate setting logprob_start_len to len(req.origin_input_ids) as well
elif recv_req.return_logprob:
# If return_logprob is True, return the logprobs for output tokens by default
req.logprob_start_len = len(req.origin_input_ids) - 1
else:
# If return_logprob is False, only the last token requires logprob computation
req.logprob_start_len = -1
else:
req.logprob_start_len = recv_req.logprob_start_len
if not req.is_prefill_only and req.logprob_start_len >= len(
req.origin_input_ids
):
if req.logprob_start_len > len(req.origin_input_ids):
error_msg = f"{req.logprob_start_len=} is higher than the number of input tokens {len(req.origin_input_ids)=}. Please use a smaller logprob_start_len."
req.logprob_start_len = len(req.origin_input_ids) - 1
req.logprob_start_len = -1
req.set_finish_with_abort(error_msg)
self._add_request_to_queue(req)
return
@@ -1760,7 +1759,7 @@ class Scheduler(
return
# Copy more attributes
req.logprob_start_len = len(req.origin_input_ids) - 1
req.logprob_start_len = -1
self._add_request_to_queue(req)
def handle_batch_embedding_request(