[Bugfix] Handle empty FlatLogprobs slices and delta output (#53704)

Signed-off-by: tony <864832769@qq.com>
This commit is contained in:
Tony
2026-08-26 21:00:54 +08:00
committed by GitHub
parent 6a5e8f5979
commit 903a02192f
4 changed files with 53 additions and 7 deletions
+9 -4
View File
@@ -119,13 +119,18 @@ class FlatLogprobs(MutableSequence[LogprobsOnePosition | None]):
for i in range(self.start_indices[index], self.end_indices[index])
}
elif isinstance(index, slice):
min_index = self.start_indices[index][0]
max_index = self.end_indices[index][-1]
selected_starts = self.start_indices[index]
selected_ends = self.end_indices[index]
# Empty slices have no source offset to normalize.
if not selected_starts:
return FlatLogprobs()
min_index = selected_starts[0]
max_index = selected_ends[-1]
return FlatLogprobs(
# Shift updated start_indices and end_indices to
# be 0-indexed
start_indices=[i - min_index for i in self.start_indices[index]],
end_indices=[i - min_index for i in self.end_indices[index]],
start_indices=[i - min_index for i in selected_starts],
end_indices=[i - min_index for i in selected_ends],
token_ids=self.token_ids[min_index:max_index],
logprobs=self.logprobs[min_index:max_index],
ranks=self.ranks[min_index:max_index],
+5 -1
View File
@@ -411,7 +411,11 @@ class RequestState:
# Prepare logprobs, based on delta mode
logprobs = self.logprobs_processor.logprobs
if delta and logprobs:
logprobs = logprobs[-len(token_ids) :]
num_new_tokens = len(token_ids)
# Avoid [-0:], which returns the full accumulated history when a
# delta contains no new token IDs. [:0] preserves the concrete
# list or FlatLogprobs representation while returning no entries.
logprobs = logprobs[-num_new_tokens:] if num_new_tokens else logprobs[:0]
sampling_mask = None
if finished and self.sampling_mask_chunks: