[Core][Refactor][Diffusion] refactor request scheduler's admission wait policy (#5843)
Signed-off-by: Huang, Zeyu <11222265+fhfuih@users.noreply.github.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
c588208cc6
commit
33dd9a5a3e
13 files changed
+253
-54
No files matched your search
@@ -948,8 +948,10 @@ class OmniDiffusionConfig:
|
||||
|
||||
self.master_port = self._resolve_master_port()
|
||||
self.request_batch_max_wait_ms = float(self.request_batch_max_wait_ms or 0.0)
|
||||
if self.request_batch_max_wait_ms < 0:
|
||||
raise ValueError(f"request_batch_max_wait_ms must be non-negative, got {self.request_batch_max_wait_ms}.")
|
||||
if not math.isfinite(self.request_batch_max_wait_ms) or self.request_batch_max_wait_ms < 0:
|
||||
raise ValueError(
|
||||
f"request_batch_max_wait_ms must be a finite non-negative number, got {self.request_batch_max_wait_ms}."
|
||||
)
|
||||
|
||||
if isinstance(self.profiler_config, dict):
|
||||
from vllm.config import ProfilerConfig
|
||||
|
||||
@@ -434,8 +434,7 @@ class DiffusionEngine:
|
||||
# Only RPC / abort work pending; loop back to drain it.
|
||||
continue
|
||||
|
||||
if self.supports_request_batch or self.dp_concurrent:
|
||||
self._wait_for_request_batch_admission_locked()
|
||||
self._wait_for_admission_if_needed_locked()
|
||||
|
||||
sched_output = self.scheduler.schedule()
|
||||
|
||||
@@ -469,53 +468,39 @@ class DiffusionEngine:
|
||||
# Engine is stopping: fail any RPCs still queued so callers don't hang.
|
||||
self._fail_pending_rpcs(RuntimeError("DiffusionEngine is shutting down."))
|
||||
|
||||
def _wait_for_request_batch_admission_locked(self) -> None:
|
||||
"""Wait for compatible requests to accumulate before scheduling a wave.
|
||||
def _wait_for_admission_if_needed_locked(self) -> None:
|
||||
"""Apply scheduler admission policy while holding the engine condition.
|
||||
|
||||
Caller must hold ``self._cv``.
|
||||
"""
|
||||
if self.step_execution or (not self.supports_request_batch and not self.dp_concurrent):
|
||||
return
|
||||
|
||||
max_wait_s = self.od_config.request_batch_max_wait_ms / 1000.0
|
||||
if max_wait_s == 0:
|
||||
return
|
||||
|
||||
max_batch = self.scheduler.max_num_running_reqs
|
||||
waiting = self.scheduler.num_waiting_requests()
|
||||
running = self.scheduler.num_running_requests()
|
||||
|
||||
if running > 0:
|
||||
return
|
||||
|
||||
start = time.monotonic()
|
||||
deadline = start + max_wait_s
|
||||
decision = self.scheduler.get_admission_wait_decision(
|
||||
now=start,
|
||||
dp_concurrent=self.dp_concurrent,
|
||||
)
|
||||
if not decision.should_wait:
|
||||
return
|
||||
|
||||
last_waiting = -1
|
||||
stable_since = start
|
||||
# For dp_concurrent, use a longer stable window so all dp_size
|
||||
# HTTP requests have time to land before scheduling.
|
||||
if self.dp_concurrent:
|
||||
stable_window_s = min(0.3, max_wait_s / 2.0)
|
||||
else:
|
||||
stable_window_s = min(0.05, max_wait_s / 5.0)
|
||||
|
||||
while not self.stop_event.is_set():
|
||||
waiting = self.scheduler.num_waiting_requests()
|
||||
now = time.monotonic()
|
||||
|
||||
if waiting >= max_batch:
|
||||
break
|
||||
if waiting > 0 and (now - stable_since) >= stable_window_s:
|
||||
break
|
||||
if now >= deadline:
|
||||
break
|
||||
|
||||
if waiting > last_waiting:
|
||||
stable_since = now
|
||||
last_waiting = waiting
|
||||
|
||||
remaining = deadline - now
|
||||
self._cv.wait(timeout=min(remaining, 0.002))
|
||||
if self.scheduler.should_end_admission_wait(
|
||||
decision,
|
||||
now=now,
|
||||
stable_since=stable_since,
|
||||
):
|
||||
break
|
||||
|
||||
remaining = decision.deadline - now if decision.deadline is not None else 0.002
|
||||
self._cv.wait(timeout=min(max(remaining, 0.0), 0.002))
|
||||
|
||||
waited_ms = (time.monotonic() - start) * 1000.0
|
||||
final_waiting = self.scheduler.num_waiting_requests()
|
||||
@@ -523,7 +508,7 @@ class DiffusionEngine:
|
||||
logger.info(
|
||||
"[RequestBatch] admission wait done waiting=%d max_batch=%d waited_ms=%.1f",
|
||||
final_waiting,
|
||||
max_batch,
|
||||
decision.max_batch,
|
||||
waited_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from vllm_omni.diffusion.sched.interface import (
|
||||
RequestBatchSamplingParamsKey,
|
||||
SchedulerRequestState,
|
||||
StepBatchSamplingParamsKey,
|
||||
_AdmissionWaitDecision,
|
||||
)
|
||||
from vllm_omni.diffusion.worker.utils import RunnerOutput
|
||||
|
||||
@@ -158,6 +159,27 @@ class BaseScheduler(ABC):
|
||||
def num_running_requests(self) -> int:
|
||||
return len(self._running)
|
||||
|
||||
def get_admission_wait_decision(
|
||||
self,
|
||||
*,
|
||||
now: float,
|
||||
dp_concurrent: bool = False,
|
||||
) -> _AdmissionWaitDecision:
|
||||
"""Return the admission-delay policy for the next scheduling wave."""
|
||||
del now, dp_concurrent
|
||||
return _AdmissionWaitDecision(should_wait=False)
|
||||
|
||||
def should_end_admission_wait(
|
||||
self,
|
||||
decision: _AdmissionWaitDecision,
|
||||
*,
|
||||
now: float,
|
||||
stable_since: float,
|
||||
) -> bool:
|
||||
"""Return whether an active admission delay should end."""
|
||||
del decision, now, stable_since
|
||||
return True
|
||||
|
||||
def get_request_state(self, request_id: str) -> SchedulerRequestState | None:
|
||||
return self._request_states.get(request_id)
|
||||
|
||||
|
||||
@@ -31,6 +31,16 @@ class DiffusionRequestStatus(enum.IntEnum):
|
||||
return status >= DiffusionRequestStatus.FINISHED_COMPLETED
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class _AdmissionWaitDecision:
|
||||
"""Internal scheduler policy for delaying the next admission wave."""
|
||||
|
||||
should_wait: bool
|
||||
deadline: float | None = None
|
||||
stable_window_s: float = 0.0
|
||||
max_batch: int = 1
|
||||
|
||||
|
||||
@dataclass(frozen=True, eq=True)
|
||||
class StepBatchSamplingParamsKey:
|
||||
"""Denoise step level Batch-compatibility key derived from ``OmniDiffusionSamplingParams``.
|
||||
|
||||
@@ -12,6 +12,7 @@ from vllm_omni.diffusion.sched.interface import (
|
||||
DiffusionRequestStatus,
|
||||
DiffusionSchedulerOutput,
|
||||
RequestBatchSamplingParamsKey,
|
||||
_AdmissionWaitDecision,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -35,7 +36,43 @@ def build_request_batch_sampling_params_key(request: OmniDiffusionRequest) -> Re
|
||||
|
||||
|
||||
class RequestScheduler(BaseScheduler):
|
||||
"""Diffusion scheduler with vLLM-style waiting/running queues."""
|
||||
"""Scheduler for static request waves, including admission coalescing."""
|
||||
|
||||
def get_admission_wait_decision(
|
||||
self,
|
||||
*,
|
||||
now: float,
|
||||
dp_concurrent: bool = False,
|
||||
) -> _AdmissionWaitDecision:
|
||||
assert self.od_config is not None
|
||||
max_wait_ms = self.od_config.request_batch_max_wait_ms
|
||||
if max_wait_ms <= 0.0 or self.max_num_running_reqs <= 1:
|
||||
return _AdmissionWaitDecision(should_wait=False)
|
||||
if self.num_running_requests() > 0:
|
||||
return _AdmissionWaitDecision(should_wait=False)
|
||||
|
||||
max_wait_s = max_wait_ms / 1000.0
|
||||
stable_window_s = min(0.3, max_wait_s / 2.0) if dp_concurrent else min(0.05, max_wait_s / 5.0)
|
||||
return _AdmissionWaitDecision(
|
||||
should_wait=True,
|
||||
deadline=now + max_wait_s,
|
||||
stable_window_s=stable_window_s,
|
||||
max_batch=self.max_num_running_reqs,
|
||||
)
|
||||
|
||||
def should_end_admission_wait(
|
||||
self,
|
||||
decision: _AdmissionWaitDecision,
|
||||
*,
|
||||
now: float,
|
||||
stable_since: float,
|
||||
) -> bool:
|
||||
waiting = self.num_waiting_requests()
|
||||
return (
|
||||
waiting >= decision.max_batch
|
||||
or (waiting > 0 and now - stable_since >= decision.stable_window_s)
|
||||
or (decision.deadline is not None and now >= decision.deadline)
|
||||
)
|
||||
|
||||
def _build_sampling_params_key(self, request: OmniDiffusionRequest) -> RequestBatchSamplingParamsKey:
|
||||
return build_request_batch_sampling_params_key(request)
|
||||
|
||||
Reference in new issue
Block a user