Fix token leak with logprob_start_len=0 in streaming sessions (#20557)
This commit is contained in:
@@ -181,8 +181,26 @@ class SessionAwareCache(BasePrefixCache):
|
||||
|
||||
slot.restore_to_req(req)
|
||||
|
||||
max_prefix_len = len(params.key.token_ids)
|
||||
# For streaming sessions, ignore the logprob_start_len truncation on
|
||||
# the key and reuse the full committed KV from the slot. The key may
|
||||
# have been truncated (e.g. to length 0 when logprob_start_len=0), but
|
||||
# the session slot already holds those KV tokens — skipping them would
|
||||
# orphan allocated memory. Use fill_ids length (the actual input for
|
||||
# this turn) as the upper bound instead of the truncated key.
|
||||
# Also clamp logprob_start_len so the scheduler doesn't expect logprobs
|
||||
# for tokens that are already in the session's committed KV.
|
||||
input_len = (
|
||||
len(req.fill_ids) if req.fill_ids is not None else len(params.key.token_ids)
|
||||
)
|
||||
max_prefix_len = max(input_len - 1, 0)
|
||||
prefix_len = min(req.kv_committed_len, max_prefix_len)
|
||||
|
||||
if (
|
||||
req.return_logprob
|
||||
and req.logprob_start_len >= 0
|
||||
and req.logprob_start_len < prefix_len
|
||||
):
|
||||
req.logprob_start_len = prefix_len
|
||||
device_indices = self.req_to_token_pool.req_to_token[
|
||||
req.req_pool_idx, :prefix_len
|
||||
].to(dtype=torch.int64)
|
||||
|
||||
Reference in New Issue
Block a user