[Scheduler] Enable decode retraction ordering under speculative decoding (#32023)

This commit is contained in:
Liangsheng Yin
2026-07-23 00:42:56 -07:00
committed by GitHub
parent a25164bda3
commit 9b853e6832
8 changed files with 71 additions and 57 deletions
+2 -14
View File
@@ -2624,13 +2624,7 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin):
self, server_args: ServerArgs
) -> Tuple[List[Req], float, List[Req]]:
"""Retract the decoding requests when there is not enough memory."""
sorted_indices = self._get_decode_retraction_order(
self.reqs,
server_args,
allow_policy_sort=(
self.spec_algorithm is None or self.spec_algorithm.is_none()
),
)
sorted_indices = self._get_decode_retraction_order(self.reqs, server_args)
retracted_reqs = []
first_iter = True
@@ -2678,7 +2672,7 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin):
@staticmethod
def _get_decode_retraction_order(
reqs: List[Req], server_args: ServerArgs, *, allow_policy_sort: bool
reqs: List[Req], server_args: ServerArgs
) -> List[int]:
"""Return indices ordered from most-preferred to least-preferred to keep.
@@ -2688,11 +2682,6 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin):
sorted_indices = list(range(len(reqs)))
# TODO(lsyin): improve retraction policy for radix cache
# For spec decoding, filter_batch API can only filter requests from the
# back, so we can only retract from the back.
# TODO(sang): Clean up finish path and support better retract policy.
if not allow_policy_sort:
return sorted_indices
def length_key(req: Req) -> Tuple[int, int]:
return (len(req.output_ids), -len(req.origin_input_ids))
@@ -2993,7 +2982,6 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin):
if self.spec_info:
self.spec_info.filter_batch(
new_indices=keep_indices_device,
has_been_filtered=False,
new_indices_cpu=keep_indices,
)