Improve overlap scheduling for better TTFT (#11856)
Co-authored-by: Peng Wang <peng_wang@linux.alibaba.com>
This commit is contained in:
@@ -162,6 +162,7 @@ class Envs:
|
||||
|
||||
# Scheduler: others:
|
||||
SGLANG_EMPTY_CACHE_INTERVAL = EnvFloat(-1) # in seconds. Set if you observe high memory accumulation over a long serving period.
|
||||
SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP = EnvBool(False)
|
||||
SGLANG_EXPERIMENTAL_CPP_RADIX_TREE = EnvBool(False)
|
||||
|
||||
# Test: pd-disaggregation
|
||||
|
||||
@@ -988,6 +988,14 @@ class Scheduler(
|
||||
def event_loop_overlap(self):
|
||||
"""A scheduler loop that overlaps the CPU processing and GPU computation."""
|
||||
self.result_queue: Deque[Tuple[ScheduleBatch, GenerationBatchResult]] = deque()
|
||||
disable_consecutive_prefill_overlap = (
|
||||
envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.get()
|
||||
)
|
||||
|
||||
def pop_and_process():
|
||||
# Process the results of the last batch
|
||||
tmp_batch, tmp_result = self.result_queue.popleft()
|
||||
self.process_batch_result(tmp_batch, tmp_result)
|
||||
|
||||
while True:
|
||||
recv_reqs = self.recv_requests()
|
||||
@@ -996,15 +1004,25 @@ class Scheduler(
|
||||
batch = self.get_next_batch_to_run()
|
||||
self.cur_batch = batch
|
||||
|
||||
disable_overlap_for_batch = (
|
||||
disable_consecutive_prefill_overlap
|
||||
and batch
|
||||
and batch.forward_mode.is_extend()
|
||||
and self.last_batch
|
||||
and self.last_batch.forward_mode.is_extend()
|
||||
)
|
||||
|
||||
if disable_overlap_for_batch:
|
||||
pop_and_process()
|
||||
|
||||
batch_result = None
|
||||
if batch:
|
||||
batch_result = self.run_batch(batch)
|
||||
self.result_queue.append((batch.copy(), batch_result))
|
||||
|
||||
if self.last_batch:
|
||||
# Process the results of the last batch
|
||||
tmp_batch, tmp_result = self.result_queue.popleft()
|
||||
self.process_batch_result(tmp_batch, tmp_result)
|
||||
if not disable_overlap_for_batch:
|
||||
pop_and_process()
|
||||
elif batch is None:
|
||||
# When the server is idle, do self-check and re-init some states
|
||||
self.self_check_during_idle()
|
||||
|
||||
Reference in New Issue
Block a user