[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
+5
View File
@@ -150,6 +150,11 @@ class SchedulerConfig:
of requests when GPU memory is scarce. Must be in the range [0.0, 1.0); 0.0
(the default) disables the watermark."""
prefill_schedule_interval: int = Field(default=1, ge=1)
"""For data-parallel deployments, only admit new prefill requests
once every N engine steps, aligned across DP ranks, to better balance
per-step forward-pass times."""
async_scheduling: bool | None = None
"""If set to False, disable async scheduling. Async scheduling helps to
avoid gaps in GPU utilization, leading to better latency and throughput.
+6
View File
@@ -599,6 +599,7 @@ class EngineArgs:
disable_chunked_mm_input: bool = SchedulerConfig.disable_chunked_mm_input
scheduler_reserve_full_isl: bool = SchedulerConfig.scheduler_reserve_full_isl
prefill_schedule_interval: int = SchedulerConfig.prefill_schedule_interval
watermark: float = SchedulerConfig.watermark
@@ -1417,6 +1418,10 @@ class EngineArgs:
**scheduler_kwargs["scheduler_reserve_full_isl"],
)
scheduler_group.add_argument("--watermark", **scheduler_kwargs["watermark"])
scheduler_group.add_argument(
"--prefill-schedule-interval",
**scheduler_kwargs["prefill_schedule_interval"],
)
scheduler_group.add_argument(
"--disable-hybrid-kv-cache-manager",
**scheduler_kwargs["disable_hybrid_kv_cache_manager"],
@@ -2064,6 +2069,7 @@ class EngineArgs:
long_prefill_token_threshold=self.long_prefill_token_threshold,
scheduler_reserve_full_isl=self.scheduler_reserve_full_isl,
watermark=self.watermark,
prefill_schedule_interval=self.prefill_schedule_interval,
disable_hybrid_kv_cache_manager=self.disable_hybrid_kv_cache_manager,
async_scheduling=self.async_scheduling,
stream_interval=self.stream_interval,
+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
+19 -2
View File
@@ -471,6 +471,11 @@ class EngineCore:
)
self._iteration_index += 1
def _should_throttle_prefills(self) -> bool:
"""Whether to defer new prefills this step (DP prefill balancing).
Overridden by the DP engine core; never throttles otherwise."""
return False
def step(self) -> tuple[dict[int, EngineCoreOutputs], bool]:
"""Schedule, execute, and make output.
@@ -482,7 +487,7 @@ class EngineCore:
# or finished and not yet removed from the batch.
if not self.scheduler.has_requests():
return {}, False
scheduler_output = self.scheduler.schedule()
scheduler_output = self.scheduler.schedule(self._should_throttle_prefills())
future = self.model_executor.execute_model(scheduler_output, non_block=True)
grammar_output = self.scheduler.get_grammar_bitmask(scheduler_output)
with (
@@ -539,7 +544,7 @@ class EngineCore:
model_executed = False
deferred_scheduler_output = None
if self.scheduler.has_requests():
scheduler_output = self.scheduler.schedule()
scheduler_output = self.scheduler.schedule(self._should_throttle_prefills())
with self.log_error_detail(scheduler_output):
exec_future = self.model_executor.execute_model(
scheduler_output, non_block=True
@@ -1751,6 +1756,9 @@ class DPEngineCoreProc(EngineCoreProc):
"DPEngineCoreProc should only be used for MoE models"
)
scheduler_config = vllm_config.scheduler_config
self.prefill_schedule_interval = scheduler_config.prefill_schedule_interval
# Counts forward-passes of the model so that we can synchronize
# finished with DP peers every N steps.
self.step_counter = 0
@@ -1901,6 +1909,15 @@ class DPEngineCoreProc(EngineCoreProc):
)
self.output_queue.put_nowait((-1, EngineCoreOutputs(scheduler_stats=stats)))
def _should_throttle_prefills(self) -> bool:
# Throttle new prefills to cadence-aligned steps for DP balancing.
# step_counter is identical across DP ranks. On a fresh wave the
# counter is 0, so prefills are admitted immediately after idle.
return (
self.prefill_schedule_interval > 1
and self.step_counter % self.prefill_schedule_interval != 0
)
def run_busy_loop(self):
"""Core busy loop of the EngineCore for data parallel case."""