[Core] Add prefill step cadence for better non-PD DP balancing (#44558)

Signed-off-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
Nick Hill
2026-06-16 13:17:18 -07:00
committed by GitHub
parent 475a6ad18a
commit d8d95998dc
7 changed files with 306 additions and 4 deletions
+7 -1
View File
@@ -49,7 +49,7 @@ class SchedulerInterface(ABC):
raise NotImplementedError
@abstractmethod
def schedule(self) -> "SchedulerOutput":
def schedule(self, throttle_prefills: bool = False) -> "SchedulerOutput":
"""Schedule the requests to process in this scheduling step.
The scheduling decision is made at the iteration level. Each scheduling
@@ -68,6 +68,12 @@ class SchedulerInterface(ABC):
or the batch as a whole. The model runner will use this information in
preparing inputs to the model.
Args:
throttle_prefills: DP prefill balancing. When True (set by the DP
engine core on non-cadence-aligned steps), new prefill compute is
deferred to a later step so prefills stay aligned across DP ranks;
automatically overridden when the rank is saturated.
Returns:
A SchedulerOutput object containing information about the scheduled
requests.
+27 -1
View File
@@ -275,6 +275,10 @@ class Scheduler(SchedulerInterface):
# Scheduler iteration counter. Drives the V2+PP+async decode-throttle
# cadence (`next_decode_eligible_step`).
self.current_step = 0
# DP prefill balancing: Flag to track whether the last cadence-aligned
# prefill batch fully drained the waiting queue. Prefill throttling
# is disabled in this case.
self.prefill_capacity_bound = False
self.scheduler_reserve_full_isl = (
self.scheduler_config.scheduler_reserve_full_isl
)
@@ -380,7 +384,7 @@ class Scheduler(SchedulerInterface):
num_new_tokens = num_new_tokens // block_size * block_size
return num_new_tokens
def schedule(self) -> SchedulerOutput:
def schedule(self, throttle_prefills: bool = False) -> SchedulerOutput:
self.current_step += 1
# NOTE(woosuk) on the scheduling algorithm:
# There's no "decoding phase" nor "prefill phase" in the scheduler.
@@ -416,6 +420,12 @@ class Scheduler(SchedulerInterface):
self.kv_cache_manager.new_step_starts()
# DP prefill balancing: on a throttled (non-cadence-aligned) step, defer
# all prefill compute unless saturated.
defer_prefills = (
throttle_prefills and not self.prefill_capacity_bound
) and any(not r.is_prefill_chunk for r in self.running)
# First, schedule the RUNNING requests.
req_index = 0
while req_index < len(self.running) and token_budget > 0:
@@ -443,6 +453,12 @@ class Scheduler(SchedulerInterface):
req_index += 1
continue
if defer_prefills and request.is_prefill_chunk:
# DP prefill balancing: defer this in-progress prefill chunk to a
# cadence-aligned step; decodes still run to fill this step.
req_index += 1
continue
num_new_tokens = (
request.num_tokens_with_spec
+ request.num_output_placeholders
@@ -766,6 +782,11 @@ class Scheduler(SchedulerInterface):
# KVTransfer: loading remote KV, do not allocate for new work.
assert num_external_computed_tokens > 0
num_new_tokens = 0
elif defer_prefills and request.num_computed_tokens == 0:
# DP prefill balancing: async KV loads (the branch above) are
# allowed to start even on throttled steps, but committing new
# prefill compute is deferred to a cadence-aligned step.
break
else:
# Number of tokens to be scheduled.
# We use `request.num_tokens` instead of
@@ -959,6 +980,11 @@ class Scheduler(SchedulerInterface):
if step_skipped_waiting:
self.skipped_waiting.prepend_requests(step_skipped_waiting)
# DP prefill balancing: on a step that admitted prefills (release),
# record whether it was capacity-bound.
if not defer_prefills:
self.prefill_capacity_bound = bool(self.waiting)
# Check if the scheduling constraints are satisfied.
total_num_scheduled_tokens = sum(num_scheduled_tokens.values())
assert total_num_scheduled_tokens <= self.max_num_scheduled_tokens